How to Programmatically Import PDF Comments Using VBA and JavaScript
Question details
The user needs to automate the importation and merging of PDF comments and annotations from multiple files into one document without losing formatting or encountering rotation errors.

- Product
- Excel VBA and Acrobat API
- Device & OS
- not provided
- Scenario
- Automating the merging of FDF/XFDF annotation data into a single PDF document using a script.
- Observed behavior
- Seeking a programmatic method to import annotations because standard OLE classes fail to accurately preserve advanced annotation details and coordinate placement.
Ensure you have access to the Adobe Acrobat SDK documentation and have enabled the necessary Acrobat library references within your Excel VBA environment.
Use the JSObject Bridge via VBA to Import PDF Comments
Utilize the JSObject bridge in your Excel VBA script to leverage Acrobat's JavaScript API for accurate annotation importing.
Standard Adobe Acrobat OLE classes do not fully support advanced annotation functions because they have not been substantially updated since the JSObject was introduced. Using the JSObject bridge allows your VBA code to natively run specific JavaScript commands to handle FDF/XFDF data accurately, preserving exact coordinates.
Open your Excel workbook and press ALT + F11 to launch the VBA Editor.
Navigate to Tools > References in the top menu and ensure the 'Adobe Acrobat type library' is checked.
Declare and initialize an Acrobat App object (AcroApp) and an AVdoc object in your VBA script to open the target PDF.
Retrieve the PDDoc object from your opened AVdoc and instantiate the JSObject bridge using a command such as 'Set jso = pdDoc.GetJSObject'.
Use the JSObject's native 'importAnns' or 'importAnnsFromData' JavaScript methods within your VBA script to safely and accurately import your FDF/XFDF comments.

Manage PDF Comments Without Complex Scripts in WPS Office
Avoid the hassle of complicated VBA coding and standard software limitations. WPS Office provides a free, lightweight alternative with high format compatibility and a familiar UI, allowing you to seamlessly handle PDF documents and Excel files in one easy-to-use application.
- 1. Download and Install: Download WPS Office from the official website and complete the quick installation process.
- 2. Open Your PDF: Launch WPS PDF and open the document containing the comments you need to manage.
- 3. Use the Comment Tools: Navigate to the Comment tab on the top ribbon to easily view, add, or export your annotations without writing code.

Frequently Asked Questions
Why do my PDF comments lose formatting when imported via VBA OLE classes?
Standard Acrobat OLE classes have limited support for modern annotations and have not been updated to handle complex placement. Using the JSObject bridge provides full access to the Acrobat JavaScript API, which preserves coordinates, formatting, and rotation.
What formats are best for exporting and importing PDF comments programmatically?
FDF (Forms Data Format) and XFDF (XML Forms Data Format) are the standard Adobe formats designed specifically for safely exporting, storing, and importing PDF annotations without altering the main document structure.
How do I access the JSObject in Excel VBA?
You can access the JSObject by opening a PDF using the Acrobat API in VBA, extracting the PDDoc object (which represents the underlying PDF document), and calling the 'GetJSObject' method on it to bridge your script to Acrobat's JavaScript engine.




