我有一种情况,我需要将Doc文件转换为PDF文件。我正在vb.net中开发Windows应用程序。如果可能的话,我也不想使用第三方dll。 所以任何人都可以给我一些更多的想法?将Doc文件转换为VB.Net中的PDF
0
A
回答
2
您可以使用Office互操作这一点。但最好是使用一些托管库一样的Aspose
using Microsoft.Office.Interop.Word;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
...
// Create a new Microsoft Word application object
Microsoft.Office.Interop.Word.Application word = new Microsoft.Office.Interop.Word.Application();
// C# doesn't have optional arguments so we'll need a dummy value
object oMissing = System.Reflection.Missing.Value;
// Get list of Word files in specified directory
DirectoryInfo dirInfo = new DirectoryInfo(@"\\server\folder");
FileInfo[] wordFiles = dirInfo.GetFiles("*.doc");
word.Visible = false;
word.ScreenUpdating = false;
foreach (FileInfo wordFile in wordFiles)
{
// Cast as Object for word Open method
Object filename = (Object)wordFile.FullName;
// Use the dummy value as a placeholder for optional arguments
Document doc = word.Documents.Open(ref filename, ref oMissing,
ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing,
ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing,
ref oMissing, ref oMissing, ref oMissing, ref oMissing);
doc.Activate();
object outputFileName = wordFile.FullName.Replace(".doc", ".pdf");
object fileFormat = WdSaveFormat.wdFormatPDF;
// Save document into PDF Format
doc.SaveAs(ref outputFileName,
ref fileFormat, ref oMissing, ref oMissing,
ref oMissing, ref oMissing, ref oMissing, ref oMissing,
ref oMissing, ref oMissing, ref oMissing, ref oMissing,
ref oMissing, ref oMissing, ref oMissing, ref oMissing);
// Close the Word document, but leave the Word application open.
// doc has to be cast to type _Document so that it will find the
// correct Close method.
object saveChanges = WdSaveOptions.wdDoNotSaveChanges;
((_Document)doc).Close(ref saveChanges, ref oMissing, ref oMissing);
doc = null;
}
// word has to be cast to type _Application so that it will find
// the correct Quit method.
((_Application)word).Quit(ref oMissing, ref oMissing, ref oMissing);
word = null;
+0
其很棒。但我不想使用第三方DLL。还有什么其他的办法吗?如果我使用Microsoft.Office.Interop.Word然后我需要在每个电脑上安装我需要安装我的exe的办公室。所以它不可能在PC上。 – 2012-03-19 13:44:49
0
2007 Microsoft Office Add-in:Microsoft另存为PDF和2007 Microsoft Office Add-in:Microsoft另存为XPS允许Microsoft Office Word 2007以PDF和XPS格式导出和保存文档。
检查这些:
Saving Word 2007 Documents to PDF and XPS Formats
How to convert Word to PDF in asp.net
如果你想使用Thirt党的dll然后检查这个SO螺纹:Converting MS Word Documents to PDF in ASP.NET
1
Imports Microsoft.Office.Interop
'This code happens to be loading a template, but it isn't necessary...
'Opens Word Application
Dim MyApp As New Word.Application
'Opens new WordDoc
Dim MyWordDoc As Word.Document = MyApp.Documents.Add(template)
MyApp.Visible = True
MyWordDoc = MyApp.ActiveDocument
'code to fill doc
'code to fill doc
'code to fill doc
MyWordDoc.SaveAs(FileLocation, Word.WdSaveFormat.wdFormatPDF)
相关问题
- 1. 将doc文件转换为PDF
- 2. 将pdf转换为word doc文件
- 3. 将单个doc文件转换为pdf
- 4. 如何将PDF文件转换为java swing中的doc文件?
- 5. 在doc中将docx转换为pdf
- 6. 如何将pdf转换为java中的doc文件
- 7. 将doc文件转换为pdf中的iPhone
- 8. 将.doc格式转换为iphone中的pdf文件
- 9. 如何使用Perl将PDF文件转换为DOC文件?
- 10. 如何将.doc文件转换为.pdf文件在android
- 11. Apache POI HWPF - 将doc文件转换为pdf的问题
- 12. 将pdf,doc,ppt转换为html5
- 13. 将pdf转换为RTF或DOC
- 14. 将Markdown + CSS转换为.doc或.pdf
- 15. 如何将MS doc转换为pdf
- 16. 从命令行将DOC转换为PDF
- 17. 循环播放.doc文件,将它们转换为.pdf(Python)
- 18. 我需要将DOC/TXT文件大批量转换为PDF
- 19. 如何使用Cocoa将pdf和doc文件转换为html
- 20. 将多个文件从.doc转换为.pdf
- 21. 如何使用Matlab将.doc文件转换为PDF?
- 22. 将RTF文件转换为DOC
- 23. 将.jar文件转换为JAVA DOC
- 24. 如何把.doc或.docx文件转换为.pdf文件?
- 25. 将.doc和.txt格式的文件转换为.aspnet的pdf文件?
- 26. 将文档文件转换为pdf后关闭一个doc文件
- 27. 将html文件转换为PDF文件?
- 28. 将.jrxml文件转换为.pdf文件
- 29. 将pdf,doc,docx,xls等转换为.NET中的rtf
- 30. 将PDF,Doc和Docx转换为c#中的rtf
那么,哪些解决方案已经通过了你实现这一点,无论是的下方或其他有所一个? – 2012-08-01 10:02:24
我正在使用第二个来自以下答案。我正在使用Microsoft.Office.Interop.Word。 – 2012-08-01 13:14:41