简体   繁体   中英

.net convert docx file to tiff

I need to programmatically save Microsoft Word 2010 documents to TIFF images using .net (preferably VB). To do this manually through Word 2010, I click “Print”, select “Fax” as the printer, then select “Print to File”. After this I click “Print”, the “Save As” dialog box displays and set the file type to “All Files” and type a file name with an extension of “tiff”. Doing this will save the Word document as a TIFF. Could someone assist me with doing this through VB.net? Any help would be greatly appreciated.

You can convert a Word document to a TIFF programatically by utilizing the standard "Fax" driver that is supplied with Microsoft Windows. The key to this working is ensuring the OutputFileName has an extension of ".tiff" Here is the sample code (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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM