Hello
If you run my sample to convert html to rtf you’ll see the result is not shown correctly both in Word 2021 or Windows 10 WordPad: WindowsApplication396.zip (6.2 MB)
WordPad will not render back colors at all.
Word 2021 will not honor the table width and spacings.
Any workaround?
@australian.dev.nerds Please note, Aspose.Words is designed to work with MS Word documents. HTML documents and MS Word documents object models are quite different and it is not always possible to provide 100% fidelity after conversion one format to another. When import HTML documents Aspose.Words in most cases mimics MS Word behavior. If you try converting your HTML to RTF using MS Word, you will get almost the same result as Aspose.Words result: out.zip (11.4 KB)
Hello and thanks, when I open html in Word 2021 and save as RTF I see:
OK, anyway, when loading an html or mhtml to be saved as RTF, which Rtf save options should be used IF I need to import the generated RTF directly to Aspose Email as the BodyRTF of MapiMessage?
Not sure if Outlook uses a specific kind of RTF for Mapi Message Body RTF.
Thanks.
@australian.dev.nerds Content in your document is formatted with DIVs. There is no direct analog of DIV elements in MS Word documents, usually the DIV s are converted to paragraphs in Aspose.Words DOM.
You can set HtmlLoadOptions.BlockImportMode to preserve DIVs and MS Word does:
HtmlLoadOptions opt = new HtmlLoadOptions();
opt.BlockImportMode = BlockImportMode.Preserve;
Document doc = new Document(@"C:\Temp\in.htm", opt);
doc.Save(@"C:\Temp\out.rtf");
Thanks, source eml/ mhtml can have any kind of file type attached, what about target Pdf document, also can have any kind of file type attached?
What other formats support such attachments? Doc, Docx etc?
No any save option to automate adding of source attachments to the target file?
Sure, but what about save output parameters? Since didn’t find enough info on docs, or sample to check it.
Do you find it wise to add a save option to disable it? Consult some developers, to me, seems unnecessary while increasing the output size in huge amounts of data.
Embedded OLE objects are supported in DOC, DOCX, RTF, XML (Word 2003 and Word 2007 XML), ODT and PDF formats.
SaveOutputParameters is returned to the caller after a document is saved and contains additional information that has been generated or calculated during the save operation. The caller can use or ignore this object. Currently this object contains only Content-Type of the saved document.
We will consider adding such option. I have logged the feature request as WORDSNET-25621.
Hello,
First of all, when loading Html or Mhtml and saving as Docx or Rtf, the HR tag is lost or not rendered: <hr>
Second, as my 1st post in this topic, if you check my source Html and result files: docs.zip (91.5 KB)
When saving as PDF and other formats, it’s still good, but saving to Docx and Rtf is not:
The problem with Docx is the back color/ table back color not extending to the fixed width, like when saving to other formats!
The problem with Rtf (which is think not your fault, just looking for workaround) is that the back color is not rendered in Rtf, I think Rtf supprts Text Highligh back color.
When that back color is not rendered, texts with White color will be invisible in the target file.
Before you advised about BlockImportMode.Preserve but to convert my html to documents with the same output look, since you mentioned there’s no equalivant of DIV elements in Word documents, I can change DIV to something else that can be converted to Word perfectly, what do you recommend to change my DIVs to?
Thanks.
I cannot reproduce the problem on my side. I have used the following simple HTML as an input document and as I can see horizontal rule is properly preserve in output documents:
Background is properly rendered if open RTF document in MS Word or OpenOffice. But simple viewers like WordPad does not show background.
You can use regular paragraph instead of DIV tags. P html tag corresponds a Paragraph node in Aspose.Words DOM.
Alternatively, you can use a centered table with cell paddings and fixed width.
But you should note, in general it is impossible to preserve original HTML document formatting when convert HTML to word formats, due to difference in their document object models and rules used by browsers and MS Word.
highlight color in this case will be preserved in RTF and will be properly displayed in both MS Word and WordPad.
I am afraid, WordPad cannot be used as an etalon viewer, due to it’s limited functionality. As you know MS Word documents are flow documents and their appearance in the viewer depends on the viewer’s layout engine implementation and the level of the document format specification support. The same document might looks differently when open it in MS Word, Open Office and WordPad.