PDFsharp & MigraDoc Foundation

PDFsharp - A .NET library for processing PDF & MigraDoc Foundation - Creating documents on the fly
It is currently Mon Oct 26, 2020 1:55 pm

All times are UTC


Forum rules


Please read this before posting on this forum: Forum Rules



Post new topic Reply to topic  [ 7 posts ] 
Author Message
 Post subject: Increase page size
PostPosted: Mon Aug 03, 2020 3:36 pm 
Offline

Joined: Mon Aug 03, 2020 3:10 pm
Posts: 4
I want to increase the pages size of a pdf, but I can't figure out how. I was thinking It would be something like:
NewPDF = (OLDPDF.Page.Height+10, OLDPDF.Page.Width+10)'
Here is my code to create new pdf and edit it:
Code:
PdfDocument PDFDoc = PdfReader.Open(@"C:\Users\oldpdf.pdf", PdfDocumentOpenMode.Import);

            PdfDocument PDFNewDoc = new PdfDocument();
           
            string name = "name";
            for (int Pg = 0; Pg < PDFDoc.Pages.Count; Pg++)
            {
                //PDFDoc.Pages[Pg].Width = PDFDoc;
             PDFNewDoc.AddPage(PDFDoc.Pages[Pg]);
                XGraphics gfx = XGraphics.FromPdfPage(PDFNewDoc.Pages[Pg]);
                XFont font = new XFont("Arial", 10, XFontStyle.Regular);
               
                gfx.DrawString("HI", font, XBrushes.Black, new XRect(0, 0, PDFDoc.Pages[Pg].Width, PDFDoc.Pages[Pg].Height), XStringFormats.BottomCenter);
                gfx.DrawString("Hello", font, XBrushes.Black, new XRect(-2, -2, PDFDoc.Pages[Pg].Width, PDFDoc.Pages[Pg].Height), XStringFormats.BottomRight);
                gfx.Dispose();

            }
            PDFNewDoc.Save(@"C:\Users\Newpdf.pdf");

I want to set page size for the new pdf to be larger then the oldPDF.
Thank you.


Top
 Profile  
Reply with quote  
 Post subject: Re: Increase page size
PostPosted: Tue Aug 04, 2020 11:39 am 
Offline
PDFsharp Expert
User avatar

Joined: Sat Mar 14, 2015 10:15 am
Posts: 580
Location: CCAA
I think you can simply set the new page size.
The contents will keep their sizes, so the margins will grow on two sides.

Is that what you want?

_________________
Best regards
Thomas
(Freelance Software Developer with several years of MigraDoc/PDFsharp experience)


Top
 Profile  
Reply with quote  
 Post subject: Re: Increase page size
PostPosted: Tue Aug 04, 2020 12:48 pm 
Offline

Joined: Mon Aug 03, 2020 3:10 pm
Posts: 4
@TH-Soft, yes so the new PDF would have larger page(more empty space at the bottom). I am adding a text to the end of each page, some pages already have different text at the end of the page. In order to avoid overwriting it, I need to increase the page size. I don't know how to do that using PdfSharp this http://www.pdfsharp.net/wiki/PageSizes-sample.ashxdidn't help much.

I would think it would be something like:
PDFNewDoc.AddPage(PDFDoc.Pages[Pg].Width+10,PDFDoc.Pages[Pg].Height+10); but add page doesn't take 2 arguments.

Thank you.


Top
 Profile  
Reply with quote  
 Post subject: Re: Increase page size
PostPosted: Tue Aug 04, 2020 2:31 pm 
Offline
PDFsharp Expert
User avatar

Joined: Sat Mar 14, 2015 10:15 am
Posts: 580
Location: CCAA
Have you tried setting page.Width and page.Height respectively?

If that does not work start fiddling with MediaBox, CropBox, and such. Change the page size before obtaining an XGraphics object.

_________________
Best regards
Thomas
(Freelance Software Developer with several years of MigraDoc/PDFsharp experience)


Top
 Profile  
Reply with quote  
 Post subject: Re: Increase page size
PostPosted: Tue Aug 04, 2020 6:23 pm 
Offline

Joined: Mon Aug 03, 2020 3:10 pm
Posts: 4
I am sorry if you have code sample that would be great.


Top
 Profile  
Reply with quote  
 Post subject: Re: Increase page size
PostPosted: Tue Aug 04, 2020 9:34 pm 
Offline
PDFsharp Expert
User avatar

Joined: Sat Mar 14, 2015 10:15 am
Posts: 580
Location: CCAA
Here is a code sample:
Code:
var pdfPage = PDFNewDoc.AddPage(PDFDoc.Pages[Pg]);
pdfPage.Width = XUnit.FromInch(4);
pdfPage.Height = XUnit.FromInch(6);

_________________
Best regards
Thomas
(Freelance Software Developer with several years of MigraDoc/PDFsharp experience)


Top
 Profile  
Reply with quote  
 Post subject: Re: Increase page size
PostPosted: Wed Aug 05, 2020 1:32 pm 
Offline

Joined: Mon Aug 03, 2020 3:10 pm
Posts: 4
Hi, thank you for the help. This expands the page and the content, but my goal is to add white space at the end of the page and then write on that space.
Sorry for the confusion.


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

All times are UTC


Who is online

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