PDFsharp & MigraDoc Foundation
http://forum.pdfsharp.de/

Cut Contents in a Rectangle and Post to New Document
http://forum.pdfsharp.de/viewtopic.php?f=2&t=809
Page 1 of 1

Author:  c_nickers [ Mon Jul 27, 2009 4:26 pm ]
Post subject:  Cut Contents in a Rectangle and Post to New Document

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?

Author:  Thomas Hoevel [ Mon Jul 27, 2009 4:41 pm ]
Post subject:  Re: Cut Contents in a Rectangle and Post to New Document

CropBox is a feature of Adobe Reader indicating which area to show.
Invisible items are not removed (could be cut marks or other information needed for printing/processing).

Author:  c_nickers [ Mon Jul 27, 2009 4:48 pm ]
Post subject:  Re: Cut Contents in a Rectangle and Post to New Document

Thank you for your reply and clarifying this for me.

Is it possible to add a line break at a specific point in the document? I think doing this would give me the same output of having just my header information on a seperate page.

Page 1 of 1 All times are UTC
Powered by phpBB® Forum Software © phpBB Group
https://www.phpbb.com/