You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@pdfbox.apache.org by Jarek Stempien <ja...@insys.be> on 2015/11/05 10:05:09 UTC
PDF to BMP problem
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 cropbBox is very small.
Regards
Jarek