We're sorry Aspose doesn't work properply without JavaScript enabled.

Free Support Forum - aspose.com

Html to pdf conversion hung if images are present

  1. A very simple source html file source.html
<!DOCTYPE html>
<html>
  <head>
  </head>
  <body>
    <div class="header">
      <h1>My Website</h1>
      <p>Lorem, ipsum dolor sit amet consectetur adipisicing elit. Dolorum molestias, ipsam asperiores illum repudiandae nesciunt, est dolorem quia cupiditate suscipit voluptatum iure autem non libero doloremque mollitia rem aliquid veritatis?</p>
      <div class="site-logo">
        <img src="https://www.gettyimages.in/gi-resources/images/Embed/new/embed2.jpg" alt="logo"/>
      </div>
    </div>
  </body>
</html>
  1. Maven dependency
		<dependency>
			<groupId>com.aspose</groupId>
			<artifactId>aspose-pdf</artifactId>
			<version>21.12</version>
		</dependency>
  1. Java code to convert html to pdf

	public static void main(String[] args) {
		convert();
		System.out.println("Done");
	}

	private static void convert() {
		MarginInfo marginInfo = new MarginInfo();
		marginInfo.setLeft(5);
		marginInfo.setRight(5);
		
		PageInfo pageInfo = new PageInfo();
		pageInfo.setMargin(marginInfo);

		// Create a HTML LoadOptions
		HtmlLoadOptions options = new HtmlLoadOptions();
		options.setPageInfo(pageInfo);
		// Initialize document object
		String htmlFileName = Paths.get("source.html").toString();
		Document document = new Document(htmlFileName, options);

		// Save output PDF document
		document.save(Paths.get("render.pdf").toString());
		document.close();
	}

“Done” never prints (unless the div containing the img is removed from source.html) and the program just hangs. What am I missing? Would appreciate some help to get this very simple conversion to work.

  1. My environment
$ java --version
openjdk 11.0.13 2021-10-19
OpenJDK Runtime Environment (build 11.0.13+8-Ubuntu-0ubuntu1.20.04)
OpenJDK 64-Bit Server VM (build 11.0.13+8-Ubuntu-0ubuntu1.20.04, mixed mode, sharing)

$ javac --version
javac 11.0.13

@kpkeerthi

We have managed to reproduce the same issue at our side. For the sake of correction, we have logged this problem in our issue tracking system as PDFJAVA-41183. You will be notified via this forum thread once this issue is resolved.

We apologize for your inconvenience.

1 Like