1

I need to convert the iTextPDF image instance to bitmap in order to set that bitmap to imageView in android.(Not android Image instance to bitmap.) Please checkout the question twice.

    Image instance = Image.getInstance(page);
    // Here i need to convert image instance to bitmap object inorder to set it to imageView
    imageView.setImageBitmap(??);

Convert PDF to image using iTextPDF: and set that image to imageView

public void readAndViewPDF(String fileUri) {

    String INPUTFILE = "c:/temp/FirstPdf.pdf";
    String OUTPUTFILE = "c:/temp/ReadPdf.pdf";

    Document document = new Document();

    PdfWriter writer = null;
    try {
        writer = PdfWriter.getInstance(document,
                new FileOutputStream(OUTPUTFILE));
        document.open();
        PdfReader reader = new PdfReader(fileUri);
        int n = reader.getNumberOfPages();
        PdfImportedPage page;
        // Go through all pages
        for (int i = 1; i <= n; i++) {
            // Only page number 2 will be included
            if (i == 2) {
                page = writer.getImportedPage(reader, i);
                Image instance = Image.getInstance(page);
                imageView.setImageBitmap(instance);
                // Here i need to convert image instance to bitmap object inorder to set it to imageView. here you can show image on your phone
                imageView.setImageBitmap(??);

            }
        }
    } catch (DocumentException e) {
        e.printStackTrace();
    } catch (FileNotFoundException e) {
        e.printStackTrace();
    } catch (IOException e) {
        e.printStackTrace();
    } finally {
        document.close();
    }

}
jazzbpn
  • 6,441
  • 16
  • 63
  • 99
  • I am Sorry, it's not. Actually I want to convert Image of iTextPDF library to bitmap. So please read question once. please!! – jazzbpn Feb 04 '18 at 02:35
  • iText doesn't produce bitmaps. It only produces PDF. The `Image` object is used to add Form or Image XObjects to a new or existing PDF. If an existing page of a PDF document is stored inside an `Image` object, it will be treated as a Form XObject (vector data); it won't be converted to a raster image. – Bruno Lowagie Feb 04 '18 at 09:45

0 Answers0