Copy link to clipboard
Copied
Hi guys, need your help. I am automating PDF and need to automate tags change/update.
In below code, there is no error encountered and the new PDF saved without issue
The problem is, the new tag is not applied in the new PDF document
Please give me advise how can I do it?
Thank you in advance
Public Sub renameTag()
Dim jsObject As Object
Dim objField As Object
Dim result As Boolean
Dim oneCell As Range
Dim testField
Set jsObject = pdfDoc.GetJSObject
For Each oneCell In wsTagReplace.Range("tblTagsReplace[Rename?]")
If oneCell.Value = 1 Then 'need to change/update tags
Set objField = jsObject.getField(currentTag)
objField.Name = newTag
End If
Next oneCell
result = pdfDoc.Save(PDSaveFull, Replace(fileName, ".pdf", "_new.pdf"))
Set objField = Nothing
Set jsObject = Nothing
End Sub
Copy link to clipboard
Copied
So your code is attempting to replace field names, not tags. In the context of PDF, "Tags" have a specific meaning, and this is not it.
But anyway, you can't change a field's name. What you can do is delete a field and recreate it with the new name.
I'd suggest writing a folder level JS function for this and then calling it from the VBA script. This will give you a much better way to develop and test the functionality.
Copy link to clipboard
Copied
Thanks Thom.
Copy link to clipboard
Copied
Hi Thom, can you share a reference or link where i can get idea. Thanks for your support in advance
Copy link to clipboard
Copied
Here's a link to the Acrobat JavaScript API Reference. Lots of topics are covered in the Index, however it's not well explained.
https://opensource.adobe.com/dc-acrobat-sdk-docs/library/jsapiref/index.html
You'll find more coherent information here at this link. Most of the introductory info is free, but it is a subscription site.
https://www.pdfscripting.com/public/PDF-Form-Scripting.cfm