What I want to accomplish is to take the contents of a PDF file, from point (0,0) to (page.Width, 2 inches), and move only that onto position (0,0) of a new Pdf document. I've attempted to accomplish this by croping the area I need and saving to a intermediate document. Then I am opening this document and drawing it onto a blank page. Here is the code I have.
Code:
string headerFooterLocation = @"C:\HeaderFooterLoc.pdf";
string filePath = @"C:\testblah.pdf";
PdfDocument headerDocument = PdfReader.Open(headerFooterLocation, PdfDocumentOpenMode.Import);
PdfPage headerPage = headerDocument.Pages[0];
headerPage.CropBox = new PdfRectangle(new PointF(0, (float)headerDocument.Pages[0].Height - (float)yBegin.Point), new SizeF((float)headerDocument.Pages[0].Width, (float)headerDocument.Pages[0].Height));
headerDocument.Save(filePath); // This document saved contains the correctly cropped stuff I want
PdfPage blankPage = new PdfPage(outputDocument);
XGraphics newGfx = XGraphics.FromPdfPage(blankPage, XGraphicsPdfPageOptions.Append);
XPdfForm drawForm = XPdfForm.FromFile(filePath);
newGfx.DrawImage(drawForm, 0, 0, drawForm.Width, yBegin.Point);
outputDocument.AddPage(blankPage);
string filename = output.Text;
outputDocument.Save(filename);
// ...and start a viewer.
Process.Start(filename);
The problem with this though is all of the original contents of the document saved at filePath still exists and not the cropped contents. I am misunderstanding how to use Crop? Is there also an easier way to accomplish this task?