【问题标题】:PDFsharp - Change page size and scale contentPDFsharp - 更改页面大小和缩放内容
【发布时间】:2017-11-27 14:48:11
【问题描述】:

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

【问题讨论】:

    标签: scale pdfsharp


    【解决方案1】:

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

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

    详情请参阅两页合一示例:
    http://www.pdfsharp.net/wiki/TwoPagesOnOne-sample.ashx

    【讨论】:

      【解决方案2】:

      根据 Vive 的评论和那里提供的链接,这里有一个使用 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);
      

      【讨论】:

        猜你喜欢
        • 2013-02-08
        • 1970-01-01
        • 2011-09-26
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2012-09-19
        • 2013-02-06
        • 2022-10-24
        相关资源
        最近更新 更多