Black box for certain images when doing PDF to Image conversion

I’m using the following code, in Java:

        Page firstPdfPage = pdfDocument.getPages().get_Item(1);
        PageInfo pdfPageInfo = firstPdfPage.getPageInfo();
        Dimension pdfDimension = new Dimension((int) pdfPageInfo.getWidth(), (int) pdfPageInfo.getHeight());
        Dimension boundaryDimension = new Dimension(MAX_WIDTH_HEIGHT, MAX_WIDTH_HEIGHT);
        Dimension scaledDimension = getScaledDimension(pdfDimension, boundaryDimension);

        Resolution resolution = new Resolution(72);
        JpegDevice jpegDevice = new JpegDevice(scaledDimension.width, scaledDimension.height, resolution, 80);

        jpegDevice.process(firstPdfPage, renditionOutputStream);

Using Aspose PDF 25.11, this generates a black box for certain images for certain PDFs, see attached example files.

input.pdf (24.4 KB)

output.jpeg (1.2 KB)

The code above produces a correct image using version 24.11. Later versions show the broken behavior, so the bug is most likely introduced somewhere around that time.

Maybe this helps: this seems to happen for images in PDF’s that have been generated using

more specifically, a textbox with an image that has been added using

<<image [image_expression] -fitWidth>>

@edorasware

It looks like the problem is a regression introduced after version 24.11 – the same PDF that renders correctly with 24.11 is rendered as a black box when processed with 25.11 (and later).

What to do next

  1. Create a minimal reproducible sample

    • Use the PDF you attached (or a copy of it).
    • Run the exact code you posted with the following additional checks:
      System.out.println("Aspose.PDF version: " + com.aspose.pdf.Version.getVersion());
      System.out.println("Page size: " + pdfPageInfo.getWidth() + " x " + pdfPageInfo.getHeight());
      System.out.println("Scaled size: " + scaledDimension.width + " x " + scaledDimension.height);
      
    • Capture any console output and the generated JPEG file.
  2. Try an alternative image device

    • Replace JpegDevice with PngDevice (or BmpDevice) using the same dimensions and resolution.
    • If the PNG is also black, the issue is not JPEG‑specific.
  3. Check the PDF content

    • Open the PDF in a viewer and verify that the image is inside a form‑XObject/text‑box (the Word “textbox with an image” scenario).
    • Note whether the image uses a mask, transparency, or an unsupported color space.
  4. Collect environment details

    • Java version (e.g., 1.8, 11, 17).
    • OS (Windows/Linux/macOS) and its version.
    • Whether you are running the code in a container, IDE, or as a service.
  5. Submit a support request

    • Attach the original PDF, the black JPEG (and PNG if you tried), the console log, and the environment details.
    • Mention that the same PDF works with 24.11 but fails with 25.11 and later, and reference the forum thread “Black box for certain images when doing PDF to Image conversion”.

The Aspose PDF team can reproduce the regression with the files you provide and will be able to issue a fix or a workaround in an upcoming release.

  1. See the original post, 25.11.
    Page size/scaled size have no impact.

  2. Tried PNGDevice, also using different resolutions and quality, same result.

  3. It works for 24.11, so this is a regression, not a weird PDF format.

  4. Java 21.0.6, running it in a Spring boot application as a jar or war.

@edorasware

We have opened the following new ticket(s) in our internal issue tracking system and will deliver their fixes according to the terms mentioned in Free Support Policies.

Issue ID(s): PDFJAVA-45688

You can obtain Paid Support Services if you need support on a priority basis, along with the direct access to our Paid Support management team.