Skip to main content
Participant
January 27, 2015
Answered

Defining page range for PDF export

  • January 27, 2015
  • 3 replies
  • 6375 views

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.

This topic has been closed for replies.
Correct answer Laubender

@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

3 replies

May 30, 2017

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.

lfcorullon13651490
Legend
May 30, 2017

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>

May 30, 2017

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.

May 29, 2017

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.

lfcorullon13651490
Legend
May 29, 2017

To point to the first page use app.activeDocument.pages[0].

The second, app.activeDocument.pages[1]. And so on...

May 30, 2017

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.

LaubenderCommunity ExpertCorrect answer
Community Expert
January 27, 2015

@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

Participant
January 27, 2015

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

Community Expert
January 27, 2015

@Tim – did you test your code? I did.

And yes. It's working…

Uwe