Free Support Forum - aspose.com

How to set PNG image background transparent when export worksheet to PDF in Java?

I am having problems with converting Excel to PDF using Aspose Cells for JAVA.
The Excel contain PNG-Images with transparent background.
But within the created pdf document the images have a white background.
I could reproduce this issue with the latest Version 20.10 of Aspose Cells for JAVA.
Could you please check it?
Thanks in advance.
Moment.

@xiaoman,

Please note, when you set worksheet’s background image and render / Save as to PDF (either by using MS Excel or by Aspose.Cells API), the background image is not rendered at all, this is Ms Excel limitation. The worksheet’s background image is only visible remaining in MS Excel without using Print Preview.

In short, if you are using some text oriented image as worksheet’s background, then you should use word art instead, see the document for your reference.

If you have set image in the header/footer or in the sheet normally and image is not rendered in the output PDF via Aspose.Cells for Java API, kindly do zip the Excel file and attach it here, we will check it soon.

I am not talking about worksheet’s background image.
I mean, when the worksheet contain PNG-Images with transparent background, after exported as PDF, the PNG-Images have a white background instead of a transparent background.

@xiaoman,

Please zip and attach the template Excel file and output PDF file, we will check it soon.

By the way, did you try using our latest version/fix: Aspose.Cells for Java v21.5.x?

Archive.zip (51.1 KB)
I try to use Aspose.Cells for Java v21.5, but not fixed.
implementation group: ‘com.aspose’, name: ‘aspose-cells’, version: ‘21.5’

    com.aspose.cells.Workbook wb = new com.aspose.cells.Workbook("files/test.xlsx");
    PdfSaveOptions opts = new PdfSaveOptions();
    opts.setCompliance(PdfCompliance.PDF_A_1_A);
    opts.setOutputBlankPageWhenNothingToPrint(false);
    opts.setAllColumnsInOnePagePerSheet(true);
    opts.setCalculateFormula(true);
    wb.save("files/test.pdf", opts);

@xiaoman

Transparent is not allowed in PdfCompliance.PDF_A_1_A , please remove the line:

opts.setCompliance(PdfCompliance.PDF_A_1_A);

Thanks, Peyton.
It fixed when I remove this option.

@xiaoman,
Good to know that your issue is sorted out by the suggested option. Feel free to contact us any time if you need further help or have some other issue or queries, we will be happy to assist you soon.