Good morning,
How to convert HTML Text to Word not converting HTML File to Word
can you give me an example
PdfDocument pdf = new PdfDocument();
PdfHtmlLayoutFormat htmlLayoutFormat = new PdfHtmlLayoutFormat();
//webBrowser loads html whether waiting
htmlLayoutFormat.IsWaiting = false;
//page setting
PdfPageSettings setting = new PdfPageSettings();
setting.Size = PdfPageSize.A4;
//use single thread to generate the pdf from above html code
Thread thread = new Thread(() =>
{ pdf.LoadFromHTML(htmlText, false, setting, htmlLayoutFormat); });
thread.SetApartmentState(ApartmentState.STA);
thread.Start();
thread.Join();
pdf.SaveToFile("output.doc",FileFormat.DOC);
System.Diagnostics.Process.Start("output.doc");
Dim document As New Document()
Dim paragraph As Documents.Paragraph = document.AddSection().AddParagraph()
paragraph.Format.IsBidi = True
paragraph.AppendHTML(div.InnerHtml)
Dim tr As TextRange = paragraph.AppendText("")
tr.CharacterFormat.Bidi = True
document.SaveToFile("output.doc", FileFormat.Docx)
Dim document As New Spire.Doc.Document()
Dim tr As TextReader = New StringReader(div.InnerText)
document.LoadHTML(tr, Documents.XHTMLValidationType.None)
document.SaveToFile("output.doc", FileFormat.Doc)
Document document = new Document();
//load html file
document.LoadFromFile("..\\..\\input\\HTMLfile.html",FileFormat.Html,XHTMLValidationType.None);
//or load html code
//string htmlcode = File.ReadAllText("..\\..\\input\\HTMLfile.html");
//TextReader tr = new StringReader(htmlcode);
//document.LoadHTML(tr, XHTMLValidationType.None);
foreach (Section section in document.Sections)
{
foreach (DocumentObject obj in section.Body.ChildObjects)
{
if (obj.DocumentObjectType == DocumentObjectType.Paragraph)
{
Paragraph para = obj as Paragraph;
foreach (ParagraphBase paragraphBase in para.ChildObjects)
{
paragraphBase.CharacterFormat.Bidi = true;
}
}
if (obj.DocumentObjectType == DocumentObjectType.Table)
{
SetParagraphInTable(obj as Table);
}
}
}
document.SaveToFile("output.docx", FileFormat.Docx);
System.Diagnostics.Process.Start("output.docx");
private static void SetParagraphInTable(Spire.Doc.Table table)
{
for (int i = 0; i < table.Rows.Count; i++)
{
Spire.Doc.TableRow row = table.Rows[i];
for (int j = 0; j < row.Cells.Count; j++)
{
Spire.Doc.TableCell cell = row.Cells[j];
if (cell.Tables.Count > 0)
{
foreach (DocumentObject cellChild in cell.ChildObjects)
{
if (cellChild.DocumentObjectType == DocumentObjectType.Table)
{
SetParagraphInTable(cellChild as Spire.Doc.Table);
}
}
}
foreach (Paragraph paragraph in cell.Paragraphs)
{
foreach (ParagraphBase paragraphBase in paragraph.ChildObjects)
{
paragraphBase.CharacterFormat.Bidi = true;
}
}
}
}
}