Quitter
  • Communauté internationale
    • Langue:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티

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

Nouveau ici ,
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.

SUJETS
SDK Acrobat et JavaScript
2.9K
Traduire
Signaler
Directives de la communauté
Restez bienveillant et courtois, ne vous attribuez pas la paternité des créations d’autrui et assurez-vous de l’absence de doublons avant de poster du contenu. En savoir plus
community guidelines

correct answers 1 bonne réponse

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.

Traduire
LÉGENDE ,
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.

Traduire
Signaler
Directives de la communauté
Restez bienveillant et courtois, ne vous attribuez pas la paternité des créations d’autrui et assurez-vous de l’absence de doublons avant de poster du contenu. En savoir plus
community guidelines
Nouveau ici ,
Jul 21, 2017 Jul 21, 2017

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

Traduire
Signaler
Directives de la communauté
Restez bienveillant et courtois, ne vous attribuez pas la paternité des créations d’autrui et assurez-vous de l’absence de doublons avant de poster du contenu. En savoir plus
community guidelines
Community Expert ,
Jul 21, 2017 Jul 21, 2017

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

Traduire
Signaler
Directives de la communauté
Restez bienveillant et courtois, ne vous attribuez pas la paternité des créations d’autrui et assurez-vous de l’absence de doublons avant de poster du contenu. En savoir plus
community guidelines
Community Expert ,
Jul 21, 2017 Jul 21, 2017
LA PLUS RÉCENTE

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.

Traduire
Signaler
Directives de la communauté
Restez bienveillant et courtois, ne vous attribuez pas la paternité des créations d’autrui et assurez-vous de l’absence de doublons avant de poster du contenu. En savoir plus
community guidelines