【发布时间】:2014-12-07 21:57:13
【问题描述】:
我有两个 Adobe 生命周期设计的表格“F1_0.pdf”和“F1_1.pdf”。两个表单都有一些表单数据。
我正在使用以下代码(itextsharp v5.1.2)合并它们。它以很好的方式将它们合并到生成的文件“Merged_Final.pdf”中。我的问题是:Merged_Final.pdf 文件只有第二个 pdf 的数据,即 F1_1.pdf。 F1_0.pdf 文件的数据不见了。 这是pdf file attachment. 那么,我该如何摆脱这个问题。
public void CombineMultiplePDFs(string[] fileNames, string outFile)
{
// step 1: creation of a document-object
Document document = new Document();
// step 2: we create a writer that listens to the document
PdfCopy writer = new PdfCopy(document, new FileStream(outFile, FileMode.Create));
if (writer == null)
{
return;
}
// step 3: we open the document
document.Open();
foreach (string fileName in fileNames)
{
// we create a reader for a certain document
PdfReader reader = new PdfReader(fileName);
reader.ConsolidateNamedDestinations();
// step 4: we add content
for (int i = 1; i <= reader.NumberOfPages; i++)
{
PdfImportedPage page = writer.GetImportedPage(reader, i);
writer.AddPage(page);
}
PRAcroForm form = reader.AcroForm;
if (form != null)
{
writer.CopyAcroForm(reader);
}
reader.Close();
}
// step 5: we close the document and writer
writer.Close();
document.Close();
}
【问题讨论】:
标签: pdf pdf-generation itextsharp itext