Skip to content

Image is broken if interpolate is set to false in generated pdf #358

@nikycube

Description

@nikycube

Hi @danfickle I'm trying to render a pdf which contains images more exactly some barcodes.
Initially I tried to render with interpolate set to true and I got blurry image. See (Picture_with_interpolate_true.pdf)
After I did some research I found your post in which you recommended to set interpolate to be false (image-rendering: pixelated;) I entered in debug mode and I saw that in PdfBoxSlowOutputDevice.class:712 PDImageXObject is set to true.
As result the image is broken. See (Picture_with_pixelated.pdf)
I have attached two pdfs with both cases.
I used version: '0.0.1-RC20' from 'openhtmltopdf-pdfbox'.
The image was created with code bellow :

	private static String generateInterleafed25Image(String barcodeNumber) throws IOException {
        BarcodeInter25 barcode = new BarcodeInter25();
        barcode.setCode(barcodeNumber);
        Image awtImage = barcode.createAwtImage(Color.BLACK, Color.WHITE);

        BufferedImage newImage = new BufferedImage(
            awtImage.getWidth(null), awtImage.getHeight(null),
            BufferedImage.TYPE_INT_ARGB);
        Graphics2D g = newImage.createGraphics();

        g.drawImage(awtImage, 0, 0, null);
        g.dispose();

        ByteArrayOutputStream baos = new ByteArrayOutputStream();
        ImageIO.write(newImage, "png", baos);
        baos.flush();

        byte[] imageInByte = baos.toByteArray();
        baos.close();
        return Base64.getEncoder().encodeToString(imageInByte);
    }

Thank you!

Picture_with_interpolate_true.pdf
Picture_with_pixelated.pdf

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions