【问题标题】:How to convert Pdf pages into Bitmaps in android?如何在 android 中将 Pdf 页面转换为位图?
【发布时间】:2012-05-28 08:15:19
【问题描述】:

我是 android 新手,你能告诉我在 android 中将 Pdf 文件页面转换为位图的示例吗?

所以,我可以在 android 中显示为 imageview

【问题讨论】:

  • 你实际上想做什么?在上面注明。发布你的代码
  • 我只想在我的应用程序中显示 pdf。所以我想将pdf页面转换为图像来显示..

标签: android


【解决方案1】:

我试过很多PDF库,最快的是Mobi PDF Viewer SDK。 这样做:

public Bitmap getPiece(String path, String password, int importWidth, int importHeight, int piece_x, int piece_y, int piece_w, int piece_h)
    {
        Document myDoc = new PDFDocument (path); 
        myDoc. Open (path, password); 

        Bitmap result = Bitmap.createBitmap(piece_w, piece_h, Config.ARGB_8888);
        result.eraseColor(0xFFFFFFFF);

        Page page = m_doc.GetPage(pageNumber);

        float w = m_doc.GetPageWidth(pageNumber);
        ratio = importWidth/w;
        w = m_doc.GetPageWidth(pageNumber) * ratio;
        float h = m_doc.GetPageHeight(pageNumber) * ratio;

        Matrix mat = new Matrix(ratio, -ratio, -piece_x, h - piece_y);
        page.RenderToBmp(result, mat);

        page.Close();

        return result;
    }

【讨论】:

    【解决方案2】:

    我使用这个库来做到这一点

    https://github.com/jblough/Android-Pdf-Viewer-Library

    说明就在那里,而且很容易实施。

    【讨论】:

    • 欢迎来到 StackOverflow。总结链接的内容被认为是一种很好的做法。我知道您不能很好地将源代码发布到库中,但是您为使库正常工作所遵循的步骤将是一个不错的补充。
    猜你喜欢
    • 2012-02-07
    • 2012-05-28
    • 1970-01-01
    • 2021-12-12
    • 1970-01-01
    • 2016-11-13
    • 1970-01-01
    • 2013-01-01
    • 2015-09-18
    相关资源
    最近更新 更多