如何使用telerik控件在c#中将docx转换并保存为pdf
您好,我正在尝试在C#中转换DOCX到PDF转换,仅使用telerik控件,而不使用任何其他第三方程序集或introp 我在stack overflow中发现了类似的问题,但没有得到正确的答案意味着无法继续使用这些方法如何使用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(
提前谢谢 请试试这个。你可以从中得到一些帮助
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”添加到引用中后,可以添加该命名空间。终于解决方案开始工作了。非常感谢您的帮助:)