Aspose inserthtml with embedded base64 image

Hi @asad.ali
I am facing the issue to convert large html to single image
testExample.zip (3.9 MB)

please see the attached code and html file

using

<dependency>
    <groupId>com.aspose</groupId>
    <artifactId>aspose-pdf</artifactId>
    <version>19.8</version>
</dependency>

<dependency>
    <groupId>com.aspose</groupId>
    <artifactId>aspose-words</artifactId>
    <version>19.12</version>
    <classifier>jdk17</classifier>
</dependency>

@jVivek

Can you please explain a bit more about what type of issue are you facing? Are you facing some exception or output image is not as per your expectations? Please try to use the latest version of the API and provide us the requested information if you still notice any issues with it.

Hello Asad,
I am facing another issue like i have HTML template and in that template i am inserting base64 encoded image into IMG src after converting html to Image is not creating properly
created image has not appearing base64 encoded image

however my focus is to genrate image from HTML content including Base64 encoded img tag

Even i have tried IResourceLoadingCallback to load image file from local folder also tried to put image into SHAP.getImageData().setImage(); but thats not working any idea

see the attached zip file
AsposeHtmlToImage.zip (255.2 KB)

@jVivek

Looks like you are using Aspose.Words to generate PDF from HTML and then using Aspose.PDF to convert obtained PDF into an image.

Can you please try with 24.12 version of each API? If issue still persists, please share following:

  • PDF document generated by Aspose.Words (instead of saving to stream, please try to save it to file path)
  • Image generated by Aspose.PDF 24.12

Hi @asad.ali
I have updated the jar Asopse-Words 24.4 and Aspose-pdf 24.4 version but still i am facing the exception while converting Html to image
When i am deplyoing the application into embedded tomcat server then image folder path is not recognizing nither src/main/resource/defaultCreative.png
nor C:/HCL/unicaM/InteractDT/studio/conf/defaultCreative.png

Even i have tried to Resource loading callback their i have set the data into setData method but

Still i am getting Exception these same error i am getting into latest 24.12 version too

see the attached zip file
AsposeHtmlToImageConverter.zip (7.0 KB)

com.aspose.words.FileCorruptedException: The document appears to be corrupted and cannot be loaded.
	at com.aspose.words.FileFormatUtil.zzIB(Unknown Source) ~[aspose-words-24.4-jdk17.jar:24.4.0]
	at com.aspose.words.Document.zzZhv(Unknown Source) ~[aspose-words-24.4-jdk17.jar:24.4.0]
	at com.aspose.words.Document.zzZva(Unknown Source) ~[aspose-words-24.4-jdk17.jar:24.4.0]
	at com.aspose.words.Document.<init>(Unknown Source) ~[aspose-words-24.4-jdk17.jar:24.4.0]
	at com.aspose.words.Document.<init>(Unknown Source) ~[aspose-words-24.4-jdk17.jar:24.4.0]
	at com.hcl.unica.interact.personalization.common.util.img.AsposeHtmlToImageConverter.convertHtmlToImage(AsposeHtmlToImageConverter.java:97) ~[main/:?]
...
...
Caused by: java.lang.NullPointerException
	at com.aspose.words.internal.zzWnM.zzZva(Unknown Source) ~[aspose-words-24.4-jdk17.jar:24.4.0]
	at com.aspose.words.internal.zzWnM.<init>(Unknown Source) ~[aspose-words-24.4-jdk17.jar:24.4.0]
	at com.aspose.words.internal.zzWnM.<init>(Unknown Source) ~[aspose-words-24.4-jdk17.jar:24.4.0]
	at com.aspose.words.internal.zzWnM.<init>(Unknown Source) ~[aspose-words-24.4-jdk17.jar:24.4.0]
	at com.aspose.words.internal.zzYsk.zzZhv(Unknown Source) ~[aspose-words-24.4-jdk17.jar:24.4.0]
	at com.aspose.words.internal.zzYsk.zzZfN(Unknown Source) ~[aspose-words-24.4-jdk17.jar:24.4.0]
	at com.aspose.words.zzXHy.zzK7(Unknown Source) ~[aspose-words-24.4-jdk17.jar:24.4.0]
	at com.aspose.words.zzYDj.zzZcd(Unknown Source) ~[aspose-words-24.4-jdk17.jar:24.4.0]
	at com.aspose.words.zzYDj.zzWKB(Unknown Source) ~[aspose-words-24.4-jdk17.jar:24.4.0]
	at com.aspose.words.zzYDj.zzYWr(Unknown Source) ~[aspose-words-24.4-jdk17.jar:24.4.0]
	at com.aspose.words.zzYDj.zzXs(Unknown Source) ~[aspose-words-24.4-jdk17.jar:24.4.0]
	at com.aspose.words.zzWIp.zzVRM(Unknown Source) ~[aspose-words-24.4-jdk17.jar:24.4.0]
	at com.aspose.words.zzWWl.zzZva(Unknown Source) ~[aspose-words-24.4-jdk17.jar:24.4.0]
	at com.aspose.words.zzWWl.zzXDA(Unknown Source) ~[aspose-words-24.4-jdk17.jar:24.4.0]
	at com.aspose.words.zzWWl.zzZva(Unknown Source) ~[aspose-words-24.4-jdk17.jar:24.4.0]
	at com.aspose.words.zzWWl.zzZhv(Unknown Source) ~[aspose-words-24.4-jdk17.jar:24.4.0]
	at com.aspose.words.zzWWl.zzZva(Unknown Source) ~[aspose-words-24.4-jdk17.jar:24.4.0]
	at com.aspose.words.zzWWl.zzZva(Unknown Source) ~[aspose-words-24.4-jdk17.jar:24.4.0]
	at com.aspose.words.zzWWl.zzZva(Unknown Source) ~[aspose-words-24.4-jdk17.jar:24.4.0]
	at com.aspose.words.zzXPc.zzWd5(Unknown Source) ~[aspose-words-24.4-jdk17.jar:24.4.0]
	at com.aspose.words.Document.zzZhv(Unknown Source) ~[aspose-words-24.4-jdk17.jar:24.4.0]
	... 292 more

Could you please provide me the correct code thanks

@jVivek

Looks like the origin of exception is Aspose.Words. We have moved the thread to respective category where you will be assisted shortly.

Hello @asad.ali
Where did you move this could you please tag me their and we have a license of Aspose-words and aspose-pdf then could you please suggest me where i can get quick assistance about it

@alexey.noskov could you please help above topic

@jVivek Unfortunately, I cannot reproduce the problem on my side. I can successfully converted your HTML document to images using the following simple code:

Document doc = new Document("C:\\Temp\\in.html");
PageSetup ps = doc.getFirstSection().getPageSetup();
// Set margins.
ps.setTopMargin(0);
ps.setBottomMargin(0);
ps.setLeftMargin(0);
ps.setRightMargin(0);
// Set page size and orientation.
ps.setPaperSize(PaperSize.A3);
ps.setOrientation(Orientation.LANDSCAPE);

ImageSaveOptions opt = new ImageSaveOptions(SaveFormat.PNG);
for (int i = 0; i < doc.getPageCount(); i++)
{
    opt.setPageSet(new PageSet(i));
    doc.save("C:\\Temp\\out_" + i + ".png", opt);
}

@alexey.noskov
sample.zip (140.1 KB)

Still i am getting exception

private void convertHtmlToImage1(String fileName) {

        try {
            Document doc = new Document(fileName);
            PageSetup ps = doc.getFirstSection().getPageSetup();
            // Set margins.
            ps.setTopMargin(0);
            ps.setBottomMargin(0);
            ps.setLeftMargin(0);
            ps.setRightMargin(0);

            // Set page size and orientation.
            ps.setPaperSize(PaperSize.A3);
            ps.setOrientation(Orientation.LANDSCAPE);

            ImageSaveOptions opt = new ImageSaveOptions(SaveFormat.PNG);
            for (int i = 0; i < doc.getPageCount(); i++)
            {
                opt.setPageSet(new PageSet(i));
                doc.save("out_" + i + ".png", opt);
            }
        }catch (Exception e) {
            throw new RuntimeException(e);
        }

    }
Caused by: com.aspose.words.FileCorruptedException: The document appears to be corrupted and cannot be loaded.
	at com.aspose.words.FileFormatUtil.zzIB(Unknown Source) ~[aspose-words-24.4-jdk17.jar:24.4.0]
	at com.aspose.words.Document.zzZhv(Unknown Source) ~[aspose-words-24.4-jdk17.jar:24.4.0]
	at com.aspose.words.Document.zzZva(Unknown Source) ~[aspose-words-24.4-jdk17.jar:24.4.0]
	at com.aspose.words.Document.<init>(Unknown Source) ~[aspose-words-24.4-jdk17.jar:24.4.0]
	at com.aspose.words.Document.<init>(Unknown Source) ~[aspose-words-24.4-jdk17.jar:24.4.0]
	at com.hcl.unica.interact.personalization.common.util.img.AsposeHtmlToImageConverter.convertHtmlToImage1(AsposeHtmlToImageConverter.java:170) ~[main/:?]
	... 288 more
Caused by: java.lang.NullPointerException
	at com.aspose.words.internal.zzWnM.zzZva(Unknown Source) ~[aspose-words-24.4-jdk17.jar:24.4.0]
	at com.aspose.words.internal.zzWnM.<init>(Unknown Source) ~[aspose-words-24.4-jdk17.jar:24.4.0]
	at com.aspose.words.internal.zzWnM.<init>(Unknown Source) ~[aspose-words-24.4-jdk17.jar:24.4.0]
	at com.aspose.words.internal.zzWnM.<init>(Unknown Source) ~[aspose-words-24.4-jdk17.jar:24.4.0]
	at com.aspose.words.internal.zzYsk.zzZhv(Unknown Source) ~[aspose-words-24.4-jdk17.jar:24.4.0]
	at com.aspose.words.internal.zzYsk.zzZfN(Unknown Source) ~[aspose-words-24.4-jdk17.jar:24.4.0]
	at com.aspose.words.zzXHy.zzK7(Unknown Source) ~[aspose-words-24.4-jdk17.jar:24.4.0]
	at com.aspose.words.zzYDj.zzZcd(Unknown Source) ~[aspose-words-24.4-jdk17.jar:24.4.0]
	at com.aspose.words.zzYDj.zzWKB(Unknown Source) ~[aspose-words-24.4-jdk17.jar:24.4.0]
	at com.aspose.words.zzYDj.zzYWr(Unknown Source) ~[aspose-words-24.4-jdk17.jar:24.4.0]
	at com.aspose.words.zzYDj.zzXs(Unknown Source) ~[aspose-words-24.4-jdk17.jar:24.4.0]
	at com.aspose.words.zzWIp.zzVRM(Unknown Source) ~[aspose-words-24.4-jdk17.jar:24.4.0]
	at com.aspose.words.zzWWl.zzZva(Unknown Source) ~[aspose-words-24.4-jdk17.jar:24.4.0]
	at com.aspose.words.zzWWl.zzXDA(Unknown Source) ~[aspose-words-24.4-jdk17.jar:24.4.0]
	at com.aspose.words.zzWWl.zzZva(Unknown Source) ~[aspose-words-24.4-jdk17.jar:24.4.0]
	at com.aspose.words.zzWWl.zzZhv(Unknown Source) ~[aspose-words-24.4-jdk17.jar:24.4.0]
	at com.aspose.words.zzWWl.zzZva(Unknown Source) ~[aspose-words-24.4-jdk17.jar:24.4.0]
	at com.aspose.words.zzWWl.zzZva(Unknown Source) ~[aspose-words-24.4-jdk17.jar:24.4.0]
	at com.aspose.words.zzWWl.zzZva(Unknown Source) ~[aspose-words-24.4-jdk17.jar:24.4.0]
	at com.aspose.words.zzXPc.zzWd5(Unknown Source) ~[aspose-words-24.4-jdk17.jar:24.4.0]
	at com.aspose.words.Document.zzZhv(Unknown Source) ~[aspose-words-24.4-jdk17.jar:24.4.0]
	at com.aspose.words.Document.zzZva(Unknown Source) ~[aspose-words-24.4-jdk17.jar:24.4.0]
	at com.aspose.words.Document.<init>(Unknown Source) ~[aspose-words-24.4-jdk17.jar:24.4.0]
	at com.aspose.words.Document.<init>(Unknown Source) ~[aspose-words-24.4-jdk17.jar:24.4.0]
	at com.hcl.unica.interact.personalization.common.util.img.AsposeHtmlToImageConverter.convertHtmlToImage1(AsposeHtmlToImageConverter.java:170) ~[main/:?]

@jVivek The problem is not reproducible on my side with the latest 24.12 version of Aspose.Words for Java. Please try using the latest version on your side and let us know if the problem still persists.

@alexey.noskov
the problem is occurring only when i have running on application With tomcat embedded server
but when i am running it without server as command line it generating image

aspose-words 24.12 jar is not available on repository so i using 24.10

but its not working with Application sever (Tomact) … disappointing

if possible, can we have schedule the call regarding it please

@jVivek 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): WORDSJAVA-3020

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.

Hello @alexey.noskov
we already have license of aspose word and aspose pdf then also do we need paid support servcie ?

@jVivek Paid support services allows to push the issue upper in the queue. The issue is currently in the queue for analysis, once analysis is done we will be able to provide you more information regarding the issue.