使用 Syncfusion DocIO 将 word 文档转换为 pdf 并保存到磁盘
Converting a word doc to pdf using Syncfusion DocIO and saving to disk
我正在使用 Syncfusion DocIO 库尝试将 word 文档转换为 pdf。
我正在关注这个 simple example:
在他们正在做的例子的底部:
PdfDocument pdfDocument = render.ConvertToPDF(wordDocument);
//释放Word文档和DocIO Renderer对象使用的所有资源
render.Dispose();
wordDocument.Dispose();
//Saves the PDF file
MemoryStream outputStream = new MemoryStream();
pdfDocument.Save(outputStream);
//Closes the instance of PDF document object
pdfDocument.Close();
我需要将 pdf 文件保存到磁盘。如何获取 outputStream 并将其保存到磁盘?我相信这个例子只是将它保存到内存中。
您可以使用 FileStream
将文件写入磁盘:
using (var fs = new FileStream(fileName, FileMode.Create, FileAccess.Write))
{
pdfDocument.Save(fs);
}
如果您不想,则不需要使用 MemoryStream
。你可以直接写到FileStream
.
是的,可以将 PDF 文档保存到磁盘,如下面的代码所示。
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
同时,Word文档也可以作为FileStream从磁盘打开并转换为PDF文档。请参考以下 link 代码示例。
https://help.syncfusion.com/file-formats/docio/word-to-pdf?cs-save-lang=1&cs-lang=asp.net%20core
注意:我为 Syncfusion 工作。
此致,
迪利巴布。
我正在使用 Syncfusion DocIO 库尝试将 word 文档转换为 pdf。 我正在关注这个 simple example:
在他们正在做的例子的底部:
PdfDocument pdfDocument = render.ConvertToPDF(wordDocument);
//释放Word文档和DocIO Renderer对象使用的所有资源
render.Dispose();
wordDocument.Dispose();
//Saves the PDF file
MemoryStream outputStream = new MemoryStream();
pdfDocument.Save(outputStream);
//Closes the instance of PDF document object
pdfDocument.Close();
我需要将 pdf 文件保存到磁盘。如何获取 outputStream 并将其保存到磁盘?我相信这个例子只是将它保存到内存中。
您可以使用 FileStream
将文件写入磁盘:
using (var fs = new FileStream(fileName, FileMode.Create, FileAccess.Write))
{
pdfDocument.Save(fs);
}
如果您不想,则不需要使用 MemoryStream
。你可以直接写到FileStream
.
是的,可以将 PDF 文档保存到磁盘,如下面的代码所示。 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
同时,Word文档也可以作为FileStream从磁盘打开并转换为PDF文档。请参考以下 link 代码示例。 https://help.syncfusion.com/file-formats/docio/word-to-pdf?cs-save-lang=1&cs-lang=asp.net%20core
注意:我为 Syncfusion 工作。
此致, 迪利巴布。