9 Replies Latest reply on May 20, 2015 12:10 PM by George_Johnson

    How does one determine if a page is in Default User Space or Rotated User Space?

    jasonh8531847

      I've really been trying to figure this out, but there doesn't seem to be an easy way to figure this out. Anyone have any suggestions?

       

      Thanks,

      Jason

        • 1. Re: How does one determine if a page is in Default User Space or Rotated User Space?
          try67 MVP & Adobe Community Professional

          It's not a question of having one or the other. Each page has both (although they can be the same)...

          This is a complex subject. You can read more about it in section 8.3.2.3 of the PDF ISO Specification.

          • 2. Re: How does one determine if a page is in Default User Space or Rotated User Space?
            George_Johnson MVP & Adobe Community Professional

            Various coordinates are specified in either default (e.g., doc.addAnnot) or rotated (e.g., doc.addField) user space. To see what a page's rotation is, use the doc.getPageRotation method.

            • 3. Re: How does one determine if a page is in Default User Space or Rotated User Space?
              jasonh8531847 Level 1

                   I've attempted to use the doc.getPageRotation method on several occasions, but it always seems to come back with 0 even when, at least with what I can see, the document is rotated by 90 degrees. The problem is I'm attempting to add about 30 - 50 points to the "bottom" of the current page, regardless of whether or not it is in default or rotated user space (or rotated), but haven't been able to determine when the page is in each state (programmatically). I've found that I've had to modify both the Media and Crop box for some, but only the Media box for others. If I modify the crop box on the 'some', it seems to move the entire page up and off into oblivion leaving a large white area at the bottom.

                   The reason I've done this is because I'm adding a "Footer" to the page. The "Footer" is necessary for proper pagination of the documents I'm working with. The built in footer routine in Adobe Pro is not sufficient for this task as it adds unnecessary borders around the entire document. This causes the pages to become unreadable, especially for scanned documents. The program that I wrote only adds just enough space to the bottom of the page to be able to insert a button with the document name and page numbers. The other issue is readability of the text in that button, which must change (bigger for large formats and smaller for small ones) and is all the same size when you use the footer/ header method built into Adobe Pro.

               

              //SET UP INITIAL VALUES

              var pdf_start_page = 1;
              var pdf_end_page = 1;
              var start_sequence = 1;
              var count_by = 1;
              var total_pages = 1;
              var curpage = 1;
              var lgpagesz = 50;
              var regpagesz = 30;
              var resizepgs = 1;

              function getInput() {
                  //ASK THE USER WHAT PAGE NUMBER TO START ON
                  var sequence = app.response({
                      cQuestion: "What is the sequence? IE. [PDF_START_PAGE],[PDF_END_PAGE],[START_SEQUENCE],[COUNT_BY],[TOTAL_PAGES],[RESIZE-1=YES|2=NO](,lgpagesz,regpagesz)",
                      cTitle: "Starting Page Number",
                      cDefault: "1," + this.numPages + ",4,1,55,1",
                      cLabel: "Start Page Number:"
                  });

                 
                  //FIND OUT IF THE SEQUENCE RESPONSE FROM THE USER CONTAINS A COMMA AND SET UP VALUES
                  if(sequence.indexOf(",") > 0){
                      var vals = sequence.split(",");
                     
                      if(vals.length > 5){
                          pdf_start_page = Number(vals[0]);           
                          pdf_end_page = Number(vals[1]);           
                          start_sequence = Number(vals[2]);           
                          count_by = Number(vals[3]);           
                          total_pages = Number(vals[4]);

                          resizepgs = Number(vals[5]);
                         
                              if(vals.length > 6){
                                  lgpagesz = vals[5];
                              }

                              if(vals.length > 7){
                                  regpagesz = vals[6];
                              }
                      }
                      else{
                          return "";
                      }
                  }else{
                      return "";

                  }
                  return sequence;
              }

              //SIMPLE ALERT WRAPPER
              function alert(title, message){   
                  app.alert({
                      cMsg: message,
                      cTitle: title
                  });
              }

              //GET USER INPUT. MAKE SURE THEY INPUT SOMETHING

              while(getInput() == ""){
                  //FORCE A LOOP UNTIL THE USER INPUTS THE APPROPRIATE SEQUENCE
                  alert("Try Again", "You must input the values in the proper sequence; [PDF_START_PAGE],[PDF_END_PAGE],[START_SEQUENCE],[COUNT_BY],[TOTAL_PAGES],[RESIZE-1=YES|2=NO](,lgpagesz,regpagesz)");
              }

              //THIS IS THE PACKAGE BEING PAGINATED
              var changeDoc = app.response({

                  cQuestion: "What Change Document? IE. ABC-1234, ABC-1234, ABCD-12345, etc.",
                  cTitle: "Change Document",
                  cDefault: "ABC-",
                  cLabel: "Change Document Number:"
              });

              //ENSURE THE USER INSERTS A DOCUMENT NUMBER. THIS IS WHAT IS APPENDED TO THE BOTTOM OF EACH PAGE. "ABC-1234 PG_______OF_______"
              while(changeDoc == ""){
                  alert("You must enter a value", "Change Document value is empty.");
                  changeDoc = app.response({
                      cQuestion: "What Change Document? IE. ABC-1234, ABC-1234, ABC-12345, etc.",
                      cTitle: "Change Document",
                      cDefault: "ABC-",
                      cLabel: "Change Document Number:"
                  });
              }

              //THIS SECTION SETS UP EACH PAGE, ADDING ADDITIONAL SPACE AT THE END OF EACH PAGE OF THE DOCUMENT

              //CHECK TO SEE IF THE USER WANTS TO RESIZE THE PAGE (SOMETIMES THE PAGES HAVE ALREADY HAD A BOTTOM PIECE ADDED.
              if(resizepgs == 1){

                  //MOVE TO THE FIRST PAGE
                  this.pageNum = 0;

                  //LOOP THROUGH ALL OF THE PAGES IN THE DOCUMENT
                  for(var i = 0; i < this.numPages; i++){   

                      //GET THE CURRENT PAGES PAGEBOX
                      var bbox = this.getPageBox({nPage:i});

                     
                      //IF THE PAGE IS LARGE THEN ADD A LITTLE MORE SPACE TO THE BOTTOM THAN OTHERS

                      if(bbox[2] > 3000){
                          bbox[3] = bbox[3] - lgpagesz;
                      }else{
                          bbox[3] = bbox[3] - regpagesz;
                      }
                     

                      //THIS IS WHERE THE PIECE AT THE BOTTOM OF EACH PAGE IS ADDED AND WHERE THE PROBLEM CAN OCCUR
                      setPageBoxes("Media",this.pageNum, this.pageNum,bbox);
                     

                      //ADDED THIS LITTLE BIT BECAUSE THE PAGES THAT CAUSE THE PROBLEM USSUALLY HAVE SOMETHING IN THE RANGE OF 0 - 40 IN THIS FIELD

                      //AS DETERMINED BY INSPECTING THE PAGE BOXES WHEN THIS PROBLEM OCCURS
                      if(this.getPageBox("BBox",i)[3] < 45){
                          setPageBoxes("Crop",this.pageNum,this.pageNum,bbox);
                      }
                      this.pageNum++;
                  }
                  //END SET UP SECTION
              }

              //THIS SECTION INSERTS THE BUTTON WITH THE AAA/BBB/CCCC NUMBER AND PAGES FOR EACH PAGE WITHIN THE ADDED PORTION FROM ABOVE
              this.pageNum = 0;
              for(var i = pdf_start_page - 1; pdf_end_page; i++){
                  //GET THE SIZE OF THE PAGE FROM THE PAGE BOX VARIABLE
                  var bbox = this.getPageBox({nPage:i});
                 
                  //SET UP THE NORMAL DIMENSIONS OF THE BUTTON
                  var buttonwidth = 500;
                  var buttonheight = 20;
                  var llx = (bbox[2]/2) - (buttonwidth/2)
                  var lly = 10;
                  var urx = llx + buttonwidth;
                  var ury = lly + buttonheight;
                  if(urx > (bbox[2] - llx)){
                      urx = (bbox[2] - llx);
                  }
                 
                  //CHECK PAGE SIZE. IF IT'S LARGER THAN 3000px THEN THE TEXT NEEDS TO BE BIGGER SO INCREASE THE SIZE OF THE FIELD.

                  //WOULD LIKE TO ADD A CALCULATION HERE THAT MAKES THE TEXT SAY 12 POINT FONT EQUIVELANT
                  if(bbox[2] > 2000){
                      buttonwidth = 1000;
                      buttonheight = 50;
                      llx = (bbox[2]/2) - (buttonwidth/2)
                      lly = 5;
                      urx = llx + buttonwidth;
                      ury = lly + buttonheight;
                  }
                 
                  //CREATE THE NEW BUTTON ON THE PAGE

                  //THIS WAS ORIGINALLY INTENDED TO PUT ACTUAL NUMBERS ON THE PAGE BUT WAS RETROFITTED TO ONLY PLACE "Page _______ OF _______"
                  var f = this.addField("Page_" + start_sequence, "button", i, [llx,lly,urx,ury]);       

                  //SET UP THE DEFAULT PROPERTIES OF THE BUTTON
                  f.borderStyle = border.s;
                  f.highlight = "push";
                  f.textSize = 0;//AUTOMATIC
                  f.textColor = color.black;
                  f.fillColor = color.white;
                  f.textFont = font.Helv

                  f.buttonSetCaption(changeDoc + "    Page _______  OF  _______")
                  start_sequence += count_by;
                 
                  if(i == pdf_end_page - 1){
                      break;
                  }
                  this.pageNum++;
              }
              //END ADD BUTTON SECTION OF CODE

              For the most part this works quit well, but hiccups when there is a page that seems to be in rotated user space. Maybe I'm wrong and it's something else, but thus far I haven't been able to determine if it isn't because I can't find a way to see if the page is in fact in rotated or default user space. The pages that had the problem where all 8.5 x 11 and in portrait orientation in the document.

               

              Any help is appreciated.

               

              Thanks!

              • 4. Re: How does one determine if a page is in Default User Space or Rotated User Space?
                jasonh8531847 Level 1

                I will definitely be looking at the document you've pointed me to. Please see my reply to George_Johnson below.

                 

                Thanks!

                 

                Do you have a direct link to this document by chance?

                • 5. Re: How does one determine if a page is in Default User Space or Rotated User Space?
                  try67 MVP & Adobe Community Professional

                  The PDF ISO Reference can be found here: http://www.adobe.com/devnet/pdf/pdf_reference.html

                   

                  Just a small comment regarding your other reply: There's no connection between what you see and the page rotation. A page may appear to be "right side up" and actually be rotated, or it may appear "sideways" and not be rotated, or the other way around. This can happen, for example, if a page was scanned sideways and then rotated so that it would appear "correctly".

                  • 6. Re: How does one determine if a page is in Default User Space or Rotated User Space?
                    jasonh8531847 Level 1

                    Yeah, I understood that. That is what led me to try and find a way to determine the rotated/default user space of the page. I was just mentioning that the 'looked' like they where portrait in the file. the getPageRotation method returned 0 for these pages as well. When I wasn't able to find a way to determine the rotated/default user space of the page I posted here.

                    • 7. Re: How does one determine if a page is in Default User Space or Rotated User Space?
                      Test Screen Name Most Valuable Participant

                      The point is that if a page was (for example) scanned sideways, it would look upright to every kind of measure or property you could use in Acrobat. Acrobat simply wouldn't know and nor could you. Sometimes the human brain can instantly detect something a computer didn't know at all.

                       

                      An application could do fuzzy logic analysis of the page contents, but that's rather advanced and beyond JavaScript.

                      • 8. Re: How does one determine if a page is in Default User Space or Rotated User Space?
                        jasonh8531847 Level 1

                        I'm assuming you're referring to say an 8.5 x 11 page being scanned in, if I were to look at it after scanning, would be landscape and I'd have to turn my head 90 degrees to read it. Adobe would think that this was a 'normal' document and as such, if asked for the width of the page would return with 72 * 11 or 792 points. Additionally if given the coordinates (in default user space) of say 0, 396, 46, 0 to place a dot, the dot would end up at the bottom of said page at about the middle (assuming the page hadn't been rotated 90 degrees so I wouldn't have to turn my head at such an awkward angle), however; if I had rotated the page presumably changing the rotated user space from the default user space, the same variables (0, 396, 46, 0 in default user space) might appear on the left or right hand side of the page somewhere down the page in the middle. I understand that Acrobat might not know the difference between an unrotated, sideways scanned page and an unrotated, upright scanned page, but I would like to be able to determine when the default user space is different from the rotated user space so that I can determine the coordinate placement of say a button so that it ends up 'appearing' at the bottom, middle part of the 'viewable' page.

                        • 9. Re: How does one determine if a page is in Default User Space or Rotated User Space?
                          George_Johnson MVP & Adobe Community Professional

                          You can do an analysis of the text contents of each page in an attempt to determine the page's orientation as a human would consider it. If it's a scan, you can first do OCR. You can then use a script to scan through all of the words on a page and get the quad of each, and probably accurately determine the orientation based on those quads. This might involve some simple statistics, but it wouldn't be too complicated.

                           

                          BTW, you shouldn't think of a page being in default or rotated user space, because it's not. A page has a rotation (0, 90, 180, 270 degrees) and coordinates of things (text, graphics, images, annotations) on a page can be specified in either default or rotated user space. Some JavaScript methods are designed to work when the coordinates are specified in one space or the other, and there's always a way to convert from one to the other.