HTML to Image parse fail


#1

I am trying to convert an html file to image using ImageDevice as follows:

public static void htmlToImage3(String html, String imageName) throws FileNotFoundException {
	String f = "filename.html";
	PrintWriter out = new PrintWriter(f);
	out.println(html);
	out.close();
	
	HTMLDocument doc = new HTMLDocument(f);
	HtmlRenderer renderer = new HtmlRenderer();
	ImageRenderingOptions o = new ImageRenderingOptions();
	ImageDevice i = new ImageDevice(o, imageName);
	
	renderer.render(i, doc);
}

Error on running this:

class com.aspose.html.internal.p67.z4: Failed to parse base URL.
com.aspose.html.internal.p65.z1.m42(Unknown Source)
com.aspose.html.Url.<init>(Unknown Source)
com.aspose.html.HTMLDocument.<init>(Unknown Source)

Html File Attached. Also worth noting that the HTML generated is from aspose.words using Node.toString.

filename.html.zip (1.0 KB)


#2

@amankapur91

Thank you for contacting support.

We have worked with the data shared by you but have not been able to reproduce it in our environment. Below is little modified version of your code snippet which successfully generates an image. We have attached generated image file for your kind reference. test.jpg

public static void htmlToImage3(String html, String imageName) throws FileNotFoundException {
String f = "D:\\filename.html\\filename.html";
//	PrintWriter out = new PrintWriter(f);
//	out.println(html);
//	out.close();

HTMLDocument doc = new HTMLDocument(f);
HtmlRenderer renderer = new HtmlRenderer();
com.aspose.html.rendering.image.ImageRenderingOptions o = new com.aspose.html.rendering.image.ImageRenderingOptions();
com.aspose.html.rendering.image.ImageDevice i = new com.aspose.html.rendering.image.ImageDevice(o, imageName);

renderer.render(i, doc);
}

htmlToImage3("" , "D:\\filename.html\\test.jpg");

Please ensure using Aspose.HTML for Java 18.10.2 in your environment and then share your kind feedback with us. In case the issue persists, kindly create a sample console application so that we may investigate further.


#3

Thank you for you help. I upgraded to 18.10.2 however, now I get the following error on the same file:

Exception in thread "main" java.lang.AssertionError: Cannot read a name from the name table in a font.
at com.aspose.html.internal.ms.System.Diagnostics.Debug.fail(Unknown Source)
at com.aspose.html.internal.p31.z26.m306(Unknown Source)
at com.aspose.html.internal.p31.z26.m666(Unknown Source)
at com.aspose.html.internal.p31.z26.m2(Unknown Source)
at com.aspose.html.internal.p31.z11.m1(Unknown Source)
at com.aspose.html.internal.p31.z11.<init>(Unknown Source)
at com.aspose.html.internal.p31.z8.m618(Unknown Source)
at com.aspose.html.internal.p31.z8.m617(Unknown Source)
at com.aspose.html.internal.p31.z8.m7(Unknown Source)
at com.aspose.html.internal.p31.z10.m2(Unknown Source)
at com.aspose.html.internal.p31.z10.m1(Unknown Source)
at com.aspose.html.internal.p31.z10.m3(Unknown Source)
at com.aspose.html.internal.p185.z2.m1(Unknown Source)
at com.aspose.html.internal.p184.z10.m1(Unknown Source)
at com.aspose.html.internal.p207.z6.m6(Unknown Source)
at com.aspose.html.internal.p144.z33.<init>(Unknown Source)
at com.aspose.html.internal.p144.z5.m1(Unknown Source)
at com.aspose.html.internal.p144.z5.<init>(Unknown Source)
at com.aspose.html.internal.p206.z21.m2(Unknown Source)
at com.aspose.html.internal.p155.z1.<init>(Unknown Source)
at com.aspose.html.internal.p142.z3.m2193(Unknown Source)
at com.aspose.html.internal.p143.z1.m1(Unknown Source)
at com.aspose.html.internal.p241.z1.m1(Unknown Source)
at com.aspose.html.rendering.HtmlRenderer.render(Unknown Source)

Also in the image you attached, please note that the borders are not on all cells of the table as they should be.

EDIT:
I have added font location as follows:

String fontLoc = "/Users/amankapur/Library/fonts/";
FontSettings.getDefaultInstance().setFontsFolder(fontLoc, true);

I am using MacOS.


#4

@amankapur91

Would you please share a narrowed down sample application reproducing this issue. Please also mention environment details including version of Mac OS, JDK/JRE for our reference.


#5

Sure. I ran the following:

package test;

import com.aspose.html.HTMLDocument;
import com.aspose.html.rendering.HtmlRenderer;
import com.aspose.html.rendering.image.ImageDevice;
import com.aspose.html.rendering.image.ImageRenderingOptions;
import com.aspose.words.FontSettings;

public class AppView {

    public static void main(String[] args) {
    
        FontSettings.getDefaultInstance().setFontsFolder("/Users/amankapur/Library/fonts/", true);
        HTMLDocument doc = new HTMLDocument("filename.html");
	    HtmlRenderer renderer = new HtmlRenderer();
	    ImageRenderingOptions o = new ImageRenderingOptions();
	    ImageDevice i = new ImageDevice(o, "filename.png");
		
	    renderer.render(i, doc);
	
    }
}

And go this error:

Exception in thread "main" java.lang.AssertionError: Cannot read a name from the name table in a font.
at com.aspose.html.internal.ms.System.Diagnostics.Debug.fail(Unknown Source)
at com.aspose.html.internal.p31.z26.m306(Unknown Source)
at com.aspose.html.internal.p31.z26.m666(Unknown Source)
at com.aspose.html.internal.p31.z26.m2(Unknown Source)
at com.aspose.html.internal.p31.z11.m1(Unknown Source)
at com.aspose.html.internal.p31.z11.<init>(Unknown Source)
at com.aspose.html.internal.p31.z8.m618(Unknown Source)
at com.aspose.html.internal.p31.z8.m617(Unknown Source)
at com.aspose.html.internal.p31.z8.m7(Unknown Source)
at com.aspose.html.internal.p31.z10.m2(Unknown Source)
at com.aspose.html.internal.p31.z10.m1(Unknown Source)
at com.aspose.html.internal.p31.z10.m3(Unknown Source)
at com.aspose.html.internal.p185.z2.m1(Unknown Source)
at com.aspose.html.internal.p184.z10.m1(Unknown Source)
at com.aspose.html.internal.p207.z6.m6(Unknown Source)
at com.aspose.html.internal.p144.z33.<init>(Unknown Source)
at com.aspose.html.internal.p144.z5.m1(Unknown Source)
at com.aspose.html.internal.p144.z5.<init>(Unknown Source)
at com.aspose.html.internal.p206.z21.m2(Unknown Source)
at com.aspose.html.internal.p155.z1.<init>(Unknown Source)
at com.aspose.html.internal.p142.z3.m2193(Unknown Source)
at com.aspose.html.internal.p143.z1.m1(Unknown Source)
at com.aspose.html.internal.p241.z1.m1(Unknown Source)
at com.aspose.html.rendering.HtmlRenderer.render(Unknown Source)
at test.AppView.main(AppView.java:21)

OS: MacOs Mojave 10.14
JDK: 1.8.0_144
Aspose Words 18.10-jdk16
Aspose HTML 18.10.2
IDE: Eclipse ( Version: 2018-09 (4.9.0), Build id: 20180917-1800)

➜  ~ java --version
java 9.0.1
Java(TM) SE Runtime Environment (build 9.0.1+11)
Java HotSpot(TM) 64-Bit Server VM (build 9.0.1+11, mixed mode)

#6

@amankapur91

Thank you for sharing further details.

We have managed to reproduce the issue with latest available version. A ticket with ID HTMLJAVA-172 has been logged in our issue management system for further investigation and resolution. The ticket ID has been linked with this thread so that you will receive notification as soon as the ticket is resolved.

We are sorry for the inconvenience.


#7

Is there an environment in which this works which I can switch too ?


#8

@amankapur91

We are afraid any workaround approach or suggestions may not be available at the moment. We will let you know as soon as some significant updates will be available in this regard. We appreciate your patience in this regard.


#9

@Farhan.Raza

Is there any update on this? This is mission critical for us to use aspose or not.


#10

@amankapur91

We are afraid there is not any update at the moment. Resolution of tickets usually take few months so we appreciate your patience and comprehension in this regard. We will let you know as soon as some significant updates will be available.