Hi Aspose Team,
We are using Aspose.word (version:21.8.0.0) library to convert RTF data to html and display the data in PDF format. But when we set margins with 0.5 height, width the RTF text is not properly aligned. Attached the RTF text and PDF for reference. Please check and help on how to resolve this issue.
Thanks,
Kartheek K S
RTFTOHTML_ Print Preview.pdf (38.9 KB)
Data.zip (2.5 KB)
@Kskartheek Could you please provide a code which will allow us to reproduce the problem? As I can see the PDF you have attached was not produced by Aspose.Words. Also it would be great if you attach the expected output document.
Hi Alexey.Noskov,
Thank you for the response.
Below is the code snippet used to convert html to RTF.
public static string HtmlToRtf(string html)
{
Aspose.Words.Document doc;
using (Stream s = GenerateStreamFromString(html))
{
doc = new Aspose.Words.Document(s);
}
Aspose.Words.Saving.RtfSaveOptions saveOptions = new Aspose.Words.Saving.RtfSaveOptions
{
SaveFormat = Aspose.Words.SaveFormat.Rtf,
ExportImagesForOldReaders = false
};
using (MemoryStream rtfStream = new MemoryStream())
{
doc.Save(rtfStream, saveOptions);
return Encoding.UTF8.GetString(rtfStream.ToArray());
}
}
And code snippet used for converting RTF to html.
public static string RtfToHtml(string rtf)
{
Aspose.Words.Document doc;
using (Stream s = GenerateStreamFromString(rtf))
{
doc = new Aspose.Words.Document(s);
}
Aspose.Words.Saving.HtmlSaveOptions saveOptions = new Aspose.Words.Saving.HtmlSaveOptions();
saveOptions.SaveFormat = Aspose.Words.SaveFormat.Html;
saveOptions.ExportImagesAsBase64 = true;
saveOptions.ExportHeadersFootersMode = Aspose.Words.Saving.ExportHeadersFootersMode.None;
using (MemoryStream htmlStream = new MemoryStream())
{
doc.Save(htmlStream, saveOptions);
String myHtml = Encoding.UTF8.GetString(htmlStream.ToArray());
return myHtml;
}
}
Also attached the required output format. Please observe the examples attached for differences.Data.zip (84.6 KB)
Thanks,
Kartheek
@Kskartheek The RTF string you have attached contains only two lines of text:
But if I understand the problem correctly the problem occurs with other content in your document. Correct me if I am wrong.
Also if you need to should preview of the document, I would recommend you to use HtmlFixed savor format instead of flow Html format. In this case preview will look exactly as in MS Word.
Is you final goal is conversion to PDF? Why do not you use Aspose.Words to convert RTF directly to PDF?
Hi Alexey.Noskov,
Thank you so much for the response.
In your screen shot, yes not working on other part of the data. but attachment contains other part of data also in the txt file. Please verify.Data.zip (84.6 KB)
HTMLFixed is not working and we are getting the error as "“An invalid SaveFormat for this options type was chosen.”. Could you please share a sample code that we can use.
Our goal is to provide in html view to show the data in preview and same data is used to print.
Thanks,
Kartheek K S
@Kskartheek
Unfortunately, I do not see other data but the data on the screenshot I have attached. Please check on your side.
You should to use HtmlFixedSaveOptions
instead of HtmlSaveOptions
to save your document as HTML Fixed.
Hi Alexey.Noskov,
Thank you for fast response.
For our scenario HTMLFixedSaveOptions may not work. Its expecting physical file locations to store images,fonts and ResourceSavingCallback properties. In our case we are directly getting the data from bytestream and taking to string to show in html. Without these options do we have any other option?
Thanks.
kartheek K S.
@Kskartheek you can set ExportEmbeddedCss, ExportEmbeddedFonts, ExportEmbeddedImages and ExportEmbeddedSvg to make all required resources embedded into the output file/stream.