0

I'm trying to concatenate two different PDF files in a java project.

I've read in others posts that the best way is to use Itext class "PdfCopy", but the strange thing is that there isn't in my project even though I have the 7.0.6 of Itext in the pom and a commercial license.

Is there an explanation or another way to solve this task without using Itext or others external libraries? Thank you

user2298581
  • 532
  • 3
  • 11
  • 37
  • Please show us your code. – Amedee Van Gasse May 26 '19 at 19:20
  • 2
    *I've read in others posts that the best way is to use Itext class "PdfCopy"* - that recommendation refers to itext up to version 5.x. itext 7.x is a major re-design of the whole api. In particular the functionality of the `PdfCopy` classes had been moved. Try `PdfDocument.copyPagesTo` instead. – mkl May 27 '19 at 04:39

2 Answers2

1

I've read in others posts that the best way is to use Itext class "PdfCopy"

That recommendation refers to iText up to version 5.x. iText 7.x is a major re-design of the whole iText api. In particular the functionality of the Pdf*Copy* classes had been moved. Try PdfDocument.copyPagesTo instead.

I.e. if you have loaded your source documents into PdfDocument instances doc1 and doc2 and have another, writable PdfDocument instance dest you want to copy those source documents into, simply do:

doc1.copyPagesTo(1, doc1.getNumberOfPages(), dest);
doc2.copyPagesTo(1, doc2.getNumberOfPages(), dest);
mkl
  • 90,588
  • 15
  • 125
  • 265
0

Please refer this as well:

Is it possible to merger several pdfs using iText7

Another library that can be used is PDFBox, sample below"

https://www.tutorialkart.com/pdfbox/pdfbox-merge-multiple-pdfs/

TechFree
  • 2,600
  • 1
  • 17
  • 18