Comment imprimer un fichier html par un script vbs?

Résolu
Canibool Messages postés 4 Date d'inscription mardi 17 octobre 2006 Statut Membre Dernière intervention 31 août 2007 - 31 août 2007 à 14:50
Canibool Messages postés 4 Date d'inscription mardi 17 octobre 2006 Statut Membre Dernière intervention 31 août 2007 - 31 août 2007 à 17:06
bonjour,

je cherche un moyen d'imprimer une page html dans un .vbs.

le
contexte est le suivant: j'ai programme écrit dans un autre langage qui
génère des bons de commande en html. ce programme appelle un script
.vbs qui se charge d'imprimer cette page.

le script ne fait pas
seulement qu'imprimer (même si c'est là qu'est mon problème). il
configure un fax en imprimante par défaut, et des bidouilles de config
du fax... ah oui parcequ'en c'est pas vraiment une impression, c'est un
envoi de fax... mais il faut imprimer le document sur le fax pour qu'il
soit envoyé.

j'avais essayé de faire ça avec un .pdf au lieu du
html. c'est possible mais pour ça il faut acrobat payant (pour utiliser
acroexch, une dll).

donc j'ai toujours pas de solution avec html
car je n'ai pas trouvé de dll à invoquer pour imprimer (IE ou mozilla),
ni de fonction PRINT à utiliser par un objet quelconque.

alors si quelqu'un à une astuce je suis preneur.

je vous montre le script pour faciliter la tâche:
Dim strComputer
Dim strDefPrinter
Dim net
Dim iTemp
Dim sPrinter
Dim FaxNum
Dim hnd
Dim ret
Dim WshShell
dim oldDefPrinter
Dim DefPrinter
Dim oFso
Dim oFile

FaxNum = "6726"
strComputer = "."
strDefPrinter = ""

Set net = CreateObject("WScript.Network")
Set objWMIService = GetObject("winmgmts:" & "{impersonationLevel=impersonate}!\" & strComputer & "\root\cimv2")

Set colInstalledPrinters = objWMIService.ExecQuery ("Select * from Win32_Printer")

For Each objPrinter in colInstalledPrinters
    if instr(1,objPrinter.Name,"RICOH")<>0 then
        strDefPrinter = objPrinter.Name
    end if
Next

net.SetDefaultPrinter strDefPrinter

Set WshShell = WScript.CreateObject ("WScript.Shell")
hnd = WshShell.Run("%windir%\system32\RUNDLL32.EXE Ifxapi32.dll,IfxOpen " &amp; strDefPrinter,1,true)
Wscript.Echo hnd
ret = WshShell.Run("%windir%\system32\RUNDLL32.EXE Ifxapi32.dll,IfxSender " &amp; hnd &amp; " 1 " &amp; FaxNum,1,true)
Wscript.Echo ret
ret = WshShell.Run("%windir%\system32\RUNDLL32.EXE Ifxapi32.dll,IfxTTI " &amp; hnd &amp; " " &amp; IFX_TTI_ON,1,true)
Wscript.Echo ret
ret = WshShell.Run("%windir%\system32\RUNDLL32.EXE Ifxapi32.dll,IfxLock " &amp; hnd,1,true)
Wscript.Echo ret

Set oFso = CreateObject("Scripting.FileSystemObject")
Set oFile = oFso.GetFile("D:\opt\oracle\cde.htm")

--là il faudrait imprimer

ret = WshShell.Run("%windir%\system32\RUNDLL32.EXE Ifxapi32.dll,IfxUnlock " &amp; hnd,1,true)
Wscript.Echo ret
ret = WshShell.Run("%windir%\system32\RUNDLL32.EXE Ifxapi32.dll,IfxClose " &amp; hnd,1,true)
Wscript.Echo ret


merci d'avance

2 réponses

Canibool Messages postés 4 Date d'inscription mardi 17 octobre 2006 Statut Membre Dernière intervention 31 août 2007
31 août 2007 à 17:06
bonne idée! j'avais pas pensé, je vais essayer ça.

merci beaucoup.
3
cs_JMO Messages postés 1854 Date d'inscription jeudi 23 mai 2002 Statut Membre Dernière intervention 24 juin 2018 27
31 août 2007 à 15:34
 Bonjour à tous,

Personnellement, je passe par Word !

'Call fnImprimerDoc("d:\test.txt")
Call fnImprimerDoc("D:\Cours6.html")

Function fnImprimerDoc(MyDoc)
strComputer = "."
Set objWMIService = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate}!\" & strComputer & "\root\cimv2")

Set colInstalledPrinters = objWMIService.ExecQuery _
("Select * from Win32_Printer")

If colInstalledPrinters.Count <> 0 Then
   For Each objPrinter in colInstalledPrinters
       If Left(objPrinter.DeviceID,9) <> "Microsoft" Then
          'WScript.Echo "Name: " & objPrinter.Name &vbCr&_
          '             "Default: " & objPrinter.Default &vbCr&_
          '             "Port: " & objPrinter.PortName &vbCr&_
          '             "Imprimante Reseau: " & objPrinter.Network

'ICI il faut rajouter un "Select Case" des imprimantes réseaux

          Dim objFso, objWordApp, objWordDoc
          Set objFso = CreateObject("Scripting.FileSystemObject")
          If objFso.FileExists(MyDoc) Then
             Set objWordApp = CreateObject("Word.Application")
             Set objWordDoc = objWordApp.documents.open(MyDoc)
             objWordApp.ActivePrinter=objPrinter.Name
             objWordDoc.PrintOut 0
             objWordDoc.Close
             objWordApp.Quit
             Set objWordApp = Nothing
             Set objWordDoc = Nothing
             MsgBox "coucou"
          End if
       Set objFso = Nothing
       End if
   Next
End If
Set objWMIService = Nothing
Set colInstalledPrinters = Nothing
End Function

jean-marc
0
Rejoignez-nous