JonathanS1
September 8, 2006, 12:04:59
Hi, can you help with a styles issue when converting HTML to Word or PDF?
I have parts of a document stored as HTML fragments in SQLServer and am constructing a publication using these fragments. For example, this is some of the text stored in the database:
<span class="standard">CLINICAL MANAGEMENT OF THE TRANSFUSION EPISODE </span>
and
<SPAN class="criterion">A consent policy is in place, which includes an explanation of relevant legislation and best practice guidance. </SPAN>
The code to generate the final publication extracts what it needs from the database and then does the following:
ss.CssSaveMode = CssSaveMode.None
tx.Save(text, StringStreamType.HTMLFormat, ss)
text = http.HtmlDecode(text)
where tx is TXTextControl.ServerTextControl.
Then, I open the CSS file containing the class definitions and insert the contents into the variable 'text' as follows so that ALL class definitions are included within the HTML produced:
text = text.Insert(text.IndexOf("<body"), "<style type='text/css' >" & css & "</style>")
If I place a breakpoint in the code and copy the HTML produced into, for example, Dreamweaver, the document created displays perfectly using the classes inserted from the CSS file, so I know the HTML created is correct.
Now, I need to convert this output to Word or PDF (depends on what the user requested), so the code does this:
tx.ResetContents()
tx.Load(text, StringStreamType.HTMLFormat)
and convert this HTML to, in this case, PDF:
tx.Save(pdf, BinaryStreamType.AdobePDF)
But ALL HTML styles formatting is lost. How can I convert HTML to Word/PDF AND retain all the formatting from the HTML?
Regards,
Jonathan
I have parts of a document stored as HTML fragments in SQLServer and am constructing a publication using these fragments. For example, this is some of the text stored in the database:
<span class="standard">CLINICAL MANAGEMENT OF THE TRANSFUSION EPISODE </span>
and
<SPAN class="criterion">A consent policy is in place, which includes an explanation of relevant legislation and best practice guidance. </SPAN>
The code to generate the final publication extracts what it needs from the database and then does the following:
ss.CssSaveMode = CssSaveMode.None
tx.Save(text, StringStreamType.HTMLFormat, ss)
text = http.HtmlDecode(text)
where tx is TXTextControl.ServerTextControl.
Then, I open the CSS file containing the class definitions and insert the contents into the variable 'text' as follows so that ALL class definitions are included within the HTML produced:
text = text.Insert(text.IndexOf("<body"), "<style type='text/css' >" & css & "</style>")
If I place a breakpoint in the code and copy the HTML produced into, for example, Dreamweaver, the document created displays perfectly using the classes inserted from the CSS file, so I know the HTML created is correct.
Now, I need to convert this output to Word or PDF (depends on what the user requested), so the code does this:
tx.ResetContents()
tx.Load(text, StringStreamType.HTMLFormat)
and convert this HTML to, in this case, PDF:
tx.Save(pdf, BinaryStreamType.AdobePDF)
But ALL HTML styles formatting is lost. How can I convert HTML to Word/PDF AND retain all the formatting from the HTML?
Regards,
Jonathan