【发布时间】:2020-08-07 15:27:05
【问题描述】:
我正在尝试用文本标记每个 PDF 页面的底部。问题是,我不希望新文本覆盖 PDF 页面的现有内容。我试图增加页面的大小,这会导致调整所有内容的大小,从而导致相同的问题。这是我的代码示例:
class Program
{
static void Main(string[] args)
{
PdfSharp.Pdf.PdfDocument PDFDoc = PdfSharp.Pdf.IO.PdfReader.Open(@"C:\Users\Desktop\name.pdf", PdfDocumentOpenMode.Import);
PdfSharp.Pdf.PdfDocument PDFNewDoc = new PdfSharp.Pdf.PdfDocument();
for (int Pg = 0; Pg < PDFDoc.Pages.Count; Pg++)
{
PdfSharp.Pdf.PdfPage pdfPage = PDFNewDoc.AddPage(PDFDoc.Pages[Pg]);
pdfPage.Height += 100;
// Add height at bottom of the page
XRect rect = new XRect(0, 0, pdfPage.Width, pdfPage.Height + 100);
pdfPage.MediaBox = new PdfSharp.Pdf.PdfRectangle(rect);
// pdfPage.Width = XUnit.FromInch(7.50);
//pdfPage.Height = XUnit.FromInch(12);
XGraphics gfx = XGraphics.FromPdfPage(PDFNewDoc.Pages[Pg]);
XFont font = new XFont("Arial", 10, XFontStyle.Regular);
//rect calls new size
gfx.DrawString("something", font, XBrushes.Black, rect, XStringFormats.BottomCenter);
}
PDFNewDoc.Save(@"C:\Users\Desktop\EditedPdf.pdf");
}
}
我对此主题进行了研究,但找不到有用的解决方案。谢谢 此外,一个建议是缩小 PDF 页面的内容,这将在页面的所有侧面提供空白。然后我可以在底部添加我的文本。这不是最佳解决方案,但总比没有解决方案好。不幸的是,我也不知道如何实现。任何帮助表示赞赏。
【问题讨论】: