We're sorry Aspose doesn't work properply without JavaScript enabled.

Free Support Forum - aspose.com

Converting RTF to Aspose.Words

Hi ,
I’m using version of Aspose.PDF and version of Aspose.Words.
I am trying to convert an RTF to Aspose.words and am getting the following error:
Exception Details: Aspose.Pdf.Exceptions.InvalidPdfFileFormatException: Incorect file format
I have tried to convert my RTF stream directly into an Aspose.Words doc but i get the error above:

thisDocument = new Words.Document(inputdocumentStream);

And after reading some similar forum questions i have tried to convert the stream first into an Aspose PDF doc and then convert that into Aspose.Words , but am getting the same error:

Pdf.Document inputPdfDocument = new Pdf.Document(inputdocumentStream);

I have attached a sample RTF doc.
Am i doing somehting wrong here or is there a work around for converting an RTF stream into an Aspose word doc ? Thanks in Advance ,

Hi Ali,

Thanks for your inquiry. The method of rendering to PDF using Aspose.Words and the Aspose.Pdf libraries has been deprecated for some time ago. This method is replaced by direct conversion to PDF, which is invoked by calling the Document.Save method. This method of rendering to the PDF format provides improved rendering fidelity and is fully maintained, with new features and bug fixes for it coming out with every release.

Moreover, While using the latest version of Aspose.Words i.e. 11.3.0, I was unable to reproduce any issue during rendering your RTF to PDF format on my side. I used the code mentioned in the following article:

Please let me know if I can be of any further assistance.

Best Regards,

Hi Awais,
This works fine when using a rtf document stored locally ,but i am receiving the rtf document in as a stream as i mentioned in the bug details above and this is where i am getting an error.
Can you please help me convert an RTF stream to an Aspose word document , thanks ,

Hi Awais,
I am still trying to get this working , do i perhaps have to save the RTF stream as a physical document first before i can convert it to an Aspose.Words document ? This is very urgent so any help would be appreciated , thanks ,

Hi Alicia,

Thanks for your inquiry. If your goal is to convert RTF document (from disk or from memory) to PDF format, I would suggest you please use Aspose.Words for .NET only.

Secondly, I was unable to reproduce any exception during loading your RTF document into Aspose.Words DOM. I used the following code snippet for testing:

string fileName = MyDir + "Alicia.rtf";

// Open the stream.
Stream stream = File.OpenRead(fileName);

// Open the document. Note the Document constructor detects HTML format automatically.
// Pass the URI of the base folder so any images with relative URIs in the HTML document can be found.
LoadOptions loadOptions = new LoadOptions();
loadOptions.LoadFormat = LoadFormat.Rtf;

Document doc = new Document(stream, loadOptions);

// You can close the stream now, it is no longer needed because the document is in memory.

// Save in the DOC format.
doc.Save(MyDir + "out.pdf");

Please let me know if I can be of any further assistance.

Best Regards,

Hey mate have you tried same thing at other machine? Maybe it doesnt like your operating system
?! I used to have health issues searching for an answer here… too hard it all for me i guess.

Hi there,

Thanks for your inquiry. Please note that Aspose.Words is platform independent. You can use the code example shared in my colleague’s reply to convert RTF stream into PDF at any system where .NET is installed.

Please let us know if you have any more queries.