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

Free Support Forum - aspose.com

Java html to pdf problems

Hi, I’m using Aspose.Pdf for Java version (just ordered it last week or so). I can’t seem to get the simplest of html documents converted to PDF. I have searched the forums and read many posts, but still can’t seem to get it to work. Here is my code (I have tried several different permuatations of this code):

String fileName = “C:\tester\test.html”;
Pdf pdf = new Pdf ();
File html = new File(fileName);
pdf.bindHTML( new FileInputStream(html),new URL(“file:/” + fileName));
pdf.save(new FileOutputStream(new File(“C:\tester\test.pdf”)));

test.html just looks like test

The problem I get is that it either creates an empty pdf file or a corrupt pdf file. When I open with Adobe reader 7, it says it cannot open it because it is an unsupported type or has been damaged.

Ideally I would like to get this working before the end of Monday, so a quick response would be very helpful! Thanks,


Well, I managed to get it to work after putting the text inside a tag. Are you not allowed to have plain text inside the html tags?


Dear Kevin,

I think this is a bug of Aspose.Pdf. I have logged it as PDFJAVA-3904 and we will try to fix it in the future version.

Hi kpriebe,

<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" />

Thanks you for considering Aspose.

Text can not be nested directly in tag, because it doesn't comply with XHTML standard. So text must be nested in other tags, such as tag, a example is shown below