5 Replies Latest reply on Feb 27, 2008 7:27 AM by Loic.Aigon

    [AS] Problem with exporting all pages individually

    Loic.Aigon Adobe Community Professional
      Hi, I ain't found any solutions by my self or on the web, so I hope, someone can help here.
      I wrote this piece of AS code. I wish it exports all the pages as separate PDFs.
      Alas, it crashes saying that the script ca't understand the page range.
      Could you please telle me where I do bad ?

      set Fpath to (choose folder with prompt "pick") as string

      tell application "Adobe InDesign CS3"
      set mydoc to active document
      set pcount to count pages of mydoc
      repeat with p from 1 to pcount
      tell PDF export preferences
      set page range to p as string
      end tell
      set docname to "toto" & "_" & p & ".pdf"
      set pdfname to Fpath & docname
      export to file (pdfname) format PDF type using "[PDF/X-1a:2001]" without showing options
      end repeat
      end tell

      thanks in advance,

      Loic
        • 1. Re: [AS] Problem with exporting all pages individually
          sstanleyau Level 4
          Is it possible you have section numbering and there is no page named "1"?<br />Try setting to absolute numbering and see if it works.<br /><br />-- <br />Shane Stanley <sstanley@myriad-com.com.au>
          • 2. Re: [AS] Problem with exporting all pages individually
            Kasyan Servetsky Level 5
            Hi Loic,

            I think when you set page range in the loop you should use “name” property of the page object:
            set page range of PDF export preferences to name of page p of mydoc
            See “Exporting Individual Pages to PDF example” on page 39 in InDesignCS3_ScriptingGuide_AS.pdf – it’s very similar to what you are trying to do.
            You can also download the free Page Exporter Utility here: http://indesignsecrets.com/page-exporter-utility-peu-5-script-updated-for-cs3.php.

            Kasyan
            • 3. Re: [AS] Problem with exporting all pages individually
              Loic.Aigon Adobe Community Professional
              Hi Shane & Kasyan,
              Sorry for the late answer, I have been busy here and in fact I even had not the occasion to try your advices until now.
              Unfortunalety, I am still stuck. Using the page name has no effect and the script still crashes.
              I ain't used any page section so it's no a way too. I am not sure I understood wel what you suggests with absolute numbering but I am digging that way and see if I can find anything.
              I will have a look on the page exporter tool but whatever the way, I need to achieve by my own. Indeed I want to produce a mini application form my code for any of my colleagues to use it.
              I will find, I will get it !
              Thanks a lot for trying to help.
              Loic
              • 4. Re: [AS] Problem with exporting all pages individually
                Kasyan Servetsky Level 5
                Hi Loic,

                Here is a little altered version of the ExportEachPageAsPDF script from the examples provided by Adobe. I assume, from the script you posted, that you want exported files to be named in the following way: toto + _ + page number + .pdf. But in my judgement, it would be more reasonable to use the name of active document without extension instead of "toto".
                Why are you trying to reinvent the wheel? Isn't it better to take a ready-made script and remake it to your needs?

                Kasyan
                --------------------------------
                tell application "Adobe InDesign CS3"
                if (count documents) is not equal to 0 then
                my myChooseFolder()
                else
                display dialog "Please open a document and try again."
                end if
                end tell
                on myChooseFolder()
                set myFolder to choose folder with prompt "Choose a Folder"
                --Get the folder name (it'll be returned as a Unicode string)
                set myFolder to myFolder as string
                --Unofficial technique for changing Unicode folder name to plain text string.
                set myFolder to "class ktxt" of (myFolder as record)
                if myFolder is not equal to "" then
                my myExportPages(myFolder)
                end if
                end myChooseFolder
                on myExportPages(myFolder)
                tell application "Adobe InDesign CS3"
                set myDocument to active document
                --set myDocumentName to name of myDocument
                repeat with myCounter from 1 to (count pages in myDocument)
                set myPageName to name of page myCounter of myDocument
                set page range of PDF export preferences to name of page myCounter of myDocument
                --Generate a file path from the folder name, the base document name, and the page name.
                --Replace any colons in the page name (e.g., "Sec1:1") so that they don't cause
                --problems with file naming.
                set myPageName to my myReplace(myPageName, ":", "_")
                set myFilePath to myFolder & "toto" & "_" & myPageName & ".pdf"
                tell myDocument
                --The export command will fail if you provide the file path
                --as Unicode text--that's why we had to convert the folder name
                --to plain text.
                export format PDF type to myFilePath using "[PDF/X-1a:2001]"
                end tell
                end repeat
                end tell
                end myExportPages
                on myReplace(myString, myFindString, myChangeString)
                set AppleScript's text item delimiters to myFindString
                set myTextList to every text item of (myString as text)
                set AppleScript's text item delimiters to myChangeString
                set myString to myTextList as string
                set AppleScript's text item delimiters to ""
                return myString
                end myReplace
                • 5. Re: [AS] Problem with exporting all pages individually
                  Loic.Aigon Adobe Community Professional
                  SOLVED at last !

                  Hi Kasyan,

                  b Thanks for all your help
                  You are right, trying to reinvent the wheel is one of my worst defaults.
                  Anyway, I finally succeed. It was dumb as usually in this cases.
                  In fact, I just forgot to tell active document to export...So I guess the script failed cause of a lack of reference.

                  Toto is for me a generic name for debugging purposes. It's clear that in the end, the final PDF name has to to be the name of the actual document.
                  As I begin scripting AS, I progress very shortly from one step to another.

                  Thanks again for worry.

                  Loic