Signin/Signup with: 
Welcome, Guest
Username: Password: Remember me
Questions about Android development and PDF
  • Page:
  • 1

TOPIC:

How to convert page to bitmap? 1 month 4 weeks ago #15861

  • Chunwen
  • Chunwen's Avatar Topic Author
  • Offline
  • New Member
  • New Member
  • Posts: 2
  • Thank you received: 0
I use below code to open a pdf file. How can I convert specific page to Bitmap? Can I convert in the background?
For example, I want to generate 5 bitmaps from page 3 to page 7. How can I do it?


private com.radaee.reader.PDFGLLayoutView m_view;
com.radaee.pdf.Document m_doc = new com.radaee.pdf.Document();
com.radaee.util.PDFFileStream stream = new com.radaee.util.PDFFileStream();


m_view = new com.radaee.reader.PDFGLLayoutView(m_Activity);

com.radaee.pdf.Global.Init(m_Activity);

stream.open(m_pdf_path);

int ret = m_doc.OpenStream(stream, null);

m_view.PDFOpen(m_doc, null, DefaultLayout.this);

m_view.PDFSetView(3);

Please Log in or Create an account to join the conversation.

How to convert page to bitmap? 1 month 4 weeks ago #15862

  • Chunwen
  • Chunwen's Avatar Topic Author
  • Offline
  • New Member
  • New Member
  • Posts: 2
  • Thank you received: 0
I solved by myself


for(int i = 0; i< totalPage; i++) {
int pageWidth = (int) m_doc.GetPageWidth(i);
int pageHeight = (int) m_doc.GetPageHeight(i);
Page page = m_doc.GetPage(i);

Bitmap bitmap = Bitmap.createBitmap(pageWidth, pageHeight, Bitmap.Config.ARGB_8888);

float m_ratio = 1;
com.radaee.pdf.Matrix mat = new com.radaee.pdf.Matrix(m_ratio, -m_ratio, 0, pageHeight * m_ratio);
page.RenderPrepare(bitmap);
page.RenderToBmp(bitmap, mat);
BMP bmp = new BMP();
bmp.Create(bitmap);
bmp.MulAlpha();//for transparent background.
bmp.Free(bitmap);
try {
FileOutputStream fout = new FileOutputStream("/sdcard/test"+i+".png");
bitmap.compress(Bitmap.CompressFormat.PNG, 0, fout);
fout.close();
} catch (Exception e) {
}

mat.Destroy();
page.Close();
}

Please Log in or Create an account to join the conversation.

Last edit: by Chunwen.

How to convert page to bitmap? 1 month 3 weeks ago #15863

  • support
  • support's Avatar
  • Offline
  • Administrator
  • Administrator
  • Posts: 692
  • Thank you received: 59
If you need more details take a look here www.radaeepdf.com/support/knowledge-base?view=kb&kbartid=98
 

Please Log in or Create an account to join the conversation.

  • Page:
  • 1
Powered by Kunena Forum