如何将excel文件和word文件从.pdf格式转换成c#格式。我尝试了下面的代码,但它显示了一个错误
这是我的密码:
Microsoft.Office.Interop.Word.Application appWord = new Microsoft.Office.Interop.Word.Application();
wordDocument = appWord.Documents.Open(@"C:\Users\ITPro2\Documents\test.docx");
wordDocument.ExportAsFixedFormat(@"D:\desktop\DocTo.pdf", Microsoft.Office.Interop.Word.WdExportFormat.wdExportFormatPDF);我得到了以下错误
The export failed because this feature is not installed.从c#导出到pdf
发布于 2016-10-05 07:52:10
虽然与https://msdn.microsoft.com/en-us/library/office/ff198122.aspx下的文档没有直接关联
请注意,如果pdf外接程序未安装,则将发生此错误.因此,请检查您的先决条件,即Office安装和外接程序。
发布于 2016-10-05 07:43:45
1) Excel 2013主要互操作组装类库 --它在.NET 4.5.1下工作得很好--只需将Microsoft.Office.Interop.Excel程序集添加到引用中,您就可以开始了。
using System;
using Microsoft.Office.Interop.Excel;
namespace officeInterop
{
class Program
{
static void Main(string[] args)
{
Application app = new Application();
Workbook wkb = app.Workbooks.Open("d:\\x.xlsx");
wkb.ExportAsFixedFormat(XlFixedFormatType.xlTypePDF, "d:\\x.pdf");
}
}
}或者2)引用此链接将DOC或DOCx文件转换为
http://www.rasteredge.com/how-to/csharp-imaging/pdf-convert-word-to-pdf/
发布于 2021-10-22 07:13:05
由于我的另一个评论被删除,这是更新的版本。
为了将我的文件转换成c#中的pdf格式,我使用了变形libary,这也可能是您的解决方案。
下面是我的一个代码示例,其中我使用Below存储从常规文件下载PDF文件。
var converter = new SautinSoft.PdfMetamorphosis();
var ms = new MemoryStream();
await blob.DownloadToStreamAsync(ms);
ms.Seek(0, SeekOrigin.Begin);
var pdfStream = converter.DocxToPdfConvertStream(ms);
if (pdfStream != null)
{
await _storageProvider.SaveFileAsync(containerName, fileName, pdfStream);
}
ms.Close();
var result = await _storageProvider.GetFileWithAttributesAsync(containerName, fileName);
return new ServiceResponse<CloudBlockBlob>(result);下面我发布了一些与库本身的示例代码的链接:
https://stackoverflow.com/questions/39868010
复制相似问题