0

I am new to android can you please show me example to convert a Pdf file pages into bitmaps in android.

So, that i can display as imageview in android

feroz
  • 1
  • 1

2 Answers2

2

I tried many PDF libraries, the fastest is Mobi PDF Viewer SDK. Do this:

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

I used this libary to did that

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

The instuctions are there, and is easy to implement.

Ayoze Pérez
  • 28
  • 1
  • 5
  • Welcome to StackOverflow. It is considered good practice to summarize the contents of links. I know you can't very well post the source code to the library, but the steps you followed to get the library working would be a nice addition. – Patrick M Jul 08 '14 at 17:51