java - Android : Merge PDFs file using iText API not working -
i trying merge pdf file using itext api merge 2 or more pdf documents one.but in result getting merge pdf 0 byte size.i post code shown below.i tried itext.jar file give same 0 size pdf.
and got :-"could not find class 'com.itextpdf.text.pdf.pdfprintergraphics2d', referenced method com.itextpdf.text.pdf.pdfcontentbyte.createprintergraphicsshapes". still not getting success.
code:
public class itextmerge { public static void main() { list<inputstream> list = new arraylist<inputstream>(); try { // source pdfs list.add(new fileinputstream(new file("mnt/sdcard/nocturia.pdf"))); list.add(new fileinputstream(new file("mnt/sdcard/professional android application development.pdf"))); // resulting pdf outputstream out = new fileoutputstream(new file("mnt/sdcard/newmerge.pdf")); domerge(list, out); } catch (filenotfoundexception e) { e.printstacktrace(); } catch (documentexception e) { e.printstacktrace(); } catch (ioexception e) { e.printstacktrace(); } } /** * merge multiple pdf 1 pdf * * @param list * of pdf input stream * @param outputstream * output file output stream * @throws documentexception * @throws ioexception */ public static void domerge(list<inputstream> list, outputstream outputstream) throws documentexception, ioexception { document document = new document(); pdfwriter writer = pdfwriter.getinstance(document, outputstream); document.open(); pdfcontentbyte cb = writer.getdirectcontent(); (inputstream in : list) { pdfreader reader = new pdfreader(in); (int = 1; <= reader.getnumberofpages(); i++) { document.newpage(); //import page source pdf pdfimportedpage page = writer.getimportedpage(reader, i); //add page destination pdf // cb.addtemplate(page, 0, 0); // cb.addtemplate(page, 0, 0); } } outputstream.flush(); document.close(); outputstream.close(); } }
any idea?
thank you
please use android port of itext:
http://repo.itextsupport.com//android_gae/com/itextpdf/itextgoogle/
you'll need trial license work itext on android; http://demo.itextsupport.com/newslicense/
Comments
Post a Comment