Free Support Forum - aspose.com

Convert Word byte array to PDF byte array

Hi,

I’m using Aspose.Words for .Net for converting Word document to PDF and it works fine.
But I wanted to know if it is possible to convert WORD document (Byte array) to PDF Document (Byte array).

At present, I’m passing word document byte stream to aspose.words and I’m saving the document to PDF.
For example,

byte[] buffer = “WORD DOCUMENT”;
Stream stream = new MemoryStream(buffer);
Document docHTML = new Document(stream);
string fileName = “file path”;
docHTML.Save(fileName, Aspose.Words.SaveFormat.Pdf);
byte[] readPDF = File.ReadAllBytes(fileName);

Then I send “readPDF” byte array to my front end.
I’m trying to avoid creating PDF file and generate PDF byte array from Word byte array.

Please let me know if that is possible.

Thank you,
Shiva

@naru.shiva,

Please try using the following code:

Document doc = new Document();

DocumentBuilder builder = new DocumentBuilder(doc);
builder.Writeln("Hello World");

MemoryStream stream = new MemoryStream();
doc.Save(stream, SaveFormat.Pdf);

byte[] pdfBytes = stream.ToArray();