Skip to main content
Participant
December 7, 2021
Question

Cannot save changes to PDF from VBA

  • December 7, 2021
  • 1 reply
  • 715 views

Hi 

Hope someone can give me a hent to get past this problem.

Im opening af PDF form template, inserting a value and want to save it as a copy with another name.

But the change deos not get saved.

 

My code is like this:

 

Private Sub MakeS11Files()

Dim FileTemplate, FileNmCopy, gApp, avDoc, pdDoc, jso

FileTemplate = "C:\TestFolder\S-11.PDF" 'File location
FileNmCopy = "C:\TestFolder\S-11_Copy.PDF"
FileCopy FileTemplate, FileNmCopy 'Copying the original template for edithing
Set gApp = CreateObject("AcroExch.app")

Set avDoc = CreateObject("AcroExch.AVDoc")
If avDoc.Open(FileNmCopy, "") Then
Set pdDoc = avDoc.GetPDDoc()
Set jso = pdDoc.GetJSObject

Debug.Print jso.getField("Text1").Value 'TEST in Immediate window show original name

Set x = jso.getField("Text1")
x.Value = "Bing Crosby"

Debug.Print jso.getField("Text1").Value 'TEST in Immediate window show Bing Crosby

pdDoc.Save PDSaveFull, FileNmCopy 'Save changes to the PDF document
pdDoc.Close

End If

Debug.Print jso.getField("Text1").Value 'TEST in Immediate window still show Bing Crosby

 

'Close the PDF; the True parameter prevents the Save As dialog from showing
avDoc.Close (True) 'The new file it generate but when I open it, it's still the original name. The process of closing the document is like abording the changes


'Some cleaning
Set gApp = Nothing
Set avDoc = Nothing
Set pdDoc = Nothing
Set jso = Nothing

End Sub

This topic has been closed for replies.

1 reply

Bernd Alheit
Community Expert
Community Expert
December 8, 2021

What version of Adobe Acrobat does you use?

Does you use a XFA form?

SBIITMCAuthor
Participant
December 8, 2021
Im using Adobe Acrobat DC

Soren Isaksen