Why pdfpage.GetBox(e_trim) returns a different rectangle from the one that is specified in page dict

Q:

Is there a reason why pdfPage.GetBox() returns a different rectangle from the one that is present in PDF?

My PDF has a MediaBox with dimentions 43, 0, 778, 1728 (left, top, width, height) and Trim box with dimentions 0, 0, 864, 1728.

I can get the Trim box dimentions using iOS built-in pdf renderer, here is my code:

NSString* pdfPath = nsstr(TempFolder() + “/” + “571982.pdf”);

NSURL* pdfURL = [NSURL fileURLWithPath:pdfPath isDirectory:NO];

CGPDFDocumentRef pdfDoc = CGPDFDocumentCreateWithURL((CFURLRef)pdfURL);

CGPDFPageRef pdfPage = CGPDFDocumentGetPage(pdfDoc, 1);

const CGRect r = CGPDFPageGetBoxRect(pdfPage, kCGPDFTrimBox);

NSLog(@“Trim box = %.2f %.2f %.2f %.2f”, r.origin.x, r.origin.y, r.size.width, r.size.height);

The result is

Trim box = 0.00 0.00 864.00 1728.00

But when I’m trying to get the Trim box using your lib, I get apprantly wrong value 43, 0, 778, 1728 (the same as Media box). Here is my code:

using(IRandomAccessStream stream = await (await ApplicationData.Current.LocalFolder.GetFileAsync(“571982.pdf”)).OpenReadAsync()) {

using(PDFDoc pdfDoc = new PDFDoc(stream)) {

using(Page pdfPage = pdfDoc.GetPage(1)) {

pdftron.PDF.Rect r = pdfPage.GetBox(PageBox.e_trim);

Debug.WriteLine(“Trim box = {0} {1} {2} {3}”, r.x1, r.y1, r.Width(), r.Height());

}

}

}

The result is

Trim box = 43 0 778 1728

Why do I get a different value from page.GetBox()?

A:

According to PDF Spec: “The crop, bleed, trim, and art boxes should not ordinarily extend beyond the boundaries of the media box. If they do, they are effectively reduced to their intersection with the media box.”

Since there are many corrupt PDF files out there PDFNet normalizes page box to the expected value (i.e. intersection between media and trim box).

In case you would like to obtain the trim/bleed/art box in its original form you can use the following snippet:

Obj tb = page.FindInheritedAttribute ("TrimBox ");

If (tb != null) {

Rect trim(tr);

}