Note that there are some explanatory texts on larger screens.

plurals
  1. POAndroid : Merge PDFs file using iText API not working
    primarykey
    data
    text
    <p>I am trying to merge pdf file by using iText API to merge two or more PDF documents into one.But in result i am getting merge pdf with 0 byte size.I post my code as shown below.I tried with iText.jar file also but give same 0 size pdf.</p> <p>And got this :-"<strong><em>Could not find class 'com.itextpdf.text.pdf.PdfPrinterGraphics2D', referenced from method com.itextpdf.text.pdf.PdfContentByte.createPrinterGraphicsShapes</em></strong>". Still i am not getting any success.</p> <p><strong>Code:</strong></p> <pre><code>public class ItextMerge { public static void main() { List&lt;InputStream&gt; list = new ArrayList&lt;InputStream&gt;(); 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 into one pdf * * @param list * of pdf input stream * @param outputStream * output file output stream * @throws DocumentException * @throws IOException */ public static void doMerge(List&lt;InputStream&gt; list, OutputStream outputStream) throws DocumentException, IOException { Document document = new Document(); PdfWriter writer = PdfWriter.getInstance(document, outputStream); document.open(); PdfContentByte cb = writer.getDirectContent(); for (InputStream in : list) { PdfReader reader = new PdfReader(in); for (int i = 1; i &lt;= reader.getNumberOfPages(); i++) { document.newPage(); //import the page from source pdf PdfImportedPage page = writer.getImportedPage(reader, i); //add the page to the destination pdf // cb.addTemplate(page, 0, 0); // cb.addTemplate(page, 0, 0); } } outputStream.flush(); document.close(); outputStream.close(); } } </code></pre> <p>Any idea?</p> <p>Thank you</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload