Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

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

New Here ,
Jul 20, 2017 Jul 20, 2017

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.

TOPICS
Acrobat SDK and JavaScript
2.8K
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Community Expert , Jul 21, 2017 Jul 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.

Translate
LEGEND ,
Jul 20, 2017 Jul 20, 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.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Jul 21, 2017 Jul 21, 2017

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

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jul 21, 2017 Jul 21, 2017

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

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jul 21, 2017 Jul 21, 2017
LATEST

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.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines