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

# .Net convert RTF to PDF

Hi! im trying to implement Aspose.Words RTF to PDF converter into our application. The method takes in the RTF documents as Byte[] and i need to return them as base64strings. My problem is that i really dont udnerstand what the content of the Document class is. So my question is how can i return this as base64string:
 var doc = new Aspose.Words.Document(stream);
stream variable is the RTF file in stream memory stream format

@henrikJohansen You should simply save the document as PDF into a stream and get base64 string from the resulting stream. For example see the following code:

byte[] rtfBytes = File.ReadAllBytes(@"C:\Temp\in.rtf");

// Create a document from RTF bytes.
using (MemoryStream rtfStream = new MemoryStream(rtfBytes))
{
Document doc = new Document(rtfStream);

// Save the document as PDF into a stream.
using (MemoryStream pdfStream = new MemoryStream())
{
doc.Save(pdfStream, SaveFormat.Pdf);

// Get base64 string from the resulting stream.
string pdfBase64String = Convert.ToBase64String(pdfStream.ToArray());
Console.WriteLine(pdfBase64String);

// Convert base64 string back to byte array and save to file. (just for demonstration purposes)
byte[] pdfBytes = Convert.FromBase64String(pdfBase64String);
File.WriteAllBytes(@"C:\Temp\out.pdf", pdfBytes);
}
}

1 Like