Is it possible with itextpdf
to merge two pdf files like this
pdf-file-1
: 1 page with 3 lines of textpdf-file-2
: 1 page with 9 lines of text
results :
pdf-file-3
: 1 page with 12 lines text, merging results of pdf-file-1
and pdf-file-2
Is it possible with itextpdf
to merge two pdf files like this
pdf-file-1
: 1 page with 3 lines of text
pdf-file-2
: 1 page with 9 lines of text
results :
pdf-file-3
: 1 page with 12 lines text, merging results of pdf-file-1
and pdf-file-2
Is it possible with itextpdf to merge two pdf files like this...
As Bruno explained in his comment, PDFs in general hardly know anything about the text they display, they don't know about chapters, sections, paragraphs, columns, etc. They don't even necessarily know about lines of text; what we perceive as a line may be a loose collection of small chunks of text drawn at some abstract coordinates.
Thus, your question as is may not even make sense seen from the inside of the PDFs in question.
If you re-formulate it, though, some similar question does make sense, e.g.
Is it possible with iTextPdf to merge two pdf files like this
pdf-file-1: 1 page with content which only fills a small part of the page, e.g. only the top half
pdf-file-2: 1 page also with content which only fills a small part of the page, e.g. only the top half
results :
pdf-file-3: 1 page with the content of pdf-file-1 at the top and that of pdf-file-2 right below it, merging results of pdf-file-1 and pdf-file-2
This indeed is possible, especially it is possible using iText. While this functionality is not an explicit feature of iText, iText does offer a low-level API which fairly easily allows to implement such merging features, e.g.:
PdfDenseMergeTool
presented in this answer does exactly what is described above, it puts the contents of as many source pages on a target page as fit there; andPdfVeryDenseMergeTool
presented in this answer does even more, it even splits source page contents to squeeze even more onto the target pages.Beware, though, those classes are not hardened by years of use and improvement, they are proofs of concept for which certain corner cases will still have to considered.
In particular they only consider actual page content, not annotations or similar active content. On the other hand they even consider white rectangles drawn onto the empty page as content. PDFs in which each page initially is filled with white are considered completely full in spite of what actually is visible