【发布时间】:2011-07-20 07:24:31
【问题描述】:
我想从 Word 文档(.doc、.docx)或 excel 文档(.xls、.xlsx)生成 PDF 文件。 我尝试使用 ITextSharp,但我无法将 word 文档的图像/表格等渲染到 pdf 中。
【问题讨论】:
我想从 Word 文档(.doc、.docx)或 excel 文档(.xls、.xlsx)生成 PDF 文件。 我尝试使用 ITextSharp,但我无法将 word 文档的图像/表格等渲染到 pdf 中。
【问题讨论】:
这是example of opening the word file using interops in VS2010 C#
我在another website 上找到了这个,希望对您有所帮助。似乎是基于可用于办公室保存为 PDF 的插件。
“另存为 PDF”插件 对于 Office 2007,请查看此链接
http://news.com.com/Microsoft+delivers+Save+as+PDF+add-on/2100-1012_3-6114752.html
2007 Microsoft Office 插件: Microsoft 另存为 PDF - 下载链接
一旦你下载了这个插件,我想 您应该能够转换为 PDF 在 .NET 中使用 Word 对象。
否则,您有第三方 用 .net 编写的组件 那是给你的,但评价 版本会在 转换后的文件,检查以下 链接,如果您准备购买 然后你可以在你的 vb.net/c#.net 代码将文档转换为 pdf
http://www.aspose.com/Wiki/default.aspx/Aspose.Pdf/WordToPDF.html
【讨论】:
使用 Office Interop 在 Word/Excel 中打开文档,然后发布为 PDF(如果您有 2007)或使用 CutePDF Writer 或类似工具进行打印。
【讨论】:
您可以使用 Spire.Xls 和 Spire.Doc 来执行此操作。
这里是示例代码。
//xls to pdf
Workbook workbook = new Workbook();
workbook.LoadFromFile("sample.xlsx", ExcelVersion.Version2007);
PdfConverter pdfConverter = new PdfConverter(workbook);
PdfDocument pdfDocument = new PdfDocument();
pdfDocument.PageSettings.Orientation = PdfPageOrientation.Landscape;
pdfDocument.PageSettings.Width = 970;
pdfDocument.PageSettings.Height = 850;
PdfConverterSettings settings = new PdfConverterSettings();
settings.TemplateDocument = pdfDocument;
pdfDocument = pdfConverter.Convert(settings);
pdfDocument.SaveToFile("test.pdf");
//doc to pdf
Document doc = new Document();
doc.LoadFromFile("sample.docx", FileFormat.Docx);
doc.SaveToFile("test.pdf", FileFormat.PDF);
【讨论】: