PDFsharp - 更改页面大小和缩放内容

PDFsharp - Change page size and scale content

是否可以缩放页面,例如A2 到 A1 与 PDFsharp? 我可以通过大小、宽度和高度来设置页面的大小。但是如何缩放页面内容?

您可以使用 DrawImage() 在新的 PDF 页面上绘制现有的 PDF 页面。您可以指定目标矩形,从而可以根据需要缩放页面。

使用 XPdfForm class 访问现有的 PDF 文件。

详见一例两页:
http://www.pdfsharp.net/wiki/TwoPagesOnOne-sample.ashx

根据 Vive 的评论和那里提供的 link,这里有一个使用 C# 调整为 A4 大小的示例:

您必须包括:

    using PdfSharp.Pdf;
    using PdfSharp.Drawing;
    using PdfSharp;

然后:

    // resize this  file from A3 to A4
    string filename = @"C:\temp\A3.pdf";

    // Create the new output document (A4)
    PdfDocument outputDocument = new PdfDocument();
    outputDocument.PageLayout = PdfPageLayout.SinglePage;

    XGraphics gfx;
    XRect box;
    // Open the file to resize
    XPdfForm form = XPdfForm.FromFile(filename);

    // Add a new page to the output document
    PdfPage page = outputDocument.AddPage();

    if (form.PixelWidth > form.PixelHeight)
         page.Orientation = PageOrientation.Landscape;
    else
         page.Orientation = PageOrientation.Portrait;

     double width = page.Width;
     double height = page.Height;

     gfx = XGraphics.FromPdfPage(page);
     box = new XRect(0, 0, width, height);
     gfx.DrawImage(form, box);

     // Save the document...
     string newfilename = @"c:\temp\resized.pdf";
     outputDocument.Save(newfilename);