We're sorry Aspose doesn't work properply without JavaScript enabled.

Free Support Forum - aspose.com

Rendering of pages as jpeg is very slow on Android. Is there any way to improve the performance?

I have implemented the trial version in my Android app. So far it works great, but for rendering pages to jpeg format it is very slow, like 10 to 15 seconds per page. Is this normal for your library? Are there any performance adjustments I can make to speed things up? Any help is appreciated. Thanks!


Hi Tom,


Thanks for using our API’s.

The time taken by API to perform conversion depends upon the structure and complexity of input file. Can you please share the resource PDF file so that we can test the scenario at our end.

The PDF files I need to make are of various sized images captured from the camera, with one image per page and the page size matches the size of the image.

So far, the creation of the PDF works great. But I also need to provide a way for users to preview the file. So I am processing each page as a jpeg to a byte stream, then decoding that into an Android Bitmap for display.

I discovered that our page adapter was actually processing the first 3 pages at once during the initial load, and that is why it was taking 15 seconds. So, I have modified my page loader to load each page sequentially, and now it takes about 5 or 6 seconds per page.

This is better than before, but still, 6 seconds to wait for each page is a long time. I would like to get that down to under 3 seconds at most, and hopefully a lot lower.

I am including some code snippets just to make sure I am doing this correctly.


Any help or advice you can offer is much appreciated. Thanks!


public void LoadPageFromPDF(String pdfFilePath, int pageNumber, Point displaySize, ImageView imageView) {

Document pdfDocument = new Document(pdfFilePath);

com.aspose.pdf.devices.Resolution resolution = new com.aspose.pdf.devices.Resolution(72);

com.aspose.pdf.devices.JpegDevice jpegDevice = new com.aspose.pdf.devices.JpegDevice(resolution, 100);

Page page = pdfDocument.getPages().get_Item(pageNumber);

ByteArrayOutputStream byteStream = new ByteArrayOutputStream(1024);

jpegDevice.process(page, byteStream); // big time lag here, 6 seconds per page


try {

// We need to do a little extra down-sampling here since we are loading multiple images for full-screen display

Bitmap bmp = decodeSampledBitmapFromByteArray(byteStream.toByteArray(), displaySize.x / 2, displaySize.y / 2);

imageView.setImageBitmap(bmp);

byteStream.close();

} catch (IOException e) {

e.printStackTrace();

}

}


In an attempt to get more speed out of your library for previewing pages on Android, I discovered that if I get the images from the page resources and save them to a stream, it is significantly faster than processing a page as a jpeg. My PDF files have 1 image per page, and each page size matches the image size.

// This takes about 5 or 6 seconds
Resolution resolution = new Resolution(72);
JpegDevice jpegDevice = new JpegDevice(resolution, 100);
jpegDevice.process(page, byteStream);

versus

// This takes about 2 seconds
XImage xmg = page.getResources().getImages().get_Item(1);
xmg.save(mByteStream);


Can you explain the performance difference here? I would prefer to use the JpegDevice since it works for more complex PDF files, but I can’t make the users wait 6 seconds for each page. The Adobe Reader app for Android is much faster with the same PDF files.

Hi,


Thanks for sharing the feedback. We are testing this scenario in our environment and will keep you posted with our findings.