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

TOPIC:

Example how to render all PDF pages to images 4 years 10 months ago #14360

  • ville
  • ville's Avatar Topic Author
  • Offline
  • New Member
  • New Member
  • Posts: 5
  • Thank you received: 1
Hi!

I need to export all pdf pages to jpeg images at the resolution of 1080x1920. How can this be done with this library? (Looking for code examples.)

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

Last edit: by ville.

Example how to render all PDF pages to images 4 years 10 months ago #14362

  • radaee
  • radaee's Avatar
  • Offline
  • Moderator
  • Moderator
  • Posts: 1123
  • Thank you received: 73
the codes like:
Global.Init(this);
Document doc = new Document();
doc.Open("pdf path");
int pcnt = doc.GetPageCount();
int pcur = 0;
while(pcur < pcnt)
{
  float pw = doc.GetPageWidth(pcur);
  float ph = doc.GetPageHeight(pcur);
  int bw = (int)(pw * scale);
  int bh = (int)(ph * scale);
  Bitmap bmp = Bitmap.Create(bw, bh, RGBA8888);
  bmp.erase(white);
  Matrix mat = new Matrix(scale, -scale, 0, bh);
  Page page = doc.GetPage(pcur);
  page.RenderToBmp(mat, bmp);
  page.Close();
  bmp.Compress(...);
  pcur++;
}
doc.Close();

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

Last edit: by radaee.

Example how to render all PDF pages to images 4 years 10 months ago #14364

  • ville
  • ville's Avatar Topic Author
  • Offline
  • New Member
  • New Member
  • Posts: 5
  • Thank you received: 1
It seems that there are unfortunately multiple PDFs that aren't opening with this library. I've attached one as an example here:
Attachments:

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

Example how to render all PDF pages to images 4 years 10 months ago #14365

  • support
  • support's Avatar
  • Offline
  • Administrator
  • Administrator
  • Posts: 690
  • Thank you received: 59
The attached file was just rendered with current demo project:


May you provide the result you're receiving and what you're expecting?
Attachments:

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

Example how to render all PDF pages to images 4 years 10 months ago #14366

  • ville
  • ville's Avatar Topic Author
  • Offline
  • New Member
  • New Member
  • Posts: 5
  • Thank you received: 1
Now that I'm debugging it it seems that for string
content://com.android.externalstorage.documents/document/151B-4307%3ADownload%2FElisa_90292596604.pdf
the resulting document contains 0 pages.

So it seems that the
document.Open(uri.toString())
is not working as expected. How should it be loaded?

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

Example how to render all PDF pages to images 4 years 10 months ago #14367

  • radaee
  • radaee's Avatar
  • Offline
  • Moderator
  • Moderator
  • Posts: 1123
  • Thank you received: 73
them example on this topic is openging local File from absolute path.
for url you need PDFHTTPStream.
Global.Init(this);
PDFHTTPStream stream = new PDFHTTPStream("http://you addr/your pdf");
Document doc = new Document();
doc.OpenStream(stream);
int pcnt = doc.GetPageCount();
int pcur = 0;
while(pcur < pcnt)
{
  float pw = doc.GetPageWidth(pcur);
  float ph = doc.GetPageHeight(pcur);
  int bw = (int)(pw * scale);
  int bh = (int)(ph * scale);
  Bitmap bmp = Bitmap.Create(bw, bh, RGBA8888);
  bmp.erase(white);
  Matrix mat = new Matrix(scale, -scale, 0, bh);
  Page page = doc.GetPage(pcur);
  page.RenderToBmp(mat, bmp);
  page.Close();
  bmp.Compress(...);
  pcur++;
}
doc.Close();
stream.Close();
the webserver shall support "ByteRange" header for http request, and you need Internet Permission declared in AndroidMenifest.xml.

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

  • Page:
  • 1
Powered by Kunena Forum