Yuv*_*gar 19 pdf pdfsharp c#-4.0
环境 - PDFsharp Library,Visual Studio 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");
Run Code Online (Sandbox Code Playgroud)
我在这里上传了文件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");
Run Code Online (Sandbox Code Playgroud)
Je *_*not 12
请创建新文档并将旧文档中的页面复制到新文档,而不是修改文档.
示例代码可以在PDFsharp论坛上找到:http://forum.pdfsharp.net/viewtopic.php?p = 2637#p2637
| 归档时间: |
|
| 查看次数: |
30266 次 |
| 最近记录: |