9 Replies Latest reply on Apr 29, 2018 11:17 PM by Stephen_A_Marsh

    How can I extract Trim, Art, Bleed and Crop Box information from PDF document

    iiyamaProLite

      I want to know where in PDF are these information saved. I need my program to know these numbers without me manually rewriting them.

        • 1. Re: How can I extract Trim, Art, Bleed and Crop Box information from PDF document
          Bernd Alheit Adobe Community Professional & MVP

          You can get this information with Acrobat Javascript.

          • 2. Re: How can I extract Trim, Art, Bleed and Crop Box information from PDF document
            MichaelN Level 3

            Use the getPageBox method.

             

            getPageBox can get the dimensions of the following:

             

            Art

            Bleed

            BBox

            Crop (default)

            Trim

             

            There is an example in the JavaScript for Acrobat reference that gets the dimensions of the media box and displays it in the console window:

             

            var aRect = this.getPageBox("Media");

            var width = aRect[2] - aRect[0];

            var height = aRect[1] - aRect[3];

            console.println("Page 1 has a width of " + width + " and a height of " + height);

            • 3. Re: How can I extract Trim, Art, Bleed and Crop Box information from PDF document
              gkaiseril MVP & Adobe Community Professional

              The dimensions are in printer points, 1/72 of an inch.

              • 5. Re: How can I extract Trim, Art, Bleed and Crop Box information from PDF document
                Stephen_A_Marsh Adobe Community Professional

                By default this is only for page 1 of a multi-page PDF.

                 

                How to gracefully handle multiple pages?

                 

                I can't script, however looking at the reference material an optional input of getPageLabel will query the page (with zero 0=1st page, 1=2nd page etc).

                • 7. Re: How can I extract Trim, Art, Bleed and Crop Box information from PDF document
                  Stephen_A_Marsh Adobe Community Professional

                  Thanks Thom, yes I have previously found that article, however I did not find any info on the getPageLabel feature in order to target the PageBox info on that page.

                   

                  EDIT: Or do you mean something different, such as:

                   

                  this.pageNum = 0; // Page 1

                  this.pageNum++; //Advance the document to the next page

                   

                  The method of returning the various page box data via an app.alert would then either be hard coded per page, or would require a GUI or something else, all of which is beyond my current scripting skills (which amount to minor hacks).

                   

                  EDIT: What I mean is that page 1 and page 2 could have two different cropbox values, so how to report on this via scripting? If the currently viewed page could be used as a variable reference when the below script is run, then that would solve the issue of needing a page selection GUI etc. Ideally this script is for use in Acrobat Reader, as Acrobat Pro has native methods of showing this data.

                   

                   

                  function ThePageSize(){    
                  var aRect = this.getPageBox("Crop");    
                  var aWidth = aRect[2] - aRect[0];    
                  var aHeight = aRect[1] - aRect[3];    
                  var bRect = this.getPageBox("Art");    
                  var bWidth = bRect[2] - bRect[0];    
                  var bHeight = bRect[1] - bRect[3];    
                  var cRect = this.getPageBox("Trim");    
                  var cWidth = cRect[2] - cRect[0];    
                  var cHeight = cRect[1] - cRect[3];    
                  var dRect = this.getPageBox("Bleed");    
                  var dWidth = dRect[2] - dRect[0];    
                  var dHeight = dRect[1] - dRect[3];    
                  var eRect = this.getPageBox("Media");    
                  var eWidth = eRect[2] - eRect[0];    
                  var eHeight = eRect[1] - eRect[3];    
                  app.alert("Crop: " + Math.round(aWidth*0.3528*100)/100 + " mm x " + Math.round(aHeight*0.3528*100)/100 + " mm" + "\n\n" +    
                    ("Art: " + Math.round(bWidth*0.3528*100)/100 + " mm x " + Math.round(bHeight*0.3528*100)/100 + " mm") + "\n\n" +    
                    ("Trim: " + Math.round(cWidth*0.3528*100)/100 + " mm x " + Math.round(cHeight*0.3528*100)/100 + " mm") + "\n\n" +    
                    ("Bleed: " + Math.round(dWidth*0.3528*100)/100 + " mm x " + Math.round(dHeight*0.3528*100)/100 + " mm") + "\n\n" +    
                    ("Media: " + Math.round(eWidth*0.3528*100)/100 + " mm x " + Math.round(eHeight*0.3528*100)/100 + " mm")    
                  );    
                  }    
                  app.addMenuItem ({cName: "Show PageBox Sizes", cParent: "View", cExec: "ThePageSize()" });  
                  
                  • 8. Re: How can I extract Trim, Art, Bleed and Crop Box information from PDF document
                    Stephen_A_Marsh Adobe Community Professional

                    Thanks again Thom, you forced me to answer my own question! So, if no explicit page number is entered, then this.pageNum is treated as a variable, dependent on the current active/viewed page! Fantastic stuff!

                     

                    So the revised code is:

                     

                    function ThePageSize(){
                    var aRect = this.getPageBox("Crop",this.pageNum);
                    var aWidth = aRect[2] - aRect[0];
                    var aHeight = aRect[1] - aRect[3];
                    var bRect = this.getPageBox("Art",this.pageNum);
                    var bWidth = bRect[2] - bRect[0];
                    var bHeight = bRect[1] - bRect[3];
                    var cRect = this.getPageBox("Trim",this.pageNum);
                    var cWidth = cRect[2] - cRect[0];
                    var cHeight = cRect[1] - cRect[3];
                    var dRect = this.getPageBox("Bleed",this.pageNum);
                    var dWidth = dRect[2] - dRect[0];
                    var dHeight = dRect[1] - dRect[3];
                    var eRect = this.getPageBox("Media",this.pageNum);
                    var eWidth = eRect[2] - eRect[0];
                    var eHeight = eRect[1] - eRect[3];
                    app.alert("Crop: " + Math.round(aWidth*0.3528*100)/100 + " mm x " + Math.round(aHeight*0.3528*100)/100 + " mm" + "\n\n" +
                      ("Art: " + Math.round(bWidth*0.3528*100)/100 + " mm x " + Math.round(bHeight*0.3528*100)/100 + " mm") + "\n\n" +
                      ("Trim: " + Math.round(cWidth*0.3528*100)/100 + " mm x " + Math.round(cHeight*0.3528*100)/100 + " mm") + "\n\n" +
                      ("Bleed: " + Math.round(dWidth*0.3528*100)/100 + " mm x " + Math.round(dHeight*0.3528*100)/100 + " mm") + "\n\n" +
                      ("Media: " + Math.round(eWidth*0.3528*100)/100 + " mm x " + Math.round(eHeight*0.3528*100)/100 + " mm")
                    );
                    }
                    app.addMenuItem ({cName: "Show PageBox Sizes", cParent: "View", cExec: "ThePageSize()" });
                    
                    • 9. Re: How can I extract Trim, Art, Bleed and Crop Box information from PDF document
                      Stephen_A_Marsh Adobe Community Professional

                      Adding a current page and total page label:

                       

                      numPages.png

                       

                      function ThePageSize(){
                      var aRect = this.getPageBox("Crop",this.pageNum);
                      var aWidth = aRect[2] - aRect[0];
                      var aHeight = aRect[1] - aRect[3];
                      var bRect = this.getPageBox("Art",this.pageNum);
                      var bWidth = bRect[2] - bRect[0];
                      var bHeight = bRect[1] - bRect[3];
                      var cRect = this.getPageBox("Trim",this.pageNum);
                      var cWidth = cRect[2] - cRect[0];
                      var cHeight = cRect[1] - cRect[3];
                      var dRect = this.getPageBox("Bleed",this.pageNum);
                      var dWidth = dRect[2] - dRect[0];
                      var dHeight = dRect[1] - dRect[3];
                      var eRect = this.getPageBox("Media",this.pageNum);
                      var eWidth = eRect[2] - eRect[0];
                      var eHeight = eRect[1] - eRect[3];
                      var pageLabel = this.pageNum + 1;
                      var totalPages = this.numPages;
                      app.alert("Page: " + pageLabel + " of " + totalPages + " pages" + "\n\n" + ("Crop: " + Math.round(aWidth*0.3528*100)/100 + " mm x " + Math.round(aHeight*0.3528*100)/100 + " mm" + "\n\n" + ("Art: " + Math.round(bWidth*0.3528*100)/100 + " mm x " + Math.round(bHeight*0.3528*100)/100 + " mm") + "\n\n" + ("Trim: " + Math.round(cWidth*0.3528*100)/100 + " mm x " + Math.round(cHeight*0.3528*100)/100 + " mm") + "\n\n" + ("Bleed: " + Math.round(dWidth*0.3528*100)/100 + " mm x " + Math.round(dHeight*0.3528*100)/100 + " mm") + "\n\n" + ("Media: " + Math.round(eWidth*0.3528*100)/100 + " mm x " + Math.round(eHeight*0.3528*100)/100 + " mm")
                      ));
                      }
                      app.addMenuItem ({cName: "Show PageBox Sizes", cParent: "View", cExec: "ThePageSize()" });