How do I make PDFViewCtrl render the media box and not the Crop box

Q:

I am using PDFNet with IOS. Everything works fine and especially the performance is much better than PSPDF Kit we used before.

But one feature doesn’t work. It’s regarding the MediaBox and CropBox setting for PDF.

MediaBox and CropBox are different for some files from our customers. We are asked to render PDF with MediaBox. But PDFNet is using Cropbox by default.

I tried some changes for PDFDoc or Page as following, but it still shows as cropbox.

`

Page * tempPage = [docToOpen GetPage:[pdfViewCtrl GetCurrentPage]];

PDFRect* rect = [tempPage GetMediaBox];

[tempPage SetCropBox:[tempPage GetMediaBox]];

[[docToOpen GetViewPrefs] SetViewArea:e_media];

[[docToOpen GetViewPrefs] SetViewClip:e_media];

[[docToOpen GetViewPrefs] SetPrintArea:e_media];

[[docToOpen GetViewPrefs] SetPrintClip:e_media];

`

A:

Below is a quote from the PDF Specification regarding setting Viewer preferences in the PDF file itself (emphasis mine)…

This entry is intended primarily for use by prepress applications that interpret or manipulate the page boundaries as described in 14.11.2, “Page Boundaries.”
NOTE 2 Most conforming readers disregard it.

PDFNet is in the majority of conforming readers, and ignores this setting. One of the reasons if the user of the viewer should have control over the viewing experience (magnification, page layout, etc) and not the particular document loaded.

That being said, the real issue seems to be…

MediaBox and CropBox are different for some files from our customers. We are asked to render PDF with MediaBox. But PDFNet is using Cropbox by default.

All PDF viewers should be showing the crop box only, as this is what is meant to be visible to the person reading the PDF, this is not something particular to PDFNet, but in the PDF spec itself.

If you want to force PDFViewCtrl to use the media box, you need to modify the PDF itself, and update the viewer (note you might want to keep the old entry, if you support saving so as not to overwrite the original crop box.

`
Page page = view->GetDoc()->GetPage(view->GetCurrentPage());
// first check if there is a crop box defined
Obj pageObj = page.GetSDFObj();
Obj obj = obj.FindObj(“CropBox”);
if(obj != null)
{
// yes, backup old. When user saves you would want to restore this value
Rect cropBox = page.GetCropBox();
pageObj.PutRect(“CropBox_Backup”, cropBox.x1, cropBox.y1, cropBox.x2, cropBox.y2)
}
// now set crop box to media box, and refresh viewer
page.SetCropBox(page.GetMediaBox());
view->UpdatePageLayout();

`