Generate PDF with images on Android [closed]

0

I need to generate a PDF on Android with some simple fields and multiple images. Searching I found this question Error creating PDF file on Android who is helping me. But I do not know how I can add the images to the PDF, they are currently saved to the device and I have the path to them.

    
asked by anonymous 21.12.2015 / 13:24

1 answer

0

There is another library called PDFBox if you are not able to use iText.

link

  

With iText it is possible to merge, so even with   new images, could be added as it arises.

The necessary you already have, the path, if it is static, you can use directly or dynamically in case you need to choose.

link

Ex:

private void combinaImagensEmPdf(String caminhoImagens, String caminhoSaida) {
    try {
        Document document = new Document();
        PdfWriter.getInstance(document, new FileOutputStream("arquivo.pdf"));
        document.open();
        File files[] = new File(caminhoImagens).listFiles();
        PdfPTable table = new PdfPTable(1);
        for (File file : files) {
            table.setWidthPercentage(100); //Altera e configura
            table.addCell(criarCelulaDeImagem(file.getAbsolutePath()));
        }
        document.add(table);
        document.close();
    } catch (FileNotFoundException e) {
        e.printStackTrace();
    }
}

public static PdfPCell criarCelulaDeImagem(String caminhoImagens) {
    Image img = Image.getInstance(caminhoImagens);
    return new PdfPCell(img, true);
}

Ref: link

    
21.12.2015 / 14:53