如何在C#中使用itextsharp合并两个pdf文件而不丢失图层?

时间:2018-04-19 05:50:24

标签: itext

如何在C#中使用itextsharp将两个pdf文件与图层合并,我尝试了但是丢失了图层  //步骤1:创建文档对象             文件文件=新文件();

        // step 2: we create a writer that listens to the document
        PdfCopy writer = new PdfCopy(document, new FileStream(outPutFilePath, FileMode.Create));
        if(writer == null)
        {
            return;
        }

        // step 3: we open the document
        document.Open();

        foreach(string fileName in filesPath)
        {
            // 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);
                page.ContentTagged = true;

                writer.AddPage(page);
            }

            PRAcroForm form = reader.AcroForm;
            if(form != null)
            {
                // writer.CopyDocumentFields(reader);
            }

            reader.Close();
        }

        // step 5: we close the document and writer
        writer.Close();
        document.Close();

0 个答案:

没有答案