0

I have followed this other topic to get a image from pdf

How to convert a pdf to an image?

I want to use this image as a pdf preview, this is de code that I have

private Bitmap showPage(int page, float zoom) throws Exception {
    Bitmap b=null;
    try {

        mPdfPage = mPdfFile.getPage(page, true);
        float wi = mPdfPage.getWidth();
        float hei = mPdfPage.getHeight();


        RectF clip = null;

        Bitmap bi = mPdfPage.getImage((int)(wi*zoom), (int)(hei*zoom), clip, true, true);
        b=bi;

        ByteArrayOutputStream bytes = new ByteArrayOutputStream();
        b.compress(Bitmap.CompressFormat.JPEG, 90, bytes);
        File f = new File(Environment.getExternalStorageDirectory()+ File.separator + "Firstpdf.jpg");
        f.createNewFile();
        FileOutputStream fo = new FileOutputStream(f);
        fo.write(bytes.toByteArray());
        Log.e("amit","Go to page bitmap______SAVE");

    } catch (Throwable e) {

    }

    return b;
}

but in this line

Bitmap bi = mPdfPage.getImage((int)(wi*zoom), (int)(hei*zoom), clip, true, true);

I get this error

The method getImage(int, int, Rectangle2D, ImageObserver) in the type PDFPage is not applicable for the arguments (int, int, RectF, boolean, boolean)

Can anyone help me?

Thank you very much!

Community
  • 1
  • 1
aloj
  • 3,194
  • 7
  • 27
  • 38

1 Answers1

0

The method getImage requires 4 parameters but you have passed 5. Check the documentation and provide correct parameters.

Henry
  • 42,982
  • 7
  • 68
  • 84
  • In [this post](http://stackoverflow.com/questions/8814758/need-help-to-convert-a-pdf-page-into-bitmap-in-android-java) he use with 3 parameters, but I can't, i'm using PDFRenderer.jar, maybe it is incorrect library – aloj Sep 21 '13 at 12:08
  • In [this link](http://www.java2s.com/Open-Source/Android-Open-Source-App/Media/Android-Pdf-Viewer-Library/com/sun/pdfview/PDFPage.java.htm) there is a method impletation with 3 parameters and It returns a Bitmap (getImage(int width, int height, RectF clip)), but I can't acces, I only can to a method with 4 parameters and return a Image – aloj Sep 21 '13 at 12:27