pdfbox-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Jarek Stempien <ja...@insys.be>
Subject PDF to BMP problem
Date Thu, 05 Nov 2015 15:31:47 GMT
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
Mime
View raw message