9 Replies Latest reply on Feb 14, 2008 1:38 PM by Really Randy

    "Save each page as PDF" naming mod?

    Really Randy Level 1
      I have a data merged document that has around 500 records that has been exported to a 500 page document.

      I use either the "Page Exporter Utility" or a similar js that will save each page as an individual PDF.

      The trouble I'm having is:
      I have the job number embedded in a text box in the slug area. I'd like to automatically use that job number to name the PDF upon export.
      Does anyone know how I can pull text from a textbox to use as a file name in js?

      As always, thanks to everyone for their help

      Randy
        • 1. Re: "Save each page as PDF" naming mod?
          Peter Kahrel Adobe Community Professional & MVP
          How do you identify the text frame? Does it have a unique label? Does what is in it have a unique paragraph style name?

          Peter
          • 2. Re: "Save each page as PDF" naming mod?
            Really Randy Level 1
            The easiest thing to do would be to give it a unique paragraph style. I could also put it on it's own layer. I'm not sure how difficult it would be to mod the excellent "Page Exporter Utility 5.0" but that would be my preference.
            • 3. Re: "Save each page as PDF" naming mod?
              Kasyan Servetsky Level 5
              Hi Randy,
              I would label the text box in the slug area with something like "My job number" in Script Label panel. Then I would read the contents of the text box:

              myDoc = app.activeDocument;
              var myText = myDoc.textFrames.item("My job number").contents;
              alert("My job number is " + myText);

              Kasyan
              • 4. Re: "Save each page as PDF" naming mod?
                Peter Kahrel Adobe Community Professional & MVP
                But there are 500 records. Randy, can you identify the job numbers in any way? Do they have any particular number or alphsnumerical format such that you can find them (and nothing else)? You can then label the text frames they're in.

                Peter
                • 5. Re: "Save each page as PDF" naming mod?
                  Really Randy Level 1
                  Thanks for responding, yes, all job numbers start wit "pnxx-" followed by a 4 digit number. i.e, "pnxx-1234".

                  Randy
                  • 6. Re: "Save each page as PDF" naming mod?
                    Peter Kahrel Adobe Community Professional & MVP
                    In that case you can label all their containing text frames like this:

                    app.findTextPreferences = null;
                    app.findTextPreferences.findWhat = 'pnxx-^9^9^9^9';
                    f = app.activeDocument.findText();
                    for (i = 0; i < f.length; i++)
                       f[i].parentTextFrames[0].label = 'jobnumber';

                    Then the exporter can retieve the jobnumber on each page like this:

                    //script
                    //more script
                    // you probably have a for-loop that iterates through
                    // the document page by page
                    for (i = 0; i < myDoc.pages.length; i++)
                    {
                    jobnum = doc.pages[i].textFrames.item ('jobnumber').contents;
                    filename = ...
                    //export
                    }
                    • 7. Re: "Save each page as PDF" naming mod?
                      Really Randy Level 1
                      OK, I finally have time to mess with this thing.
                      I put in the lines that Peter so kindly posted here. There are a few things that I'm still not getting though.

                      in the first part of the suggestion I see that it runs through the document and finds the text box with my job number and labels it "jobnumber"
                      If I label the text box on the master page "jobnumber" before I import the data merge, that would probably do the trick, right?

                      The second part of the script I'm really just not getting.

                      Here's what I have (with the previous code still intact, just commented out.)

                      As always, Thanks a million!

                      //############################################################################
                      // # An InDesign CS3 JavaScript
                      // # Exports each page of an InDesign CS document as a separate PDF to
                      // # a selected folder using the current PDF export settings.
                      // ############################################################################


                      i //Display a choose folder dialog box.
                      if(app.documents.length != 0){
                      var myFolder = Folder.selectDialog (Choose a Folder);
                      if(myFolder != null){
                      myExportPages(myFolder);
                      }
                      }
                      else{
                      alert(Please open a document and try again.);
                      }

                      i //Find the textbox that contains the job number.

                      app.findTextPreferences = null;
                      app.findTextPreferences.findWhat = pnxx-^9^9^9^9;
                      f = app.activeDocument.findText();
                      for (i = 0; i < f.length; i++)
                      f[i].parentTextFrames[0].label = jobNumber;

                      function myExportPages(myFolder){
                      var myPageName, myFilePath, myFile;
                      var myDocument = app.activeDocument;
                      var myDocumentName = myDocument.name;
                      var myDialog = app.dialogs.add();
                      with(myDialog.dialogColumns.add().dialogRows.add()){
                      staticTexts.add({staticLabel:Base name:});
                      var myBaseNameField = textEditboxes.add({editContents:myDocumentName, minWidth:160});
                      }
                      var myResult = myDialog.show({name:ExportPages});
                      if(myResult == true){
                      var myBaseName = myBaseNameField.editContents;

                      i //Remove the dialog box from memory.

                      myDialog.destroy();

                      i /* for(var myCounter = 0; myCounter < myDocument.pages.length; myCounter++){
                      i myPageName = myDocument.pages.item(myCounter).name;
                      i app.pdfExportPreferences.pageRange = myPageName;
                      i */

                      for (i = 0; i < myDocument.pages.length; i++)
                      {
                      jobnum = myDocument.pages[i].textFrames.item (jobNumber).contents;

                      i //The name of the exported files will be the base name + the page name + .pdf.
                      i //If the page name contains a colon (as it will if the document contains sections),
                      i //then remove the colon.
                      var myRegExp = new RegExp(:,gi);
                      myPageName = myPageName.replace(myRegExp, _);
                      i // myFilePath = myFolder + / + myBaseName + _ + myPageName + .pdf;
                      myFilePath = myFolder + / + myBaseName + _ + jobnum + .pdf;
                      myFile = new File(myFilePath);
                      myDocument.exportFile(ExportFormat.pdfType, myFile, false);
                      }
                      }
                      else{
                      myDialog.destroy();
                      }
                      }
                      • 8. Re: "Save each page as PDF" naming mod?
                        Peter Kahrel Adobe Community Professional & MVP
                        Well, you don't really have to label anything beforehand. What you need to do is this: find all job numbers, then for each jobnumber, get the page it's on and export it. The script below does that (assuming that text frames in the bleed area behave the same as any other text frame). It doesn't do any error-checking, it's just something to start off with.

                        Peter

                        destination_folder = '/d/';

                        doc = app.activeDocument;
                        doc.sections.everyItem().includeSectionPrefix = false;
                        app.findTextPreferences = null;
                        app.findTextPreferences.findWhat = 'pnxx-^9^9^9^9';
                        found = doc.findText();
                        for (i = 0; i < found.length; i++ )
                        {
                        f = File (destination_folder + found[i].contents + '.pdf');
                        app.pdfExportPreferences.pageRange = found[i].parentTextFrames[0].parent.name;
                        doc.exportFile (ExportFormat.pdfType, f, false);
                        }
                        • 9. Re: "Save each page as PDF" naming mod?
                          Really Randy Level 1
                          Awesome!
                          Here's the mods I made. This works like a charm. If you want to mod the search just change the "pnxx-^9^9^9^9" part and set the PDF preset by changing the "TV0verlay" part.

                          This one is so much cleaner than the Adobe supplied "Save Each Page as PDF" script.
                          ++++++++++++++++++++++++++++++++++

                          var destinationFolder = Folder.selectDialog ("Choose a Folder");

                          var myPDFExportPreset = app.pdfExportPresets.item("TV0verlay");

                          doc = app.activeDocument;
                          doc.sections.everyItem().includeSectionPrefix = false;
                          app.findTextPreferences = null;
                          app.findTextPreferences.findWhat = 'pnxx-^9^9^9^9';
                          found = doc.findText();
                          for (i = 0; i < found.length; i++ )
                          {
                          f = File (destinationFolder + "/" + found[i].contents + '.pdf');
                          app.pdfExportPreferences.pageRange = found[i].parentTextFrames[0].parent.name;
                          doc.exportFile (ExportFormat.pdfType, f, false, myPDFExportPreset);
                          }
                          +++++++++++++++++++++++++++++++++++