Load HTML


#1

In your product comparison you write “…Open in HTML format… => YES”)

I tried unsuccessfully

Document doc = new Document( “c:\myhtml.html” );

AND

Document doc = new Document( myStream );

To load, always getting “System.Exception: Unknown file format”.

Question: Is there another way to load HTML into Word or is your product comparison wrong?

Thanks
Uwe



#2

Please attach the file to the post, we need it to check the HTML format recognition.


#3

Ah, now I see. I just passed a HTML-fragment (generated from a FreeTextBox on a webform) to the Aspose.Word.

I now add “”- and “”-tags, now it does not throw the exception any more.

But it looks really ugly. This is the HTML code:

Something in bold and italic.

And in the attachment you see the PDF output. Looks rather ugly. Any chance to get this working correctly?


#4

Hi,

It seems like for some reason Aspose.Word evaluation injects the watermark text twice so the converted HTML is placed right between the watermarks… Could you please attach or post your code sample? I have the converted pdf looking fine with this snippet of code:


Document doc = new Document(Path.Combine(PATH, “test.html”));

doc.Save(“temp.xml”, SaveFormat.FormatAsposePdf);

Aspose.Pdf.Pdf pdf = new Aspose.Pdf.Pdf();

pdf.BindXML(“temp.xml”, null);

pdf.Save(Path.Combine(PATH, “result.pdf”));



#5

This is my source:

using ( StreamWriter sw = File.CreateText( @“c:\ablage\asposepdftext2.html” ) )
{
sw.Write( “”+FreeTextControl.Text+"" );
}

Document doc = new Document( @“c:\ablage\asposepdftext2.html” );
doc.Save( @“c:\ablage\asposepdftext2.pdf.xml”, SaveFormat.FormatAsposePdf );

Pdf pdf = new Pdf();
pdf.BindXML( “c:\ablage\asposepdftext2.pdf.xml”, null );
pdf.Save( @“c:\ablage\asposepdftext2.pdf” );


#6

You can also try using new Document() and then DocumentBuilder.InsertHtml() - this method does not require HTML and BODY tags.


#7

Thanks Uwe. Please make sure that you are using the latest version of Aspose.Word and report us if it helps. Anyway, we have logged your request and will try to fix it quickly.


#8

This is fixed in Aspose.Word 2.3.2, it will be released in the next few days, keep an eye on the blogs.