Save a PDF Using Its Metadata Title in Acrobat JavaScript
Question details
Save a PDF using its metadata title as the filename with Acrobat JavaScript.

- Product
- Adobe Acrobat
- Device & OS
- not provided
- Scenario
- The user wants to read a PDF's title metadata and use it to name a saved copy.
- Observed behavior
- The saved PDF should use a valid filename derived from its metadata title and include the .pdf extension.
Check the PDF's title under File > Properties > Description and make sure the destination folder exists and is writable. The example uses a Windows destination and requires a desktop Acrobat environment where folder-level JavaScript and privileged save operations are permitted.
Save the PDF with a Trusted Acrobat JavaScript Function
Use a folder-level trusted function to create a Windows-compatible filename from the PDF title and save it to a specified folder.
Acrobat's saveAs method requires a privileged context for this operation. A trusted function defined in a folder-level script provides that context; code placed in a PDF document script alone is not sufficient.
The example replaces invalid Windows filename characters, removes trailing periods and spaces, and handles common reserved device names. It uses Untitled if the metadata title is empty.
In an Acrobat folder-level JavaScript file, add the following code: var saveWithTitle = app.trustedFunction(function (doc) { app.beginPriv(); try { var name = doc.info.title || "Untitled"; name = name.replace(/[<>:"/\\|?*\x00-\x1F]/g, "_").replace(/[. ]+$/g, ""); if (!name) name = "Untitled"; if (/^(CON|PRN|AUX|NUL|COM[1-9]|LPT[1-9])(?:\.|$)/i.test(name)) name = "_" + name; doc.saveAs("/C/FILELINK/" + name + ".pdf"); } finally { app.endPriv(); } });
Replace /C/FILELINK/ in the script with your existing destination folder in Acrobat path syntax. For example, C:\FILELINK\ is written as /C/FILELINK/.
Save the script in an Acrobat folder-level JavaScript directory and restart Acrobat. Open the PDF, open the JavaScript console, and run saveWithTitle(this); while the PDF is active.
Open the destination folder and verify that the PDF has the expected title-based filename and .pdf extension.

Manage PDF Files Alongside Office Documents in WPS Office
WPS Office is a free, lightweight alternative with a familiar interface for working with PDFs and compatible Office documents. It supports a straightforward move between common file formats, though it does not provide Acrobat's trusted JavaScript saveAs workflow.

Frequently Asked Questions
Where can I check a PDF's metadata title?
In Acrobat, open the PDF and select File > Properties > Description. The Title field is the value read by doc.info.title.
Why does saveAs fail when I run it from a document script?
Saving to a specified path requires a privileged context. Define an app.trustedFunction in a folder-level script and run the save operation within app.beginPriv() and app.endPriv().
What happens if the PDF has no metadata title?
The example uses Untitled as the filename, producing Untitled.pdf in the selected destination folder.
How do I write a Windows destination path for Acrobat?
Use Acrobat path syntax with forward slashes and the drive letter as a path segment. For example, C:\FILELINK\ becomes /C/FILELINK/.
Can WPS Office run this Acrobat trusted JavaScript function?
This workflow relies on Acrobat-specific trusted functions and saveAs behavior. WPS Office can be used to work with PDFs, but it is not a replacement for that Acrobat JavaScript workflow.




