Copy link to clipboard
Copied
Good afternoon!
The code below compiles just fine and I have no missing references, but when I reach the For Each block, there are no FormField items to process (and the loop is not entered).
Here are the references:
I'm using Adobe Acrobat Standard DC, 2015 Release (Classic) | Version 2015.006.30434. Do I need the Professional version for this code to work?
I've spent the better part of the day trying to figure out what I thought would be a pretty simple task. What I want to do is loop through a list of several hundred PDF files, open them, find a specific text string, modify it, slightly expand the width of the text box that contains it, then save/close.
I've found code to find and select the string (AVDoc.FindText), but nothing that allows me to change it (e.g. A300-000A-T-1 to A300-000A-T-101).
There are some relatively cryptic (cryptic to me anyway) posts out there regarding JSO, but I'm not having much luck with that so far. Most of them talk about adding items to the form, not changing existing ones.
Anyway, I'm surprised that there is not something like "AVDoc.ReplaceText" in the reference document:
https://wwwimages2.adobe.com/content/dam/acom/en/devnet/acrobat/pdfs/iac_api_reference.pdf
That would solve everything.
Thanks in advance!
Public Sub ListPDF_Fields()
Dim AcroExchAVDoc As CAcroAVDoc
Dim AcroExchApp As CAcroApp
Dim AFORMAUT As AFORMAUTLib.AFormApp
Dim FormField As AFORMAUTLib.Field
Dim FormFields As AFORMAUTLib.Fields
Dim bOK As Boolean
Dim sFields As String
Dim sTypes As String
Dim sFieldName As String, PDFPath As String
' For this procedure to work, computer must have a full version
' of Adobe Acrobat installed. Also, a reference to the following
' Type Libraries must be made:
' AFormAut 1.0
' Adobe Acrobat 7.0 (or newer)
On Error GoTo ErrorHandler
PDFPath = Range("B" & ActiveCell.Row)
Set AcroExchApp = CreateObject("AcroExch.App")
Set AcroExchAVDoc = CreateObject("AcroExch.AVDoc")
bOK = AcroExchAVDoc.Open(PDFPath, "") '**************File open is successful
AcroExchAVDoc.BringToFront
AcroExchApp.Hide
If (bOK) Then
Set AFORMAUT = CreateObject("AFormAut.App")
Set FormFields = AFORMAUT.Fields
For Each FormField In FormFields '***************No FormField objects exist for processing!
With FormField
sFieldName = .Name
If .IsTerminal Then
If sFields = "" Then
sFields = .Name
sTypes = .Type
Else
sFields = sFields + "," + .Name
sTypes = sTypes + "," + .Type
End If
End If
End With
Next FormField
AcroExchAVDoc.Close True
End If
Debug.Print sFields
Debug.Print sTypes
Set AcroExchAVDoc = Nothing
Set AcroExchApp = Nothing
Set AFORMAUT = Nothing
Set FormField = Nothing
Exit Sub
ErrorHandler:
MsgBox "FieldList Error: " + Str(Err.Number) + " " + Err.Description + " " + Err.Source
End Sub
No, I am saying you need to write a COMPLETELY NEW plugin (in C/C++) to do what you wish.
https://www.datalogics.com/products/pdf/pdflibrary/
Sorry, Java and .NET – no Python.
Copy link to clipboard
Copied
Probably because there aren’t any form fields on the PDF that you are working with. It’s probably a static PDF file with no interactive fields (which is what you are trying to obtain).
The JavaScript and VB APIs do not have any access to the actual content of a PDF. You will need to use our plugin APIs (via C/C++) instead to accomplish search & replace.
Copy link to clipboard
Copied
Thanks for the quick response, lrosenth!
You're right, there are no interactive fields in these PDFs (just text fields and a few images). These are datasheets describing package contents. This explains why no FormFields were found, because there aren't any.
Please confirm that even though my file is editable using Standard DC and that the text of interest can be found and highlighted using AVDoc,FindText that it is not possible to edit the content of these files using vba or js.
Please provide a link to a reference describing your plug-in APIs that provide search & replace functionality. Will these plug-ins require a Pro installation? I checked with our IT manager and all we have here is Standard.
I should also mention that I have some basic skills in Python. Would the PDF tools provided in that realm allow me to accomplish this task, or are the plug-ins the only option?
Thanks again for your help.
Copy link to clipboard
Copied
That is correct – it is NOT possible to edit using VBA & JS. Only with the Plugin API.
Standard is just fine – Pro is not required. As to the Search/Replace, you would need to use low level APIs, specifically of the PDEdit variety.
PlugIns are the only option for Acrobat. If you want to go a completely different route, Adobe offers a PDF library (though Datalogics – www.datalogics.com<http://www.datalogics.com>) that has VB and Python bindings.
Copy link to clipboard
Copied
If the Plugin for editing is the one called "Edit PDF"...the pink one with the two rectangles and the three lines in the icon, I already have this component. The search/replace feature works fine manually file-by-file, but this won't help me in the effort to update hundreds of files. Please confirm that the Plug-in to which you refer above is called "Edit PDF" and that it can't be scripted in some way with the tools that I currently possess to process a large number of files.
I checked out Datalogics (https://www.datalogics.com/products/pdf/pdflibrary/)​ and I am unalbe to find anything there regarding VB or Python. Could you point me to a page that describes the VB and Python bindings to which you refer?
I'll start a conversation on this topic with Datalogics as well...thank you for the lead.
Copy link to clipboard
Copied
No, I am saying you need to write a COMPLETELY NEW plugin (in C/C++) to do what you wish.
https://www.datalogics.com/products/pdf/pdflibrary/
Sorry, Java and .NET – no Python.
Copy link to clipboard
Copied
Ok, well at least I now have a justifiable reason to learn C++. In the meantime, I guess we'll be opening these files and manually editing them one at a time. Fortunately, we don't have to have them all at once...just as needed.
I really appreciate your help with this.