【发布时间】:2018-12-19 11:29:49
【问题描述】:
我有 3 个 PDF,我想将它们中的页面添加到输出 PDF 文件中。我要做的是:导入第一个 PDF -> 创建新的 PDF 文档 -> 添加页面 -> 在某个页面中绘制,最后我想将该文档中的页面添加到将要导出的主要 PDF 文档中。如果需要,继续对第二个 PDF 文件执行相同操作。
ERROR: A PDF document must be opened with PdfDocumentOpenMode.Import to import pages from it.
我从主类调用处理 PDF 的方法:
Pdftest pdftest = new Pdftest();
PdfDocument pdf = PdfReader.Open(@"C:\Users\pdf_file.pdf", PdfDocumentOpenMode.Import);
pdftest.CreatePages(pdf_file);
Pdftest 类:
public class Pdftest
{
PdfDocument PDFNewDoc = new PdfDocument();
XFont fontChico = new XFont("Verdana", 8, XFontStyle.Bold);
XFont fontGrande = new XFont("Verdana", 12, XFontStyle.Bold);
XBrush fontBrush = XBrushes.Black;
public void CreatePages(PdfDocument archivoPdf)
{
PdfDocument NuevoDoc = new PdfDocument();
for (int Pg = 0; Pg < archivoPdf.Pages.Count; Pg++)
{
PdfPage pp = NuevoDoc.AddPage(archivoPdf.Pages[Pg]);
}
XGraphics Graficador = XGraphics.FromPdfPage(NuevoDoc.Pages[0]);
XPoint coordinate = new XPoint();
coordinate.X = XUnit.FromInch(1.4);
coordinate.Y = XUnit.FromInch(1.8);
graficador.DrawString("TEST", fontChico, fontBrush, coordinates);
for (int Pg = 0; Pg < NuevoDoc.Pages.Count; Pg++)
{
PdfPage pp = PDFNewDoc.AddPage(NuevoDoc.Pages[Pg]); //Error mentioned.
}
}
}
【问题讨论】:
标签: c# pdf pdf-generation pdfsharp