在Android中将pdf转换为图像

时间:2013-09-21 11:43:34

标签: android pdf

我已经按照其他主题从pdf

获取图像

How to convert a pdf to an image?

我想将此图像用作pdf预览,这是我的代码

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;
}

但在这一行

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

我收到此错误

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

任何人都可以帮助我吗?

非常感谢!

1 个答案:

答案 0 :(得分:0)

方法getImage需要4个参数,但已通过5.检查文档并提供正确的参数。