PNG to PDF Error using Java

Hi. I’m trying to convert a Base64 Byte Array into a PDF Document using Java.

However, I get the following Exception:

JavaException: com.aspose.words.internal.zzY6: Could not create the bitmap with the specified parameters. Possible lack of system resources.

Here is my code:

var bytes = getBytes();
          
var pdfDoc = new com.aspose.words.Document();
          
var documentBuilder = new com.aspose.words.DocumentBuilder(pdfDoc);
documentBuilder.insertImage(bytes);
          
var path = "C:\Temp\sample.pdf";
          
pdfDoc.save(path, com.aspose.words.SaveFormat.PDF);

I have attached the BMP image.BitmapImage.zip (17.0 KB)

Can someone please help!

@swy Could you please attach the problematic image here for testing? We will check the issue and provide you more information.

I have now attached as a Zip file (as BMP wasn’t allowed). Thank you.

@swy Thank you for additional information. I cannot reproduce the problem on my side using the latest 22.11 version of Aspose.Words for Java. The following code does not throw an exception and properly generated PDF document:

byte[] bytes  = Files.readAllBytes(Paths.get("C:\\Temp\\BitmapImage.bmp"));

Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);

builder.insertImage(bytes);

doc.save("C:\\Temp\\out.pdf");

Thanks for looking into this for me Alexey. I have downloaded the latest version of Aspose.words (aspose-words-22.11-jdk16.jar), but I still get the same problem. In fact, tif files no longer work with the latest version.

I have just tried again with a smaller file and it seems to work OK. I guess I need to increase the memory allocation. Thank you for you help.

1 Like