Copy link to clipboard
Copied
I am using VBA as a platform to do some PDF manipulation. The issue I am having is that I cannot seem to get the PDF object to save if the PDF object have not been opened. Below is a snippet of the code that inserts pages to the PDF object, and then saves the pdf object. In terms of the code, I have determined that it works since I have tested the save method with the same input with another pdf object and it worked just fine. Can someone help by explaining why it doesn't allow me to save the object?
Thanks!
Dim NewPDF As New Acrobat.AcroPDDoc
Set NewPDF = CreateObject("AcroExch.PDDoc")
If NewPDF.InsertPages(j, OriPDF, j, 1, 0) Then MsgBox "Success"
If NewPDF.Save(PDSaveLinearized, WritePath & "\" & sh.Cells(StartRow + j - 1, i).Value & ".pdf") Then MsgBox "Success"
NewPDF.Close
Set NewPDF = Nothing
When the above code was ran, neither of the success lines worked as expected.
Before you call InsertPages, you need to call Create - this is different from CreateObject:
Acrobat DC SDK Documentation - PDDoc.Create
This will create a PDDoc without any pages, which you cannot save to disk (actually, you can, but you cannot open it once saved): A PDF document always has to have at least one page. But, once created, you can insert pages. However, you have to make sure that you specify -1 as the first parameter to InsertPages, otherwise the call will fail.
Copy link to clipboard
Copied
A PDDoc object is an OLE marker for an open PDF. Creating one does not in any way create a file, it just prepares Acrobat to accept automation commands such as Open.
Copy link to clipboard
Copied
Ok. So if you were me, how will you create a blank pdf object using code?
Copy link to clipboard
Copied
With Adobe Acrobat create an empty PDF document. In your code open this document.
Copy link to clipboard
Copied
Before you call InsertPages, you need to call Create - this is different from CreateObject:
Acrobat DC SDK Documentation - PDDoc.Create
This will create a PDDoc without any pages, which you cannot save to disk (actually, you can, but you cannot open it once saved): A PDF document always has to have at least one page. But, once created, you can insert pages. However, you have to make sure that you specify -1 as the first parameter to InsertPages, otherwise the call will fail.
Find more inspiration, events, and resources on the new Adobe Community
Explore Now