PDFsharp & MigraDoc Foundation

PDFsharp - A .NET library for processing PDF & MigraDoc Foundation - Creating documents on the fly
It is currently Tue Jul 09, 2024 8:16 am

All times are UTC


Forum rules


Please read this before posting on this forum: Forum Rules



Post new topic Reply to topic  [ 6 posts ] 
Author Message
 Post subject: Shrink PDF Document
PostPosted: Mon Jun 06, 2011 10:05 pm 
Offline

Joined: Mon Jun 06, 2011 9:57 pm
Posts: 9
I'm new to using PDFSharp and manipulating PDF documents so please correct any of my vocabulary if needed.

I'm taking in a PDF document. I then add one line of text to the top of the document 7 pixels from the top. Sometimes on the pdf there could be information already up in this top portion so what I need to do is shrink the existing information on the PDF just a little so there is space at the top when I write my one line of text.

Here is my sample text for just placing the image in the top right corner basically one of the samples already.

Dim sharpDoc As PdfDocument = PdfReader.Open(fileName)
For i = 0 To sharpDoc.Pages.Count - 1

sharpDoc.Pages(i).Size = PdfSharp.PageSize.A4
Dim graphics = XGraphics.FromPdfPage(sharpDoc.Pages(i))

Dim xfont As New XFont("Times New Roman", 8)
graphics.DrawString(String.Format("ProcessID: {0} Received: {1}", process.Id, Now.Date.ToString("yyyy-MM-dd")), xfont, XBrushes.Black, CInt(sharpDoc.Pages(i).Width) - 220, 10, XStringFormats.Default)
Next

I need some information on how to scale the original information on the PDF I'm working with to make sure that the line of text I put at the top doesn't cover anything up.

Thanks for the help.


Top
 Profile  
Reply with quote  
 Post subject: Re: Shrink PDF Document
PostPosted: Tue Jun 07, 2011 7:21 am 
Offline
PDFsharp Guru
User avatar

Joined: Mon Oct 16, 2006 8:16 am
Posts: 3101
Location: Cologne, Germany
Check this sample:
http://www.pdfsharp.net/wiki/TwoPagesOnOne-sample.ashx

_________________
Regards
Thomas Hoevel
PDFsharp Team


Top
 Profile  
Reply with quote  
 Post subject: Re: Shrink PDF Document
PostPosted: Mon Jun 13, 2011 8:59 pm 
Offline

Joined: Mon Jun 06, 2011 9:57 pm
Posts: 9
So I think what I can tell from the sample is that you take the page and then create a new Xrect that is half the width of the original pdf?

Then your using it as an image to draw onto the new page?

One thing I forgot to mention is that these documents are text searchable documents and I need to retain that functionality in the future as well.

If I'm reading the example right that will not occur? Is there any way to do it?


Top
 Profile  
Reply with quote  
 Post subject: Re: Shrink PDF Document
PostPosted: Tue Jun 14, 2011 7:34 am 
Offline
PDFsharp Guru
User avatar

Joined: Mon Oct 16, 2006 8:16 am
Posts: 3101
Location: Cologne, Germany
The PDF files are imported as PDF and the search function of Adobe Reader still works.

You can scale the page to any size you want. The sample draws pages at half there size to get two pages on one.

_________________
Regards
Thomas Hoevel
PDFsharp Team


Top
 Profile  
Reply with quote  
 Post subject: Re: Shrink PDF Document
PostPosted: Tue Jun 14, 2011 3:20 pm 
Offline

Joined: Mon Jun 06, 2011 9:57 pm
Posts: 9
Ok. I took pieces of that example and was able to scale the page to where I needed it. The problem I'm having is that I could have multple pages in one pdf file and currently it just keeps writing the same page everytime.

So if I have 5 different pages it just writes page 1 five times.

How do I move to the next page in the pdf file to scale and add my text? I'm not seeing what line of code that would be in the example.


Top
 Profile  
Reply with quote  
 Post subject: Re: Shrink PDF Document
PostPosted: Tue Jun 14, 2011 3:59 pm 
Offline

Joined: Mon Jun 06, 2011 9:57 pm
Posts: 9
After further review of the code I found this line:
// Set page number (which is one-based)
form.PageNumber = idx + 1;

Which did the trick. I thought that was just setting a page number for the new page and we don't use page numbers. Now I realize that was incrementing the forms pages.


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

All times are UTC


Who is online

Users browsing this forum: No registered users and 42 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