PDFsharp & MigraDoc Foundation
https://forum.pdfsharp.net/

Shrink PDF Document
https://forum.pdfsharp.net/viewtopic.php?f=2&t=1684
Page 1 of 1

Author:  vidamj [ Mon Jun 06, 2011 10:05 pm ]
Post subject:  Shrink PDF Document

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.

Author:  Thomas Hoevel [ Tue Jun 07, 2011 7:21 am ]
Post subject:  Re: Shrink PDF Document

Check this sample:
http://www.pdfsharp.net/wiki/TwoPagesOnOne-sample.ashx

Author:  vidamj [ Mon Jun 13, 2011 8:59 pm ]
Post subject:  Re: Shrink PDF Document

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?

Author:  Thomas Hoevel [ Tue Jun 14, 2011 7:34 am ]
Post subject:  Re: Shrink PDF Document

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.

Author:  vidamj [ Tue Jun 14, 2011 3:20 pm ]
Post subject:  Re: Shrink PDF Document

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.

Author:  vidamj [ Tue Jun 14, 2011 3:59 pm ]
Post subject:  Re: Shrink PDF Document

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.

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