Copy link to clipboard
Copied
I have a script that extracts and renames files that have been extracted.
What I require is during the process I wish to add a page to the beginning of the extracted Files and have it say something like, "Part 1 of 2".
var re = /\.pdf$/i;
var filename = this.documentFileName.replace(re,"");
try {for (var i = 0; i < this.numPages; i+= 5) this.extractPages({
nStart: i,
nEnd: (((i+4)>=this.numPages) ? this.numPages-1 : (i+4)),
cPath: "/K/Penta/Split/"+filename+"_" +"Pages_" + (i+1) + "-" + (((i+5)>=this.numPages) ? this.numPages : (i+5)) +".pdf"
});
} catch (e) { console.println("Aborted: " + e) }
The Script extracts a set number of pages and saves them with their new name
Message was edited by: Joshua Adams
Excellent!! How about marking a correct answer?
Copy link to clipboard
Copied
I recommend you add those pages to the original file, and then extract them along with the rest of the pages.
Doing it after the fact is trickier.
Copy link to clipboard
Copied
The function for adding a new page is "doc.newPage()";
To use it you'll need to make a small adjustment to your script. Remove the cPath argument from the "extractPages" function so it will return a doc object for the extracted pages. Add the new page function and follow it with a "doc.saveAs()" to path removed from "extractPages".
Copy link to clipboard
Copied
So if I remove the cpath and add the new function it will add a new page too the beginning of the extracted files, could you show me the modified script i cant access adobe pro at the moment
Copy link to clipboard
Copied
Well, here are the JS reference entries for the 3 functions you need to implement this script.
This script should look something like this
var oNewDoc = this.extractPages(...)
oNewDoc.newPage(...)
oNewDoc.saveAs(...)
Copy link to clipboard
Copied
Hi Tom I want to thank you for your help, I almost have it working, I just need your advice on why Adobe Javascript keeps telling me I'm missing a set of : when I know I'm not, also If you have any other suggestions to fix my script I'm open to suggestions
var re = /\.pdf$/i;
var filename = this.documentFileName.replace(re,"");
try {for (var i = 0; i < this.numPages; i+= 5)
var oNewDoc = this.extractPages({
nStart: i,
nEnd: (((i+4)>=this.numPages) ? this.numPages-1 : (i+4)),
});
oNewDoc.newPage();
oNewDoc.saveAs(cPath: "/K/Penta/Split/"+filename+"_" +"Pages_" + (i+1) + "-" + (((i+5)>=this.numPages) ? this.numPages : (i+5)) +".pdf")
} catch (e) { console.println("Aborted: " + e) }
I can't test my script until I figure why Adobe Javascript is being diffcult
Copy link to clipboard
Copied
The "oNewDoc.saveAs" line is incorrectly formed. Remove "cPath:". This syntax is only used to indicate a member of an object, which is one way to pass parameters into a function. But in this case your missing the rest of the object definition syntax. Doesn't matter anyway cause you've only got one input. So just remove the offending bit.
Copy link to clipboard
Copied
Thank You Thom, I'm sorry for bothering you, I just need help with the newPage function is their a way, to make it say after extracts list what pages are in this file. Example: The File saves as img-322123814-0001_Pages_1-5 and extracts out of a 30 page document so I want it say in the new page Part 1 of 6 or something along those lines?
Copy link to clipboard
Copied
Yes, there are a few different ways to do this. The easiest is to add a form field to the bottom of the page and write the text into it. Another method is to add a watermark to the page.
Copy link to clipboard
Copied
Ok I found a function called addwatermarkfromtext, how could I implement it to count how many files the original was extracted to, and for every extracted file say Part 1 of 6, or how many files it was extracted too
Copy link to clipboard
Copied
The watermark function just adds fixed text. You need to do any counting and make the string labels in the normal way, before watermarking. You do the extracting so you can count each one.
Copy link to clipboard
Copied
In your script, add another increment variable in the loop for keeping track of the number of sections. Then this can be used to create the watermark text. Something like this.
var n = 1;
var nParts = Math.ceil(this.numPages/5);
for(....)
{
....
oNewDoc = ....
....
oNewDoc.addWatermarkFromText({cText: "Part "+n + " of " + nParts, ...})
oNewDoc.saveAs...
}
Copy link to clipboard
Copied
var re = /\.pdf$/i;
var filename = this.documentFileName.replace(re,"");
var n = 1;
var nParts = Math.ceil(this.numPages/998);
try {for (var i = 0; i < this.numPages; i+= 998){
var oNewDoc = this.extractPages({
nStart: i,
nEnd: (((i+997)>=this.numPages) ? this.numPages-1 : (i+997)),
});
oNewDoc.newPage({nPage: 0});
oNewDoc.addWatermarkFromText({cText: "Part "+n + " of " + nParts,
nStart: 0});
oNewDoc.saveAs({cPath: "/K/Penta/Split/"+filename+"_" +"Pages_" + (i+1) + "-" + (((i+998)>=this.numPages) ? this.numPages : (i+998)) +".pdf"});
n++;
}
} catch (e) { console.println("Aborted: " + e) }
Work Just as I want, Thanks
Copy link to clipboard
Copied
Excellent!! How about marking a correct answer?