【发布时间】:2017-11-27 14:48:11
【问题描述】:
是否可以从例如缩放页面? A2 到 A1 与 PDFsharp? 我可以通过大小、宽度和高度来设置页面的大小。但是如何缩放页面的内容呢?
【问题讨论】:
是否可以从例如缩放页面? A2 到 A1 与 PDFsharp? 我可以通过大小、宽度和高度来设置页面的大小。但是如何缩放页面的内容呢?
【问题讨论】:
您可以使用DrawImage() 在新的 PDF 页面上绘制现有的 PDF 页面。您可以指定目标矩形,从而可以根据需要缩放页面。
使用 XPdfForm 类访问现有的 PDF 文件。
详情请参阅两页合一示例:
http://www.pdfsharp.net/wiki/TwoPagesOnOne-sample.ashx
【讨论】:
根据 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);
【讨论】: