环境- PDFsharp库,Visual 2012和C#作为语言。
我试图:
我可以做以下所有的事情。但是当我打开Test2.pdf文件时,页面的大小正在缩小到宽度= 11英寸,高度- 11英寸。这些PDF文件,我正在使用的产品规格表,我已经从互联网下载。我相信这种情况只发生在某些类型的文件上,我不知道如何区分这些文件。
代码如下:
//File dimentions - Width = 17 inches, Height - 11 inches (Tabloid Format)
PdfDocument pdfDocument = PdfReader.Open(@"D:\Test1.pdf", PdfDocumentOpenMode.Modify);
PdfPage page = pdfDocument.Pages[0];
XGraphics gfx = XGraphics.FromPdfPage(page);
XFont font = new XFont("Verdana", 20, XFontStyle.BoldItalic);
gfx.DrawString("Hello, World!", font, XBrushes.Black, new XRect(0, 0, page.Width, page.Height), XStringFormats.Center);
//When the file is saved dimentions change to - Width = 11 inches, Height - 11 inches
pdfDocument.Save(@"D:\Test2.pdf");我已经把文件上传到这里了Test1.pdf
==================================================================================
正如PDFsharp团队建议的那样,代码应该如下所示:
PdfDocument PDFDoc = PdfReader.Open(@"D:\Test1.pdf", PdfDocumentOpenMode.Import);
PdfDocument PDFNewDoc = new PdfDocument();
for (int Pg = 0; Pg < PDFDoc.Pages.Count; Pg++)
{
PdfPage pp = PDFNewDoc.AddPage(PDFDoc.Pages[Pg]);
XGraphics gfx = XGraphics.FromPdfPage(pp);
XFont font = new XFont("Arial", 10, XFontStyle.Regular);
gfx.DrawString("Hello, World!", font, XBrushes.Black, new XRect(0, 0, pp.Width, pp.Height), XStringFormats.BottomCenter);
}
PDFNewDoc.Save(@"D:\Test2.pdf");发布于 2013-07-15 07:59:28
不要修改文档,请创建一个新文档并将页面从旧文档复制到新文档。
示例代码可以在PDFsharp论坛上的这篇文章中找到:
http://forum.pdfsharp.net/viewtopic.php?p=2637#p2637
https://stackoverflow.com/questions/17647872
复制相似问题