0

How to merge two pdf files with layers using itextsharp in C#, I tried but losing layers // 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(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 Answers0