Skip to main content
Known Participant
July 20, 2017
Answered

Can you save an empty page by creating a PDDoc object from scratch?

  • July 20, 2017
  • 2 replies
  • 2846 views

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.

This topic has been closed for replies.
Correct answer Karl Heinz Kremer

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.

2 replies

Karl Heinz  Kremer
Community Expert
Karl Heinz KremerCommunity ExpertCorrect answer
Community Expert
July 21, 2017

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.

Legend
July 21, 2017

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.

silveryneAuthor
Known Participant
July 21, 2017

Ok. So if you were me, how will you create a blank pdf object using code? 

Bernd Alheit
Community Expert
Community Expert
July 21, 2017

With Adobe Acrobat create an empty PDF document. In your code open this document.