Spire.Doc is a professional Word .NET library specifically designed for developers to create, read, write, convert and print Word document files. Get free and professional technical support for Spire.Doc for .NET, Java, Android, C++, Python.

Wed May 01, 2013 5:03 pm

Greetings, my company is actively evaluating the purchase of Spire.Office for .NET Site Enterprise Subscription.

We are looking at the capabilities for generating a Word Doc from HTML, and have come up with a few questions.

We are currently using the Document LoadHTML method, see below.

1) Even when using the Spire.Doc.Documents.XHTMLValidationType.None we receive errors when the HTML is not perfectly formatted. For example, an <Input> tag without a closing tag. Are there any guidelines for how to construct the HTML / CSS for the best compatibility with Spire.Doc?

2) Is there a way to have the document rendered in Landscape (currently it is in portrait)? The PageLayout event does not seem to fire.

3) Are there HTML tags / attributes which will help control where page breaks occur in the rendered PDF?

4) JavaScript tag content that is included in the body is rendered into the Word document at text. Is there any way to prevent this?

Thanks in advance.

private void buttonDoc_Click(object sender, EventArgs e) {
//Get an HTML Stream
string url = "http://localhost:50035";
WebRequest request = WebRequest.Create(url);
WebResponse response = request.GetResponse();
System.IO.Stream webStream = response.GetResponseStream();
TextReader textReader = new StreamReader(webStream);

Document doc = new Document();
doc.PageLayout += doc_PageLayout;
doc.LoadHTML(textReader, Spire.Doc.Documents.XHTMLValidationType.None);
doc.SaveToFile(@"C:\SpireTest.docx");
DocViewer(@"C:\SpireTest.docx");
}

void doc_PageLayout(object sender, Spire.Doc.Documents.Rendering.PageLayoutEventArgs args) {
args.PageSetup.Orientation = Spire.Doc.Documents.PageOrientation.Landscape;
}

private void DocViewer(string fileName) {
try {
System.Diagnostics.Process.Start(fileName);
} catch { }
}

mbyrne
 
Posts: 4
Joined: Mon Apr 29, 2013 2:29 pm

Thu May 02, 2013 8:42 am

Dear Michael,

Thanks for your inquiry.
For 1#, our Spire.Doc component doesn't support to convert HTML elements whithout closing tags to word at present, but our dev team is working on this feature at present. There is any update on it, we will tell you.

For 2#, please try the code snippet below to render the document in Landscape.
Code: Select all
  Document doc = new Document();
               doc.LoadHTML(textReader, XHTMLValidationType.None);
                foreach (Section section in doc.Sections)
                {
                    section.PageSetup.Orientation = Spire.Doc.Documents.PageOrientation.Landscape;
                }


For 3#, sorry for that our Spire.Doc component doesn't support page break html tag at present.
We have added it as a new feature into our shedule. Now you can refer to the code snippet below to try to find the specific text , and then add pageBreak before the text .
Code: Select all
 
               TextSelection select = doc.FindString(specificText, true, true);
                Paragraph p = select.GetAsOneRange().OwnerParagraph;
                Break item = p.AppendBreak(BreakType.PageBreak);
                p.ChildObjects.Insert(0, item);
         


For 4#, I have reproduced this issue and posted it to our dev team. Sorry for the inconvenience.
Our dev colleagues will do some researches and fix it. Once it has been solved, we will tell you.

If you have other issues, please feel free to contact us.

Regards,
Amy
E-iceblue support team
User avatar

amy.zhao
 
Posts: 2766
Joined: Wed Jun 27, 2012 8:50 am

Wed May 08, 2013 9:05 am

Dear Michael,

Do you try the code about issue2 and issue3? Does the code solve these two issues?
Please give us a feedback message at your early convenience.

Thanks and Regards,
Amy
E-iceblue support team
User avatar

amy.zhao
 
Posts: 2766
Joined: Wed Jun 27, 2012 8:50 am

Fri May 10, 2013 9:26 am

Dear Michael,

Thanks for your waiting.
The new version which supports converting the HTML elements without closing tags to PDF has been released.
Please download and test Spire.Doc Pack Version:4.8 (http://www.e-iceblue.com/Download/download-word-for-net-now.html).

Regards,
Amy
E-iceblue support team
User avatar

amy.zhao
 
Posts: 2766
Joined: Wed Jun 27, 2012 8:50 am

Wed May 15, 2013 10:52 am

Dear Michael,

Has the issue been resolved? Could you please update the thread if convenience?

If there are any questions, welcome to get it back to us.


Regards,
Gary
E-iceblue support team
User avatar

Gary.zhang
 
Posts: 1380
Joined: Thu Apr 04, 2013 1:30 am

Return to Spire.Doc