【问题标题】:Converting a word doc to pdf using Syncfusion DocIO and saving to disk使用 Syncfusion DocIO 将 word doc 转换为 pdf 并保存到磁盘
【发布时间】:2018-12-20 04:58:01
【问题描述】:

我正在使用 Syncfusion DocIO 库尝试将 word doc 转换为 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 并将其保存到磁盘?我相信这个例子只是把它保存到内存中。

【问题讨论】:

    标签: c# asp.net-core asp.net-core-mvc syncfusion


    【解决方案1】:

    您可以使用FileStream 将文件写入磁盘:

    using (var fs = new FileStream(fileName, FileMode.Create, FileAccess.Write))
    {
        pdfDocument.Save(fs);
    }
    

    如果您不想使用,则无需使用 MemoryStream。您可以直接写信给FileStream

    【讨论】:

    • 如果使用 word doc 作为源并且输出应该是 pdf。有没有办法从直接将源上传到流然后使用流将输出仅保存到磁盘?每当我使用 (var stream = new FileStream(filePath, FileMode.Create)) 时,它都会在磁盘上创建文件,然后我可以在 using 中使用蒸汽。有没有办法不用在磁盘上创建文件?
    • Syncfusion documentation 中的示例展示了如何从流中加载 Word 文档
    【解决方案2】:

    是的,可以将 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 文档。请参阅以下链接以获取代码示例。 https://help.syncfusion.com/file-formats/docio/word-to-pdf?cs-save-lang=1&cs-lang=asp.net%20core

    注意:我为 Syncfusion 工作。

    问候, 迪利巴布。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-05-17
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多