3 Replies Latest reply on Jun 10, 2017 6:16 AM by Laubender

    PDF export script question

    chadlindsey Level 1

      Hopefully someone can help.

      I have a script that has been good for years, but just noticed that any pages that have a prefix in the page layout will not be exported when the script is run.

      The script runs through every page within the page layout, and exports the PDF based on the selected export preset. If the page was renamed with a prefix, it is skipped. Any thoughts?

       

      Thanks, Chad

       

      activate

      with timeout of 86400 seconds

        tell application "Adobe InDesign CC 2017"

        set doc_name to active document

        set doc_pages to every page of doc_name

        set file_name to text returned of (display dialog "Please enter a File Name:" default answer "" buttons {"Cancel", "Ok"} default button 2 with icon 1)

        set pdf_style to name of every PDF export preset

        set export_style to (choose from list pdf_style with prompt "Select PDF Export Preset") as string

        set folder_path to (choose folder with prompt "Please select your destination folder...") as string

       

        repeat with anItem in doc_pages

        set page_number to name of anItem as string

        count characters of page_number

        if length of page_number is 1 then

        set new_number to text -3 thru -1 of ("00" & page_number)

        end if

        if length of page_number is 2 then

        set new_number to text -3 thru -1 of ("0" & page_number)

        end if

        if length of page_number is 3 then

        set new_number to page_number

        end if

        if length of page_number is 4 then

        set new_number to page_number

        end if

        set PDF_name to folder_path & file_name & "_" & new_number & ".pdf"

        set page range of PDF export preferences to page_number

        tell doc_name

        export format PDF type to PDF_name using export_style without showing options

        end tell

        end repeat

       

        beep 3

        display dialog "Your PDFs were successfully exported" buttons {"Done"} default button 1

        end tell

      end timeout

        • 1. Re: PDF export script question
          david_p Level 1

          If your document has, for example, a page "1" and page "A1", the page name property will be "1" for both pages. The script would create a PDF of page 1 twice, overwriting the first PDF on the second pass. You'll need to include a check to as to whether the section prefix of the applied section property is an empty string—if not, then include the section prefix when concatenating the desired PDF file name. The other issue is setting the page range of the PDF export preferences with the name of the page. I don't have time to test it right now, but one way to work around that is to use the document offset property, which is similar to absolute page numbering, instead of the page name property.

          • 2. Re: PDF export script question
            Laubender Adobe Community Professional & MVP

            Hi,

            I'm not much into AppleScript so I cannot give code samples.


            David outlined some problems with your approach.
            There is another detail, a case where PDFs can be overwritten because of page naming:
            Prefix or not: Two or more pages that share the same name in different sections.

             

            What's not clear for me:
            What would you like to get as desired output if a document has the following page names where are two sections and section two is prefixed with "A" for e.g. "Appendix".

             

            "220","221","222","223","1","2","3"

             

            Should it be:

            220.pdf , 221.pdf , 222.pdf, 223.pdf, 224A1.pdf, 225A2.pdf, 226A3.pdf ?

            or something else?

             

            Then you could do two things:
            1. Set the naming of the pages so that the prefixes are added to the page names.

            That would lead to names I suggested with my little example above.

             

            In ExtendScript code this would be:

             

            app.activeDocument.sections.everyItem().includeSectionPrefix = true;
            

             

            This is doable in AppleScript as well.

            EDIT: Also doable in the UI, but not in one go like the script line above.

             

            2. But one problem remains: If two sections share the same page names—and/or the same prefixes—still files will be overwritten.
            Maybe a rare case, because every InDesign user is given a fair warning if trying to set up sections like that, but who knows:
            The user can deny the warning or turn off warnings with that "Don't show again" checkbox so that InDesign will give no warning at all.

             

            So you need a control system if a document page has the same name like a different one in the same document.

             

            Regards,
            Uwe

            • 3. Re: PDF export script question
              Laubender Adobe Community Professional & MVP

              A third item added:

              3. Make sure that the files you want to write do not already exist.
              You could check this before writing any file to disk.

               

              Regards,
              Uwe