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

Rename PDF based on content?

New Here ,
Sep 19, 2016 Sep 19, 2016

Copy link to clipboard

Copied

Is there a Javascript available that automatically renames a PDF based on the content?

Some fields in the PDF should be reflected in the PDF name.

TOPICS
Acrobat SDK and JavaScript , Windows

Views

15.9K

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
LEGEND ,
Sep 19, 2016 Sep 19, 2016

Copy link to clipboard

Copied

No, since you have the PDF open, you cannot rename it.

What content are you going to use?

It could be saved under a new name using  form fields or the PDF properties of key words, subject, or title if the properties are field in for the PDF. But this type of coding will require some special code in folders.

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 ,
Sep 19, 2016 Sep 19, 2016

Copy link to clipboard

Copied

All my files have key words on the same place. And saving them under a new correct name is what im looking for. Can I send you an example of the pdf that would need to be renamed?

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
LEGEND ,
Sep 19, 2016 Sep 19, 2016

Copy link to clipboard

Copied

We are here to help you with script problems not write the entire script for you.

https://acrobatusers.com/tutorials/how-save-pdf-acrobat-javascript

How to Save a PDF with Acrobat JavaScript

by Thom Parker will get you started with the folder level script for saving using JavaScript. You can use the document object's info.Keywords method to get

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 ,
Sep 20, 2016 Sep 20, 2016

Copy link to clipboard

Copied

I have just started using the javascript function, so i'm trying to figure everything out.

So the script below just saves your pdf as "x" in the same location. But how can I change this X into a value/text present on my PDF?

// Split Path into an array so it is easy to work with

var aMyPath = this.path.split("/");

// Remove old file name

aMyPath.pop();

// Add new file name

aMyPath.push("x.pdf");

// Put path back together and save

this.saveAs(aMyPath.join("/"));

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 08, 2019 Jan 08, 2019

Copy link to clipboard

Copied

I know this is an old thread, but it still shows an unanswered. Renaming of PDF files with JavaScript is doable by very tedious especially if you need to extract text from a specific location(s). There is also a performance issue since working with page content in JavaScript is not fast. Using a plug-in with a user interface can be more convenient especially when dealing with this task on a regular basis. Here is a link to a tutorial that shows how to bulk rename PDF files using text from the document with AutoSplit plug-in: Automatic Renaming of PDF Files . Text can be extracted from specific page location(s) or by text search (using text patterns such as SSN, account numbers and etc.). This is a commercial plug-in for Adobe Acrobat, not a JavaScript.

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 ,
Jan 08, 2019 Jan 08, 2019

Copy link to clipboard

Copied

How is renaming PDF files with JS doable, tedious or not?

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 08, 2019 Jan 08, 2019

Copy link to clipboard

Copied

If it is necessary to extract text from a specific location on a page in order to use it in the output file name, then the algorithm is as follows:

1. First, use a ruler/grid tool (Use Ctrl+U and Ctrl+R keyboard shortcuts to toggle the tools on/off) to determine the coordinates on the page where the "text of interest" is located. If there are multiple areas, measure each one and record the coordinates.

2. In JavaScript code, enumerate all words on the page using this.getPageNthWordQuads() method that returns coordinates for each word as an array of coordinates.

3. Check each "quad" returned by the function against the area(s) of interest (determined manually in step 1). Complication: it is necessary to take page rotation and difference in coordinate systems into account when checking each quad. Quads are returned in the page coordinate system (user space, origin is in bottom-left corner), while coordinates on screen are measured in screen coordinate system (device space, origin is in upper-left corner, y-axis is pointing down).

4. If the word lies inside an "area of interest", add it to the output text string.

5. Once done enumerating the words, save the file using this.SaveAs() method while combining a predefined output path with the extracted text.

Drawbacks:

1. Coordinates for the text needs to be measured manually.

2. If new documents with a different layout are used, then the script needs to be edited with new coordinates.

3. Can be a very slow process if there is a lot of text and a lot of files involved.

The similar script can be used if the text of interest conforms to a well-defined text pattern (such as SSN, account number, client ID, email and etc.). Then there is no need to measure text coordinates and text can be extracted by performing a text search. In this case, all words need to be enumerated using this.getPageNthWord() method and the resulting text string can be searched using a regular expression.

Here is a link to a script that shows how to extracts SSNs from a page text: Acrobat Javascript Samples Scripts. Similar approach can be used to extract text and then use it to save a file with a custom file name. The advantage of this method is its flexibility, since it does not rely on a fixed text location(s) that can be easily changed. This method will be slower than a first one, since all page text needs to be extracted before it can be searched.

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 ,
Jan 08, 2019 Jan 08, 2019

Copy link to clipboard

Copied

I know all of that, but it's not what I asked about. I asked specifically about renaming files, which you said is possible.

AFAIK, JS can only save a file under a new name; It can't rename an existing file.

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 08, 2019 Jan 08, 2019

Copy link to clipboard

Copied

Sorry, I did not understand your question first. You are absolutely correct, JavaScript cannot rename an existing file, only to create new ones. I was under assumption that creating a new file with a different name is really counts as renaming, since there is no other option available in JS. I do not think that this is actually a bad thing, because it probably saved a lot of user files from being lost, accidentally overwritten or given the same name. In my opinion, automatic file renaming without a user review/confirmation step is kind of dangerous. If input files layout/content have been changed from what the script is designed to do, then script can no longer extract the correct text, and then consequences are grim. By saving the renamed files in a different location, the originals are preserved and can be always used to roll-back the changes or re-running the renaming algorithm. Better safe then sorry.

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 ,
Jan 08, 2019 Jan 08, 2019

Copy link to clipboard

Copied

LATEST

I agree. Just wanted to make sure there isn't some kind of hidden feature I was not aware of that allowed it...

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