Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/264.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何使用telerik控件在c#中将docx转换并保存为pdf_C#_Pdf_Telerik_Docx_File Conversion - Fatal编程技术网

如何使用telerik控件在c#中将docx转换并保存为pdf

如何使用telerik控件在c#中将docx转换并保存为pdf,c#,pdf,telerik,docx,file-conversion,C#,Pdf,Telerik,Docx,File Conversion,您好,我正在尝试在C#中转换DOCX到PDF转换,仅使用telerik控件,而不使用任何其他第三方程序集或introp 我在stack overflow中发现了类似的问题,但没有得到正确的答案意味着无法继续使用这些方法 提前谢谢 请试试这个。你可以从中得到一些帮助 RadDocument document = null; IDocumentFormatProvider providerDocx = (IDocumentFormatProvider) new DocxFormatProvider(

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

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


提前谢谢

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

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();
}

在尝试添加代码的第2行时,我得到“找不到类型或命名空间名称‘IDocumentFormatProvider’(是否缺少using指令或程序集引用?)。添加此引用Telerik.Windows.Documents.FormatProvidersDocxFormatProvider Provider providerDocx=new DocxFormatProvider();我无法导入命名空间“Telerik.Windows.Documents.Flow.FormatProviders.Pdf”,但可以导入“Telerik.Windows.Documents.Flow.FormatProviders.Docx”。不知道为什么?在将“Telerik.Windows.Documents.Flow.FormatProviders.Pdf.dll”添加到引用中后,可以添加该命名空间。终于解决方案开始工作了。非常感谢您的帮助:)