Automatically Rename PDF Files by using a pre-determined area from the document (ex. invoice no)

Community Beginner ,
Feb 03, 2021 Feb 03, 2021

Copy link to clipboard

Copied

Hello,

I need to rename my PDF documents by using a specific text from the document. The text is always in the same position in the documet.

Is this possible with JavaScript?

 

Thank you, Alina

TOPICS
Create PDFs, How to, JavaScript, Print and prepress

Views

79

Likes

translate

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
Most Valuable Participant ,
Feb 03, 2021 Feb 03, 2021

Copy link to clipboard

Copied

Yes. A script can extract text from a specific area of a page by looking at the coordinates of all the words on it, but it's a pretty advanced scripting task...

Likes

translate

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
Most Valuable Participant ,
Feb 03, 2021 Feb 03, 2021

Copy link to clipboard

Copied

Small addendum: The script can't actually rename the file, but it can save a new copy of it under the new name.

Likes

translate

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 Beginner ,
Feb 03, 2021 Feb 03, 2021

Copy link to clipboard

Copied

Thank you.

I will try to make a function to extract the file name (desired text) from the PDF context first.

Likes

translate

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 Beginner ,
Feb 10, 2021 Feb 10, 2021

Copy link to clipboard

Copied

Hello,

 

First I've checked the position of the text:

/*Find Quads*/

var ckWord, numWords;
for (var i = 0; i < this.numPages; i++ )
{
numWords = this.getPageNumWords(i);
for (var j = 0; j < numWords; j++)
{
var ckWord = this.getPageNthWord(i, j);
if(ckWord == "NORMAN")
{
console.println(this.getPageNthWordQuads(i,j))
}
}
}

 

Based on this output I've put the values on the var intLocation:

 

filePath = "/c/temp/";
var intLocation = [[410,514,460,514,410,504,460,504]];
var ckWord, numWords, fileName;
for (var i = 0; i < this.numPages; i++ )
{
	numWords = this.getPageNumWords(i);
	for (var j = 0; j < numWords; j++)
	{
		ckWord = this.getPageNthWord(i, j);
		selection = this.getPageNthWordQuads(i,j);
				          
		if( parseInt(selection[0][0]) == intLocation[0][0] && parseInt(selection[0][1]) == intLocation[0][1] && parseInt(selection[0][2]) == intLocation[0][2] && parseInt(selection[0][3]) == intLocation[0][3] && parseInt(selection[0][4]) == intLocation[0][4] && parseInt(selection[0][5]) == intLocation[0][5] && parseInt(selection[0][6]) == intLocation[0][6] && parseInt(selection[0][7]) == intLocation[0][7])
		{			
			console.println("");
			console.println(j);
			console.println(ckWord);
			console.println(selection);
			this.extractPages(i, i, filePath + ckWord + ".pdf");
			break;
		}
	}	
}

 Thanks for the hint 🙂

Likes

translate

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