合并PDF文件

jkj*_*kjl 4 pdf itext

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

Rob*_*ert 10

花了我很长时间来弄清楚这一点,但这是一个有效的例子:

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
        }
    }
Run Code Online (Sandbox Code Playgroud)

希望这可以帮助!

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