【问题标题】:How to convert and save a docx to pdf in c# using telerik controls如何使用 Telerik 控件在 C# 中将 docx 转换并保存为 pdf
【发布时间】:2018-08-27 22:16:00
【问题描述】:

您好,我正在尝试将 DOCX 转换为 C# 中的 PDF 转换,仅使用 Telerik 控件而不是任何其他第三方程序集或 introp。

我在堆栈溢出中发现了类似的问题,但没有得到正确答案意味着无法继续使用这些方法。

提前致谢。

【问题讨论】:

    标签: c# pdf telerik docx file-conversion


    【解决方案1】:

    请试试这个。你可以从中得到一些帮助。

    RadDocument document = null;
    IDocumentFormatProvider providerDocx = (IDocumentFormatProvider) new DocxFormatProvider();
    using (FileStream stream = File.Open(@"C:\Test.docx", FileMode.Open))
    {
        document = providerDocx.Import(stream);
    
        var providerPdf = new PdfFormatProvider();
    
        Stream outStream = new MemoryStream();
        providerPdf.Export(document, outStream);
    
        //Test the conversion:
        var fileStream = File.Create("PdfTest.pdf");
        outStream.Seek(0, SeekOrigin.Begin);
        outStream.CopyTo(fileStream);
        fileStream.Close();
    }
    

    【讨论】:

    • 我在尝试添加代码的第二行时收到“找不到类型或命名空间名称“IDocumentFormatProvider”(您是否缺少 using 指令或程序集引用?)”。
    • 添加这个参考 Telerik.Windows.Documents.FormatProviders
    • DocxFormatProvider providerDocx = new DocxFormatProvider();
    • 无法导入命名空间“Telerik.Windows.Documents.Flow.FormatProviders.Pdf”,但能够导入“Telerik.Windows.Documents.Flow.FormatProviders.Docx”。不知道为什么?
    • 在将“Telerik.Windows.Documents.Flow.FormatProviders.Pdf.dll”添加到引用中后能够添加该命名空间。最后解决方案现在正在运行。非常感谢您的帮助:)
    猜你喜欢
    • 2014-04-20
    • 2023-04-08
    • 2013-11-02
    • 2018-08-13
    • 2012-02-07
    • 2017-04-14
    • 2016-11-20
    • 1970-01-01
    • 2015-09-11
    相关资源
    最近更新 更多