Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to split a PDF into pages using VBA 1

Status
Not open for further replies.

NashProjects

Programmer
Mar 25, 2009
11
0
0
GB
hi all,

Im stumped with a problem.

I have a PDF file and I need to split this into individual pages... I would normally do this manually but I have thousands per month and so I want to automate this process.

I am an expert in excel vba but this has baffled me as i cant seem to find any activex dll's which have this functionality?

I would appreciate if anyone can help me with this problem!!!

Thanks in advance guys.

Kind regards

Lee Nash

 
I would normally do this manually
How ?

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
Well there are several standalone applications out there that all you to split pdfs into seperate files.

I know there is code out there that can combine pdf's into one so there must be some code out there that can split pdfs into seperate files based on their page number?

Im assuming this is logical but I cant for the life of me find this code anywhere!


Kind regards

Lee Nash

 
PHV, if Nash means splitting into individual pages as individual files, then the manual process with Acrobat is:

Document, Extract Pages

 
Nash,

I have done this before. The entire code is a bit long (and superfluous for you), but this should give you a good start:

a) The reference you need is to "Acrobat.tlb", which is located in the Acrobat Pro programme folder

b) This code (adapted to your needs):
Code:
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
[b]
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
[/b]

This will split a pdf into one-page PDFs.

Hope this helps!
MiS

[navy]"We had to turn off that service to comply with the CDA Bill."[/navy]
- The Bastard Operator From Hell
 
That of course assumes the OP has Acrobat - not just Reader - and is not trying to work with any given PDF file. I would love to be able to use that code, but I do not have Acrobat itself.

Gerry
 
@Gerry: Yes, of course, Acrobat Professional is required.

That code is part of a PDF Text extracter I wrote a while ago.
In the end is was (almost) useless. It was just finished and gave good results when most PDFs we received were of the three-columned kind, and my extraction gave crap results...
[curse]
Anyway: the splitter works and occasionally comes in handy.
:)

I'm mostly working with ABBYY Fine Reader 8 Pro now, which is quite good and also has a good OCR engine.


[navy]"We had to turn off that service to comply with the CDA Bill."[/navy]
- The Bastard Operator From Hell
 
So...just because I am curious...NashProjects, do you have Acrobat Pro?

MakeItSo: I have never seen ABBYY (or heard of it), but I just took a look...hmmmm, that seems pretty good.

The only reason I mentioned anything RE: having Acrobat Pro, is that:

"a) The reference you need is to "Acrobat.tlb", which is located in the Acrobat Pro programme folder"

is an assumption. I recall a thread way back when that went back and forth, back and forth, with the OP getting more and more confused and frustrated. Finally, it came out that the OP did NOT have Acrobat and all the suggestions about using it were moot.

I most certainly am not really trying to tell you how to post, but it may be a good thing to mention:

IF you have Acrobat Pro, then....

Gerry
 
Ummm im not techical with Acrobat so im assuming i wont have!!

I think I need to find another way around that, as its for the office and if I do buy acrobat then i'll only have one license for it...

I want this program to be used on everyones pc rather then just my own.

Thanks for the heads up guys i really appreciate it but I think i need to find some freeware dll that will allow me access to do this.


Kind regards

Lee Nash

 
Oh, I mean my comment to MakeItSo. You do not have Acrobat, so his assumption that you did - and so posting a code solution that you can not use - was just that, an incorrect assumption.

Gerry
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top