2 Replies Latest reply on Feb 9, 2017 2:54 PM by Jump_Over

    Create a document with the same number of pages as the selected pdf

    arekh2792424 Level 1

      Hello everyone,

           I am running into a problem where my indesign just completely freezes returning no error code when I run this script, the goal is that indesign will create a document with the same number of pages as the selected pdf. This is what I have so far:

       

      Initialization();

      function Initialization() {

          //prompt user to select a file.

          var selectedFile = File.openDialog("Choose a PDF File");

          //Retrieve the page count of the selected file.

          var pageCount = readPageCount(selectedFile);

          createDoc(selectedFile, pageCount);

      }

      // This function is based on another script and believe the issue lies within this section here:

      function readPageCount(selectedFile) {

        // Read in first line of section

        var theLine = selectedFile.readln();

        // Locate the line containing the /Count entry

        while(theLine.indexOf("/Count") == -1)

        {

        theLine = selectedFile.readln();

        }

        // Extract the page count

        return parseInt(theLine.substring(theLine.indexOf("/Count") +6), 10);

      }

      function createDoc(selectedFile, pageCount) {

          //Create a new document with the same number of pages as the selected document.

          var BC10UP = app.documents.add();

          with (BC10UP.documentPreferences) {

              pageHeight = "11in";

              pageWidth = "8.5in";

              pageOrientation = PageOrientation.landscape;

              pagesPerDocument = pageCount; }

      }

       

       

      any help or advice is much appreciated!!