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

Rei*_*Mat 5 scale pdfsharp

是否可以使用 PDFsharp 将页面从 A2 缩放到 A1?我可以通过“大小”、“宽度”和“高度”来设置页面的大小。但是如何缩放页面内容呢?

Ezr*_*zra 7

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

您必须包括:

    using PdfSharp.Pdf;
    using PdfSharp.Drawing;
    using PdfSharp;
Run Code Online (Sandbox Code Playgroud)

然后:

    // 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);
Run Code Online (Sandbox Code Playgroud)


Je *_*not 4

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

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

有关详细信息,请参阅一页上的两页示例:
http://www.pdfsharp.net/wiki/TwoPagesOnOne-sample.ashx