DocファイルをPDFファイルに変換する必要がある状況があります。私はvb.netでWindowsアプリケーションを開発しています。また、可能であればサードパーティのdllを使用したくありません。だから誰かが私にもう少しアイデアを与えることができますか?
22748 次
4 に答える
2
これにはOfficeInteropを使用できます。ただし、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;
于 2012-03-19T13:27:32.700 に答える
1
2007 Microsoft Office アドイン: Microsoft Save as PDF および2007 Microsoft Office Add-in : Microsoft Save as XPS を使用すると、Microsoft Office Word 2007 でドキュメントを PDF および XPS 形式でエクスポートおよび保存できます。
Word 2007 ドキュメントを PDF および XPS 形式に保存するasp.net
で Word を PDF に変換する方法
サード パーティの dll を使用する場合は、この SO スレッドを確認してください: Converting MS Word Documents to PDF in ASP.NET
于 2012-03-19T13:24:44.173 に答える