Error when using InputStream as parameter of new ImageStamp class

Hello. I am using Aspose.PDF Java 17.8
So, I want to place an ImageStamp over PDF document. The image is Base64 PNG.
This is my code so far:
//base64image = “data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAr0AAA…(snip)”
byte[] bytes = javax.xml.bind.DatatypeConverter.parseBase64Binary(base64Image.split(",")[1]);
InputStream is = org.apache.commons.io.IOUtils.toInputStream(new java.lang.String(bytes, “UTF-8”), java.nio.charset.StandardCharsets.UTF_8);
ImageStamp imgStamp = new ImageStamp(is);
But the app gives me error:
com.aspose.pdf.internal.ms.System.z9: Error loading file: Unsupported file format
Parameter name: input
I tried using java.util.Base64 and got same error
I appreciate the help from forum members.
Thank you.

@papin97

Thank you for contacting support.

Would you please try below approach for converting base64 image string to ByteArrayInputStream and then proceed accordingly. Please ensure using Aspose.PDF for Java 19.9 in your environment.

String source = "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAr0AAA…(snip)";
String base64ImageString = source.replace("data:image/png;base64,", "");
byte[] imageBytes = javax.xml.bind.DatatypeConverter.parseBase64Binary(base64ImageString);
ByteArrayInputStream inputStream = new ByteArrayInputStream(imageBytes);
com.aspose.pdf.ImageStamp imgStamp = new com.aspose.pdf.ImageStamp(inputStream);

We hope this will be helpful. Please feel free to contact us if you need any further assistance.

I tried it and it solves my problem! Thank you!.
I hope your solution gets added to Aspose Docs.

@papin97

Thank you for your kind feedback and suggestion. Please feel free to contact us if you need any further assistance.