WinBatch® Technical Support Forum

All Things WinBatch => WinBatch => Topic started by: MW4 on February 04, 2020, 11:43:05 AM

Title: PDF file splitter
Post by: MW4 on February 04, 2020, 11:43:05 AM
I thought there was a good PDF file splitter in the Tech Database, but I can't seem to find it.

I just want to extract every page in a pdf to a separate file.

1-3.PDF
into
1.pdf
2.pdf
3.pdf

A point in the right direction would be greatly appreciated!

Thanks!
Title: Re: PDF file splitter
Post by: td on February 04, 2020, 01:18:04 PM
You may not have found a cut&paste example in the Tech Database but there are multiple pdf related examples in there.  If you spend some time looking at those, you may be able to develop a script.   Otherwise, you could perform a Web search for .Net assemblies that could be called from WinBatch.
Title: Re: PDF file splitter
Post by: td on February 04, 2020, 05:29:43 PM
Just a random thought and have never tried it but MS Word can load and save pdf documents.  Perhaps you could use it to split up your document into single page documents. Word has an extensive COM Automation programming model that can be used with WinBatch.
Title: Re: PDF file splitter
Post by: stanl on February 05, 2020, 02:57:24 AM
Below is vba code, but should be convertible to WB
Code (WINBATCH) Select


Dim PDDoc As Acrobat.CAcroPDDoc, newPDF As Acrobat.CAcroPDDoc
Dim PDPage As Acrobat.CAcroPDPage
Dim thePDF as String, PNum as Long


Set PDDoc = CreateObject("AcroExch.pdDoc")
Result = PDDoc.Open(thePDF)
If Not Result Then
   MsgBox "Can't open file: " & FileName
   Exit Sub
End If


PNum = PDDoc.GetNumPages


For i = 0 To PNum - 1
    Set newPDF = CreateObject("AcroExch.pdDoc")
    newPDF.Create
    NewName = "Page_" & i "_of_" & PNum & ".pdf"
    newPDF.InsertPages -1, PDDoc, i, 1, 0
    newPDF.Save 1, NewName
    newPDF.Close
    Set newPDF = Nothing
Next i


Title: Re: PDF file splitter
Post by: td on February 05, 2020, 07:07:33 AM
I was under the impression that ADOBE or whomever no longer supported the "AcroExch.pdDoc" COM Automation object - at least without paying them some $- but I could very easily be wrong.
Title: Re: PDF file splitter
Post by: td on February 05, 2020, 07:20:37 AM
PDFsharp is an open-source pdf library for C#.  It can be found here http://www.pdfsharp.net/ (http://www.pdfsharp.net/).  I haven't used it but it does say it can be used to split PDF documents.  Might be worth a look.
Title: Re: PDF file splitter
Post by: billfrog on February 06, 2020, 09:53:59 AM
You could avoid Winbatch altogether and download something like PDFtk...
Not sure if the free version can do what you want, but the paid version can do it from the command line.

https://www.pdflabs.com/tools/pdftk-the-pdf-toolkit/