Reputation: 13875
I am using the Syncfusion DocIO library to try and convert a word doc to a pdf. I am following this simple example:
At the bottom of the example they are doing:
PdfDocument pdfDocument = render.ConvertToPDF(wordDocument);
//Releases all resources used by the Word document and DocIO Renderer objects
render.Dispose();
wordDocument.Dispose();
//Saves the PDF file
MemoryStream outputStream = new MemoryStream();
pdfDocument.Save(outputStream);
//Closes the instance of PDF document object
pdfDocument.Close();
I need to save the pdf file to the disk instead. How can I take the outputStream and save it to disk? I believe the example is just saving it to memory.
Upvotes: 2
Views: 1785
Reputation: 185
Yes, it is possible to save the PDF document to a disk which is illustrated in the following code. https://help.syncfusion.com/file-formats/pdf/loading-and-saving-document?cs-save-lang=1&cs-lang=asp.net%20core#saving-a-pdf-document-to-file-system
Meanwhile, Word document can also be opened from a disk as a FileStream and converted to PDF document. Kindly refer the following link for code example. https://help.syncfusion.com/file-formats/docio/word-to-pdf?cs-save-lang=1&cs-lang=asp.net%20core
Note: I work for Syncfusion.
Regards, Dilli babu.
Upvotes: 0
Reputation: 8642
You can use a FileStream
to write the file to disk:
using (var fs = new FileStream(fileName, FileMode.Create, FileAccess.Write))
{
pdfDocument.Save(fs);
}
You don't need to use the MemoryStream
if you don't want to. You can write directly to the FileStream
.
Upvotes: 1