PdfBox-Android
PdfBox-Android copied to clipboard
PDFRenderer fails with some graphics in pdf.
Describe the bug A clear and concise description of what the bug is. Some graphics are displayed as black rectangles with some white pixels
To reproduce Code snippet to reproduce the behavior:
String workDir="/storage/emulated/0/Android/data/com.MyApp/files"; //this is getExternalFilesDir(null)
String inputFile="/storage/emulated/0/Android/data/com.MyApp/files/fr_sample_statements_and_charts.pdf";
File inF=new File(inputFile);
com.tom_roush.pdfbox.pdmodel.PDDocument pdf = com.tom_roush.pdfbox.pdmodel.PDDocument.load(inF);
for (int i = 0; i < pdf.getNumberOfPages(); i++)
{
com.tom_roush.pdfbox.rendering.PDFRenderer renderer = new com.tom_roush.pdfbox.rendering.PDFRenderer(pdf);
Bitmap pagBmp = renderer.renderImage(i , 1, com.tom_roush.pdfbox.rendering.ImageType.RGB); //this sometimes does not render properly
try (FileOutputStream out = new FileOutputStream(workDir + "/" + i + ".png"))
{
pagBmp.compress(Bitmap.CompressFormat.PNG, 100, out);
}
}
pdf.close();
PDF example https://cs.thomsonreuters.com/ua/acct_pr/csa/cs_us_en/pdfs/fr_sample_statements_and_charts.pdf
Expected behavior Graphics inside pdf should be always rendered properly.
Actual behavior
File / page 0.png contains an empty / white image (should be company logo)
Files / pages 132.png-141.png have black rectangles with some gray bars where there should be a graphic. Examples:
Files / pages 46.png-48.png have correct graphics (pie, bars, lines charts). Example:
Environment details:
- PdfBox-Android version: 2.0.17.0
- Android API version: minSdkVersion="23" targetSdkVersion="30"
- Problem occurred in Sony Xperia XA2 Android 9.
Additional context -Still need to test in other platforms.
I am also facing a similar issue where images in pdf are showing up weirdly. With PdfBox-Android version: 2.0.19.0
With PdfBox-Android version: 2.0.0.0
minSdk 21 targetSdk 32 On Android 12 Emulator
akashkumarstudio: I think the problem is related to JPEG 2000 filter which is not implemented in this version (and also in original Apache PDFBox). What I am doing is using android native PDFRender for drawing the pages (which anyway is faster than PDFBox render), and PDFBox-Android for text layer, which however still has some problems, since often text is not properly placed on the rendered pages. I hope this can help.