Copy link to clipboard
Copied
Hello,
I am trying to automate a PDF export process, where a single indesign file has to be exported as multiple PDFs into a specifically named folder structure. I have placed the information that the script needs on a non-printing layer on the first page of each PDF (The filename for the PDF and the foldername to put it in). My script successfully stores this information, along with the page number on which it was found.
The problem is that the indesign documents are divided into several sections and alternate layouts; when my script loops through the pages to harvest the information it stores the pages by their position in a zero-based array, not by their actual page numbers. It seems that it is the actual page numbers that are needed to define the page range for export. As the page numbers are repeated across the alternate layouts, I'm guessing would need to specify I section and a page number.
I can get the number of the page with pages.name, but how do I get the section number and put these two together in my page range definition?
BTW, all the PDFs are continuous page ranges, although sometimes they bridge section breaks.
Many thanks for any help.
@Tim – if you already have a zero based array, I would convert that to a special string representation.
1. Use the property documentOffset of a specific page and build a new array with that.
2. Add 1 to every number in the array
3. Make a string out of it and add "+" to every number in that string to get the absolute string notation for the page range
If you do an export or if you are printing pages, you could always use a string like that to get an absolute range to export or print pages:
"+1 - +10"
...Copy link to clipboard
Copied
@Tim – if you already have a zero based array, I would convert that to a special string representation.
1. Use the property documentOffset of a specific page and build a new array with that.
2. Add 1 to every number in the array
3. Make a string out of it and add "+" to every number in that string to get the absolute string notation for the page range
If you do an export or if you are printing pages, you could always use a string like that to get an absolute range to export or print pages:
"+1 - +10"
"+1,+2,+3,+5,+6"
"+1" is always the first page of a document. Its document offset is 0. => "+"+String(0+1)
"+2" is always the second page of a document. Its document offset is 1. => "+"+String(1+1)
Or more generally spoken:
"+"+String(myPage.documentOffset+1);
var myArrayOfDocumentOffsets = [0,1,2,3,8,9,10,12,25];
for(var n=0;n<myArrayOfDocumentOffsets.length;n++){
myArrayOfDocumentOffsets
= myArrayOfDocumentOffsets +1; };
var myString = myArrayOfDocumentOffsets.join(",").replace(/(\d+)/g,"+$1");
Now you can use that string as value for the pageRange of your export function.
You provided no code, so you have to implement this yourself…
Uwe
Copy link to clipboard
Copied
Hi Uwe,
Many thanks for your reply. SO if I understand correctly, I can define the page range in the "+1-+10" format, and these are the overall numbers of the pages in the document run, irrespective of section breaks. So, in code, something like this:
var myPDFExportPreset = app.pdfExportPresets.item("IPAD PDF EXPORT");
with(app.pdfExportPreferences){
//pageRange can be either PageRange.allPages or a page range string
//(just as you would enter it in the Print or Export PDF dialog box).
pageRange = "+1-+10";
}
myDoc.exportFile(ExportFormat.PDF_TYPE,File(currentFolder+"/"+"P1-1.pdf"),false, myPDFExportPreset);
This would export pages 1 to 10?
Thanks again,
Tim
Copy link to clipboard
Copied
@Tim – did you test your code? I did.
And yes. It's working…
Uwe
Copy link to clipboard
Copied
And Tim – it would be good practice to reset your pageRange to the inital value.
And: You could also try the asynchronousExportFile() method if you want to do you export in the background.
See documentation:
Adobe InDesign CS6 (8.0) Object Model JS: Document
Uwe
Copy link to clipboard
Copied
Uwe - thanks for all your help; it took a bit of fiddling, but I have it working now.
Thanks again,
Tim
Copy link to clipboard
Copied
How can I implement this page range script to be functional in conjunction with the popular batch convert script?
I’m attempting to batch PDF the first two pages (i.e. 1st spread) within multi-page indesign documents.
I’m a noob when it comes to scripting, but it seems my page range would look like: +1-+2, correct?
How do I manufacture a script that does that?
The batch convert script has a script add-on feature, so that is what gives me hope that this might work.
Any help is appreciated. Cheers.
Copy link to clipboard
Copied
To point to the first page use app.activeDocument.pages[0].
The second, app.activeDocument.pages[1]. And so on...
Copy link to clipboard
Copied
The below screenshot displays the popular batch script I’m currently using. It has a script add-on feature (“Run a script” as seen below in the screenshot, third line from the bottom).
So how can I take the info you just wrote and apply it so that I can add it to this script, using that “Run a script” feature?
I have no idea how to get this running, I’m guessing I would save a jsx file using textEdit or something, but I don’t see how using what you gave me can bring about that directly?
Any feedback is appreciated.
*Remember I’m merely trying to get a simple script that PDFs the first two pages of multi-page documents (i.e. +1-+2).
Batch converter dialogue within indesign screenshot.
Copy link to clipboard
Copied
Don't use this script.
Just save the code below as .jsx file and use it in InDesign.
It'll export just pages 1 and 2 from the activeDocument to PDF.
If you want to change the destination folder, just write it where I put "~/Desktop/..."
You can change the PDF name to your activeDocument file name too... improving the script code.
#target indesign
with(app.pdfExportPreferences){
pageRange = "1,2";
}
var myPDFExportPreset = app.pdfExportPresets.item("[High Quality Print]")
app.activeDocument.exportFile(ExportFormat.pdfType, File("~/Desktop/myTestDocument.pdf"), false, myPDFExportPreset);
Copy link to clipboard
Copied
Yeah but I need to use the batch convert script, because I need to process many indd documents, which some containing the first two pages (i.e. first spread) that I need to PDF, understand?
I’ll try to see if I can add the script you provided with the batch convert script.
Thanks again. I really appreciate any help.
Copy link to clipboard
Copied
It didn’t work. I saved as a jsx within TextEdit, and added it to the batch convert script, ran it, and it didn’t give any errors either.
It did behave slightly differently in that each document was opened within indesign and closed afterwards, or it’s the first time it was slow enough for me to visually see it doing this.
I feel like it’s so close.
Thanks again anyway.
If you can assist further with the little info I’ve provided I would really appreciate it. Cheers.
Finder view showing all spreads PDF’d instead of only top spread (i.e. 2-3) screenshot.
Copy link to clipboard
Copied
I would try only the first improved lines...
1. var page1 = app.activeDocument.pages[0].name;
2. var page2 = app.activeDocument.pages[1].name;
3. with(app.pdfExportPreferences){
4. pageRange = page1, page2;
5. }
Em 29 de mai de 2017 11:10 PM, "adobe1kenobe066" <forums_noreply@adobe.com>
escreveu:
Adobe Community <https://forums.adobe.com/?et=watches.email.thread>
Defining page range for PDF export
resposta de adobe1kenobe066
<https://forums.adobe.com/people/adobe1kenobe066?et=watches.email.thread>
em InDesign Scripting - Visualize a discussão completa
<https://forums.adobe.com/message/9543402?et=watches.email.thread#9543402>
Copy link to clipboard
Copied
It failed again (screenshots 1-3 below).
If you can, please feel free to let me know what I’m doing wrong.
Remember I’m attempting to PDF only the first two pages (i.e. first spread) in a indd document that has many pages within it.
Thanks again.
1. text edit javascript screenshot.
2. pageRange javascript attached to batch pdf script screenshot.
3. All pages PDF, instead of the goal, which is to PDF only first two pages (i.e. first spread) screenshot.
Copy link to clipboard
Copied
FWIW: Property/Value pairs in objects do not use the = operator for coupling.
Instead use the : operator and stringify the comma:
{ pageRange : page1+","+page2 }
Better defined with absolute numbering. Then you do not need variables page1 and page2 at all:
{ pageRange : "+1,+2" }
Note: Not tested.
I do not think, that changing app.pdfExportPreferences will work at all with Peter Kahrel's script.
Instead I would follow a different strategy.
Run a script that will remove all pages but the first 2 ones.
/*
Strategy:
To export only the first 2 pages, remove all others, export and do not save when closing the document.
WARNING:
Do not save the InDesign documents when run with
Peter Kahrel's Batch Processor Script!
ALWAYS DO:
[ ] Save documents on closing
DO NOT:
Save documents on closing
*/
// Removes all pages on the processed document, but pages [0] and [1]:
if(app.documents[0].pages.length > 2)
{
app.documents[0].pages.itemByRange(2,-1).remove();
};
Regards,
Uwe
Copy link to clipboard
Copied
Wow. You are the man dude, that is bad-assery. It worked like a charm.
Thanks so much dude, really.
Incredible.
Copy link to clipboard
Copied
Also, the indd spreads are still in tact with all the spread, so perfect.
Thanks again man. Really appreciate it.
Find more inspiration, events, and resources on the new Adobe Community
Explore Now