gpt4 book ai didi

pdf - 合并 PDF 文件

转载 作者:行者123 更新时间:2023-12-04 20:27:06 25 4
gpt4 key购买 nike

是否可以使用 itextsharp 将可填充的 pdf 文件与 asp.net C# 中的常规 pdf 文件合并。任何帮助将不胜感激。

最佳答案

我花了很长时间才弄清楚这一点,但这里有一个工作示例:

public static void MergeFiles(string destinationFile, string[] sourceFiles)
{
try
{
int f = 0;
String outFile = destinationFile;
Document document = null;
PdfCopy writer = null;
while (f < sourceFiles.Length) {
// Create a reader for a certain document
PdfReader reader = new PdfReader(sourceFiles[f]);

// Retrieve the total number of pages
int n = reader.NumberOfPages;
//Trace.WriteLine("There are " + n + " pages in " + sourceFiles[f]);
if (f == 0)
{
// Step 1: Creation of a document-object
document = new Document(reader.GetPageSizeWithRotation(1));
// Step 2: Create a writer that listens to the document
writer = new PdfCopy(document, new FileStream(outFile, FileMode.Create));
// Step 3: Open the document
document.Open();
}
// Step 4: Add content
PdfImportedPage page;
for (int i = 0; i < n; )
{
++i;
page = writer.GetImportedPage(reader, i);
writer.AddPage(page);
}
PRAcroForm form = reader.AcroForm;
if (form != null)
writer.CopyAcroForm(reader);
f++;
}
// Step 5: Close the document
document.Close();
}
catch(Exception)
{
//handle exception
}
}

希望这可以帮助!

来源:
http://www.ujihara.jp/iTextdotNET/examples/concat_pdf.java

关于pdf - 合并 PDF 文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6196124/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com