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

PDF tags automation thru VBA

New Here ,
Jan 29, 2024 Jan 29, 2024

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
TOPICS
Windows

Views

267

Translate

Translate

Report

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 ,
Jan 29, 2024 Jan 29, 2024

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. 

 

 

Thom Parker - Software Developer at PDFScripting
Use the Acrobat JavaScript Reference early and often

Votes

Translate

Translate

Report

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 ,
Jan 29, 2024 Jan 29, 2024

Copy link to clipboard

Copied

Thanks Thom.

Votes

Translate

Translate

Report

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 ,
Feb 27, 2024 Feb 27, 2024

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

Votes

Translate

Translate

Report

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 ,
Feb 27, 2024 Feb 27, 2024

Copy link to clipboard

Copied

LATEST

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

 

 

Thom Parker - Software Developer at PDFScripting
Use the Acrobat JavaScript Reference early and often

Votes

Translate

Translate

Report

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