Skip to content

Image show as black box starting with version 3.0.3 #1524

@seime

Description

@seime

Describe the bug

Png image (signature) stamped on PDF becomes black box. Worked well in 3.0.0, tested in 3.0.2 but broken in 3.0.3.

To Reproduce

Code to reproduce the issue

// Load image
URL resource = getClass().getResource(imageResource);
image = Image.getInstance(resource);
image.scaleToFit(80, 80);
...
// Open the existing PDF
PdfReader reader = new PdfReader(pdfTemplateStream);

// Create stamper for writing
ByteArrayOutputStream baos = new ByteArrayOutputStream();
PdfStamper stamper = new PdfStamper(reader, baos);

// Choose the page to modify (page numbers start at 1)
int pageNumber = 1;

// Get PdfContentByte for adding new content *above* existing
PdfContentByte canvas = stamper.getOverContent(pageNumber);

// Select a font
BaseFont font = BaseFont.createFont(BaseFont.HELVETICA, BaseFont.CP1252, BaseFont.EMBEDDED);

...
// Add to canvas
// content is just a simple wrapper for image + position
image.setAbsolutePosition(content.getX(), content.getY());
canvas.addImage(image);

Expected behavior

The image displays properly and not as a black box

Screenshots

Image

Actual :

Image

Input files

PDF to be stamped

Image to stamp:
Image

System

  • OS: Linux and MacOS
  • OpenPDF version: 3.0.3

Your real name

Arne Seime

Additional information

I see #1499 was merged between 3.0.2 and 3.0.3. It could be totally unrelated. While there could be a problem with either the image or the PDF I'm using, it used to work but not anymore.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions