I'm trying to crop a PDF document using .net and PDFSharp. My documents are all 25" wide. I need to split each one into two pages of 12.5". Here is the code I have that appears to work:
foreach (var page in pdfDoc.Pages)
{
var h = page.Height.Point;
var w = page.Width.Point;
var leftRectangle = new PdfRectangle(new XPoint(0, 0), new XPoint(w / 2, h));
page.MediaBox = leftRectangle;
page.CropBox = leftRectangle;
page.ArtBox = leftRectangle;
page.BleedBox = leftRectangle;
page.TrimBox = leftRectangle;
targetDoc.AddPage(page);
var rightRectangle = new PdfRectangle(new XPoint(w / 2, 0), new XPoint(w, h));
page.MediaBox = rightRectangle;
page.CropBox = rightRectangle;
page.ArtBox = rightRectangle;
page.BleedBox = rightRectangle;
page.TrimBox = rightRectangle;
targetDoc.AddPage(page);
}
As you can see, I reached a point where I was trying to set every type of box. This is because when I uploaded the document to the printing service after having modified only the CropBox
, it was still registering every right page as 25". None of these boxes avoids the problem. I'm assuming at this point that the "bounding box" is not being modified, and thus it's not truly being cropped, just the display is being modified, which is why it looks correct when I open it in Foxit Reader.
Is there a way to truly crop a document this way?