Is it possible to merger several pdfs using iText7

后端 未结 3 2148
忘掉有多难
忘掉有多难 2020-12-06 18:50

I have several datasheets for products. Each is a separate file. What I want to do is to use iText to generate a summary / recommended set of actions, based on answers to a

3条回答
  •  被撕碎了的回忆
    2020-12-06 19:24

    The question doesn't specify the language, so I'm adding an answer using C#; this works for me. I'm creating three separate but related PDFs then combining them into one.

    After creating the three separate PDF docs and adding data to them, I combine them this way:

    PdfDocument pdfCombined = new PdfDocument(new PdfWriter(destCombined));
    PdfMerger merger = new PdfMerger(pdfCombined);
    
    PdfDocument pdfReaderExecSumm = new PdfDocument(new PdfReader(destExecSumm));
    merger.Merge(pdfReaderExecSumm, 1, pdfReaderExecSumm.GetNumberOfPages());
    
    PdfDocument pdfReaderPhrases = new PdfDocument(new PdfReader(destPhrases));
    merger.Merge(pdfReaderPhrases, 1, pdfReaderPhrases.GetNumberOfPages());
    
    PdfDocument pdfReaderUncommonWords = new PdfDocument(new PdfReader(destUncommonWords));
    merger.Merge(pdfReaderUncommonWords, 1, pdfReaderUncommonWords.GetNumberOfPages());
    
    pdfCombined.Close();
    

    So the combined PDF is a PDFWriter type of PdfDocument, and the merged pieces parts are PdfReader types of PdfDocuments, and the PdfMerger is the glue that binds it all together.

提交回复
热议问题