6 Replies Latest reply: Mar 26, 2012 7:37 AM by absqua RSS

    Bleed from the inserted pdf

    AlexeyNik

      Hi.
      There
      Rectangle. It inserted into PDF. How do you know the size of the bleed from the inserted pdf?

        • 1. Re: Bleed from the inserted pdf
          [Jongware] MVP

          It seems you cannot know. The only property that sounds like it's useful is pdfAttributes, but that (a) is readonly, and (b) only tells you if Crop to Bleed was used when placing the file.

           

          You can't even be sure if you place the same PDF page twice, once with and once without bleed, because the bleed for left, right, top and bottom can have any value -- they don't have to be the same.

          • 2. Re: Bleed from the inserted pdf
            Muppet Mark Community Member

            Jong, here is a function I get some mileage from… Its not pretty… Im convinced the regex stuff could be better but while it work for me I ain't looked at it too much… Values are in points so you need other functions to do UnitValue or plain Math conversion… If the PDF is Illustrator then the boxes are NOT what you would expect… ( inside out back to front the usual AI hash ) So in some cases a creator check is needed… Getting the TBLR bleeds is simple enough…

             

             

            function getPDFboxes( f ) { // Feed it the PDF file…
            
                      var pdfBoxes = Object();
            
                      try {
            
                                f.open( 'r' );
            
                                var str = f.read();
            
                                var b = str.match( /BleedBox\[(\d+\.\d+\s){3}\d+\.\d+\]/g ); // All matches
            
                                if ( b != null ) pdfBoxes.BleedBox = b[0].match( /\d+\.\d+/g ); // Array from just the first match
            
                                var a = str.match( /ArtBox\[(\d+\.\d+\s){3}\d+\.\d+\]/g ); // Ditto the others
            
                                if ( a != null ) pdfBoxes.ArtBox = a[0].match( /\d+\.\d+/g );
            
                                var m = str.match( /MediaBox\[(\d+\.\d+\s){3}\d+\.\d+\]/g );
            
                                if ( m != null ) pdfBoxes.MediaBox = m[0].match( /\d+\.\d+/g );
            
                                var t = str.match( /TrimBox\[(\d+\.\d+\s){3}\d+\.\d+\]/g );
            
                                if ( t != null ) pdfBoxes.TrimBox = t[0].match( /\d+\.\d+/g );
            
                                var c = str.match( /CropBox\[(\d+\.\d+\s){3}\d+\.\d+\]/g );
            
                                if ( c != null ) pdfBoxes.CropBox = c[0].match( /\d+\.\d+/g );
            
                                f.close();
            
                      } catch( err ) {
            
                                f.close();
                      };
            
                      return pdfBoxes;
            
            };
            
            

             

            Oh I forgot but should add that I generally split PDF pages it makes them easier to work with… Multi-pages and multi-sized pages has just not been worth me trying to work out…

            • 3. Re: Bleed from the inserted pdf
              [Jongware] MVP

              I opened a PDF with TextWrangler and did a hopeful/naive search for text strings such as 'bleed', 'crop', etc. -- but you are right, every single page can have different settings! So to get the actual bleed/crop for *any* page, you have to parse the entire Pages array, which is a wonderful construction, as any set of "Pages" may include yet another complete set of "Pages", which in turn ... (etc.).

               

              Writing a PDF parsing library has been on my "might be worth trying" list for a while -- I can think of all sorts of interesting things one could do with it.

              • 4. Re: Bleed from the inserted pdf
                AlexeyNik Community Member

                Thanks Muppet Mark.

                • 5. Re: Bleed from the inserted pdf
                  Laubender MVP

                  @Jongware – A PDF could be "optimized". In Acrobat 9 Pro(?) and above the task to decifer the code will be near to impossible…

                   

                  You will not see any information in an "optimized" PDF like:

                  /CropBox[0.0 0.0 595.0 842.0]

                  /MediaBox[0.0 0.0 595.0 842.0]
                  /Rotate 0


                  Just tested with Acrobat 9 Pro. Created a new PDF from scratch (in Acrobat), choose "Save As / Adobe PDF files, optimized" as saving option.

                   

                  Uwe

                  • 6. Re: Bleed from the inserted pdf
                    absqua Community Member

                    If you can use an external tool, I think rather than writing my own pdf parsing library I would use one of the ones already out there and freely available. See for instance pdfinfo -box in the xpdf suite. (You can tell it which page to look at or run it once per page if you need to know the sizes for every page; it looks like it reports the page box dimensions of the first page by default.)

                     

                    Jeff