PDFsharp & MigraDoc Foundation

PDFsharp - A .NET library for processing PDF & MigraDoc Foundation - Creating documents on the fly
It is currently Sat Apr 27, 2024 6:56 am

All times are UTC


Forum rules


Please read this before posting on this forum: Forum Rules



Post new topic Reply to topic  [ 3 posts ] 
Author Message
PostPosted: Mon Jul 27, 2009 4:26 pm 
Offline

Joined: Mon Jul 27, 2009 1:42 pm
Posts: 2
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?


Top
 Profile  
Reply with quote  
PostPosted: Mon Jul 27, 2009 4:41 pm 
Offline
PDFsharp Guru
User avatar

Joined: Mon Oct 16, 2006 8:16 am
Posts: 3096
Location: Cologne, Germany
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).

_________________
Regards
Thomas Hoevel
PDFsharp Team


Top
 Profile  
Reply with quote  
PostPosted: Mon Jul 27, 2009 4:48 pm 
Offline

Joined: Mon Jul 27, 2009 1:42 pm
Posts: 2
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.


Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 3 posts ] 

All times are UTC


Who is online

Users browsing this forum: Google [Bot] and 418 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Privacy Policy, Data Protection Declaration, Impressum
Powered by phpBB® Forum Software © phpBB Group