Merge 2 PDFs in Java -
i have problem itext , merging of 2pdfs 1 pdf.
i merge pdfs:
pdf1 - 1 site:
this pdf1.
pdf2 - 1 site:
this pdf2.
what need: https://dl.dropboxusercontent.com/u/4001370/whatineed.pdf
code 1 - 2 sites:
one site one: pdf1.
1 site two: pdf2.
pdfmergerutility ut = new pdfmergerutility(); ut.addsource("c:\\temp\\pdf1.pdf"); ut.addsource("c:\\temp\\pdf2.pdf"); ut.setdestinationfilename("c:\\temp\\code1.pdf"); ut.mergedocuments();
code 2 - number overwritten:
this pdf(1/2).
public class main { public static void main(string[] args) throws ioexception, documentexception { pdfreader reader; pdfimportedpage page; linkedlist<file> filelist = new linkedlist<file>(); filelist.add(new file("c:\\temp\\pdf1.pdf")); filelist.add(new file("c:\\temp\\pdf2.pdf")); file ergebnis = new file("c:\\temp\\code2.pdf"); document document2 = new document(pagesize.a4); pdfwriter writer = pdfwriter.getinstance(document2, new fileoutputstream(ergebnis)); document2.open(); pdfcontentbyte canvas = writer.getdirectcontent(); // header reader = new pdfreader(filelist.get(0).getabsolutepath()); page = writer.getimportedpage(reader, 1); canvas.addtemplate(page, 0, 0); // aufgabe reader = new pdfreader(filelist.get(1).getabsolutepath()); for(int i=1; i<=reader.getnumberofpages(); i++){ page = writer.getimportedpage(reader, i); canvas.addtemplate(page, 0, 0); document2.newpage(); } document2.close(); writer.close(); }
}
i have no idea. hope can me @ problem.
please read chapter 6 of book. explains why using pdfwriter
/pdfimportedpage
wrong way merge documents. should use pdfcopy
or pdfsmartcopy
if want concatenate 2 documents. should use pdfstamper
if want 1 document act company stationery other document. question, it's not clear 1 of both need (you leave open interpretation), please read chapter 6. i've done effort of writing , making available free can choose solution right you.
Comments
Post a Comment