Skip to main content
Participating Frequently
March 22, 2012
Answered

Bleed from the inserted pdf

  • March 22, 2012
  • 2 replies
  • 1702 views

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

This topic has been closed for replies.
Correct answer Jongware

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 replies

AlexeyNikAuthor
Participating Frequently
March 25, 2012

Thanks Muppet Mark.

Jongware
Community Expert
JongwareCommunity ExpertCorrect answer
Community Expert
March 22, 2012

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.

Inspiring
March 24, 2012

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…

Inspiring
March 26, 2012

@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


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