0

我正在尝试使用我的 .Net Core 3.1 应用程序中的以下代码将 word 文档文件转换为 PDF 文件。

private static void CovertIntoPdf(string documentPath, string path)

        {

            FileStream docStream = new FileStream(documentPath, FileMode.Open, FileAccess.Read);

            WordDocument document = new WordDocument(docStream, Syncfusion.DocIO.FormatType.Automatic);



            DocIORenderer render = new DocIORenderer();

            render.Settings.ChartRenderingOptions.ImageFormat = ExportImageFormat.Jpeg;



            Console.WriteLine("Started " + DateTime.Now.ToString("yyyy.MM.dd HH:mm:ss:ffff"));



            PdfDocument pdfDocument = render.ConvertToPDF(document);



            Console.WriteLine("Ended " + DateTime.Now.ToString("yyyy.MM.dd HH:mm:ss:ffff"));



            render.Dispose();

            document.Dispose();



            FileStream stream = new FileStream(path, FileMode.Create, FileAccess.ReadWrite);

            var encodedData = ConvertPdfStreamToBase64(pdfDocument);

            pdfDocument.Save(stream);

            pdfDocument.Close();

        }

这种特殊方法需要将近 15 秒来处理文件。

PdfDocument pdfDocument = render.ConvertToPDF(document);​

文件大小仅为 195KB。为此,它影响了我的应用程序的性能。

我正在关注此链接https://help.syncfusion.com/file-formats/pdf/working-with-document-conversions?cs-save-lang=1&cs-lang=asp.net%20core

您能否提供一些其他替代方法来将 Docx 文件转换为 PDF 格式?

先感谢您。

4

0 回答 0