我有一種情況,我需要將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. 將pdf轉換爲word doc文件
- 2. 將doc文件轉換爲PDF
- 3. 將單個doc文件轉換爲pdf
- 4. 如何將PDF文件轉換爲java swing中的doc文件?
- 5. 如何將pdf文件轉換爲android中的doc文件?
- 6. 在doc中將docx轉換爲pdf
- 7. 將doc文件轉換爲pdf中的iPhone
- 8. 將.doc格式轉換爲iphone中的pdf文件
- 9. 如何將pdf轉換爲java中的doc文件
- 10. 如何將.doc文件轉換爲.pdf文件在android
- 11. 如何使用Perl將PDF文件轉換爲DOC文件?
- 12. Apache POI HWPF - 將doc文件轉換爲pdf的問題
- 13. 從命令行將DOC轉換爲PDF
- 14. 將pdf,doc,ppt轉換爲html5
- 15. 將Markdown + CSS轉換爲.doc或.pdf
- 16. 將HTML轉換爲doc(x)和/或PDF
- 17. 如何將MS doc轉換爲pdf
- 18. 將pdf轉換爲RTF或DOC
- 19. 如何將PDF文件轉換爲使用vb.net的word文件
- 20. 循環播放.doc文件,將它們轉換爲.pdf(Python)
- 21. 將多個文件從.doc轉換爲.pdf
- 22. 使用PHP將Doc/Docx文件轉換爲PDF
- 23. 我需要將DOC/TXT文件大批量轉換爲PDF
- 24. 如何使用Cocoa將pdf和doc文件轉換爲html
- 25. 工具操作doc文件,並將它們轉換爲PDF
- 26. 將解決方案轉換爲pdf或doc文件
- 27. 如何使用Matlab將.doc文件轉換爲PDF?
- 28. 將文本文件轉換爲PDF轉換代碼將文本截斷vb.net
- 29. 用Doc將Doc文件轉換成Docx?
- 30. 將RTF文件轉換爲DOC
那麼,哪些解決方案已經通過了你實現這一點,無論是的下方或其他有所一個? – 2012-08-01 10:02:24
我正在使用第二個來自以下答案。我正在使用Microsoft.Office.Interop.Word。 – 2012-08-01 13:14:41