2013-06-24 123 views
0

我需要以編程方式將Microsoft Word 2010文檔保存爲使用.net(最好是VB)的TIFF圖像。要通過Word 2010手動執行此操作,請單擊「打印」,選擇「傳真」作爲打印機,然後選擇「打印到文件」。在此之後,我點擊「打印」,顯示「另存爲」對話框,並將文件類型設置爲「所有文件」,然後輸入擴展名爲「tiff」的文件名。這樣做會將Word文檔保存爲TIFF。有人可以幫助我通過VB.net做到這一點嗎?任何幫助將不勝感激。.net將docx文件轉換爲tiff

回答

0

您可以通過使用Microsoft Windows提供的標準「傳真」驅動程序以編程方式將Word文檔轉換爲TIFF。此工作的關鍵是確保OutputFileName具有「.tiff」的擴展名以下是示例代碼(VB.net & Word 2010):

Dim objWdDoc As Word.Document 
Dim objWord As Word.Application 
Dim sDesktop As String = _ 
    Environment.GetEnvironmentVariable("userprofile") & "\Desktop\" 

objWord = CreateObject("Word.Application") 
objWdDoc = objWord.Documents.Open(sDesktop & "testdocument.doc") 
objWord.Visible = True 

'Select Printer 
objWord.ActivePrinter = "Fax" 
'Print to Tiff 
objWdDoc.PrintOut(Range:=WdPrintOutRange.wdPrintAllDocument, _ 
         OutputFileName:=sDesktop & "test.tiff", _ 
         Item:=WdPrintOutItem.wdPrintDocumentContent, _ 
         PrintToFile:=True) 
'Close Document 
objWdDoc.Close() 
'Close Word 
objWord.Quit() 
'General Cleanup 
objWdDoc = Nothing 
objWord = Nothing