Why bother with the cropbox? Here's some simple code, just replace "png"
with "bmp":
https://stackoverflow.com/questions/23326562/apache-pdfbox-convert-pdf-to-images
If that doesn't help, please upload your pdf file somewhere.
Tilman
Am 05.11.2015 um 16:31 schrieb Jarek Stempien:
Hi,
I'm trying to convert PDF to BMP and I've problem with quality. Can
you help me? Is there something wrong with code?
PDDocument document= *null*;
*try*
{
document= PDDocument./load/( *new*java.io.File(pdfFile) );
}
*catch*(Exception e)
{
e./printStackTrace/();
*return**false*;
}
writeImage(document, "bmp", 1, Integer.*/MAX_VALU/*,
ImageType.*/RGB/*, 96, outputFiles, 800);
*public**boolean*writeImage(PDDocument document, String imageFormat,
*int*startPage, *int*endPage,
ImageType imageType, *int*dpi, List<OutputStream>
outputFiles, *int*maxWidth) *throws*IOException
{
*boolean*bSuccess= *true*;
endPage= Math./min/(endPage, document.getNumberOfPages());
PDFRenderer renderer= *new*PDFRenderer(document);
*for*(*int*i= startPage- 1, j=0; i< endPage; i++,j++)
{
PDPage page= document.getPage(i);
PDRectangle cropbBox= page.getCropBox();
*float*widthPt= cropbBox.getWidth();
*float*scale= 1f;
*if*(maxWidth!= -1)
{
scale= (*float*)maxWidth/widthPt;
}
BufferedImage image= renderer.renderImage(i, scale, imageType);
*if*(j+ 1 > outputFiles.size())
{
outputFiles.add(*new*ByteArrayOutputStream());
}
bSuccess&= ImageIOUtil./writeImage/(image, imageFormat,
outputFiles.get(j), dpi);
}
*return*bSuccess;
}
I see also that PDRectangle cropbBoxis very small.
Regards
Jarek
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]