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

Increase page size
https://forum.pdfsharp.net/viewtopic.php?f=2&t=4164
Page 1 of 1

Author:  newhopez [ Mon Aug 03, 2020 3:36 pm ]
Post subject:  Increase page size

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.

Author:  TH-Soft [ Tue Aug 04, 2020 11:39 am ]
Post subject:  Re: Increase page size

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?

Author:  newhopez [ Tue Aug 04, 2020 12:48 pm ]
Post subject:  Re: Increase page size

@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.

Author:  TH-Soft [ Tue Aug 04, 2020 2:31 pm ]
Post subject:  Re: Increase page size

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.

Author:  newhopez [ Tue Aug 04, 2020 6:23 pm ]
Post subject:  Re: Increase page size

I am sorry if you have code sample that would be great.

Author:  TH-Soft [ Tue Aug 04, 2020 9:34 pm ]
Post subject:  Re: Increase page size

Here is a code sample:
Code:
var pdfPage = PDFNewDoc.AddPage(PDFDoc.Pages[Pg]);
pdfPage.Width = XUnit.FromInch(4);
pdfPage.Height = XUnit.FromInch(6);

Author:  newhopez [ Wed Aug 05, 2020 1:32 pm ]
Post subject:  Re: Increase page size

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.

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