Imprimer un document Word ou RTF sans ouvrir Office ?

Vous débutez et vous avez besoin d'aide ? N'hésitez pas à poser vos questions
Avatar de l’utilisateur
Flype
Messages : 2431
Inscription : jeu. 29/janv./2004 0:26
Localisation : Nantes

Imprimer un document Word ou RTF sans ouvrir Office ?

Message par Flype »

J'ai besoin d'une commande, d'une fonction, d'une routine quelconque pour imprimer un document Word sur une imprimante locale ou distante sans ouvrir MS Office Word ou même Excel ou encore WordPad en RTF...
on reste d'accord sur le fait que Office est bien installé sur l'ordinateur hôte. si quequ'un a une idée...

Windows dispose d'une commande DOS 'Print' mais bon je sais pas l'utiliser...

J'ai vu aussi qu'on peut faire CopyFile('modele.doc','196.168.0.22') ou 196.168.0.22 serait l'adresse ip d'une imprimante réseau par ex.
mais pour le coup c pas d'une imprimante réseau avec ip que j'exploite.

enfin en gros c çà que je cherche...
Image
Anonyme2
Messages : 3518
Inscription : jeu. 22/janv./2004 14:31
Localisation : Sourans

Message par Anonyme2 »

Je ne sais pas, mais Word supporte-t-il des commandes en ligne et si oui une pour l'impression sans l' ouvrir ?

Faute de mieux :roll:
tme007
Messages : 57
Inscription : mar. 26/oct./2004 12:34

Message par tme007 »

Pour un fichier HTML, voici ce que j'utilise, si cela peut t'ouvrir une piste sur ce que tu cherches ....

rundll32.exe C:\WINDOWS\System\mshtml.dll,PrintHTML "%1"
Avatar de l’utilisateur
Flype
Messages : 2431
Inscription : jeu. 29/janv./2004 0:26
Localisation : Nantes

Message par Flype »

denis>
les parametres DOS de winword.exe - rien trouvé à ce sujet :cry:

tme007>
ouais je crois bien qu'il faut jouer non pas avec une DLL
mais avec les objets COM car Office est ainsi exploitable de " l'extérieur ".
en principe, il faut utiliser les interfaces de Purebasic.

je crois bien que Francois Weil et Fred ont déjà débroussaillé un peu le sujet il y a qq mois sur le forum anglais notamment grace à l'enorme travail de aXtend... mais franchement c inbuvable pourtant je sens que c çà qu'il faut faire... help
Dernière modification par Flype le jeu. 24/févr./2005 18:31, modifié 1 fois.
Image
Avatar de l’utilisateur
Flype
Messages : 2431
Inscription : jeu. 29/janv./2004 0:26
Localisation : Nantes

Message par Flype »

en fouillant j'ai vu que microsoft propose une solution alternative pour exploiter office autrement qu'au travers des objets COM.

pour les curieux...
http://support.microsoft.com/default.as ... -us;190057

ceux qui viennent de l'AmigaOS se souviennent forcement de ARexx... hmffff, c'etait bien quand meme. :roll:
Image
Fred
Site Admin
Messages : 2809
Inscription : mer. 21/janv./2004 11:03

Message par Fred »

Si tu n'as que du RTF, tu peux tricher en utilisant le control RichEdit (EditorGadget()) qui a une fonction d'impression.
Avatar de l’utilisateur
djes
Messages : 4252
Inscription : ven. 11/févr./2005 17:34
Localisation : Arras, France

Message par djes »

Il est peut-être aussi possible de passer par le controle webgadget qui permet d'intégrer internet explorer à une fenêtre. Comme les documents word s'ouvrent nativement dans celui-ci, peut-être qu'en passant par l'interface on peut demander une impression ( WebObject.IWebBrowser2 = GetWindowLong_(GadgetID(#WEBGADGET), #GWL_USERDATA)
).

Je crois aussi qu'il existe des bibliothèques gratuites pour lire les .doc, un peu comme le pdf, en moins compatible.

Sinon, j'ai trouvé ce petit site qui est mine sur word : http://www.kayodeok.btinternet.co.uk/fa ... bhowtoauto
Avatar de l’utilisateur
Flype
Messages : 2431
Inscription : jeu. 29/janv./2004 0:26
Localisation : Nantes

Message par Flype »

Fred a écrit :Si tu n'as que du RTF, tu peux tricher en utilisant le control RichEdit (EditorGadget()) qui a une fonction d'impression.
yep c'est sans doute le plus raisonnable...
et en ce qui me concerne le rtf est suffisant pour mon cas.
mais comment on fait pour faire une sortie imprimante d'un texte formaté depuis un RichEdit... as-tu un exemple...

( le but est d'imprimer à la volée des étiquettes autocollantes 52mm x 37mm avec nom de produit + code barre via une police dédiée )
Image
gansta93
Messages : 1448
Inscription : jeu. 26/févr./2004 11:17
Localisation : Le Village
Contact :

Message par gansta93 »

Dans les associations de fichiers, pour les fichier word, on a la commande suivante.

Code : Tout sélectionner

winword.exe /p %1
Donc avec un RunProgram() je pense que ça peut se faire.
Avatar de l’utilisateur
Flype
Messages : 2431
Inscription : jeu. 29/janv./2004 0:26
Localisation : Nantes

Message par Flype »

merci gansta c coool
ca marche avec winword.exe, et meme avec wordpad.exe de la meme maniere. ADOPTE !

par contre je reste interessé pour savoir imprimer un texte formaté depuis un EditorGadget :)
Image
Avatar de l’utilisateur
Flype
Messages : 2431
Inscription : jeu. 29/janv./2004 0:26
Localisation : Nantes

Message par Flype »

concernant l'impression depuis un EditorGadget, en cherchant un peu j'ai trouvé qqchose sur le forum anglais.
je l'ai adapté un peu... est-ce que çà marche bien chez vous ?

perso pour mes tests j'utilise l'imprimante virtuelle d'office, sinon j'ai pas finit de bouffer du papier.

Code : Tout sélectionner

;/
;/

Structure textlength 
  flags.w 
  CodePage.b 
EndStructure

Structure DInfo1 
  cbSize.l 
  lpszDocName.l 
  lpszOutput.l 
  lpszDataType.l 
  fwType.w 
EndStructure 

;/
;/

Procedure RichEditPrint(Gadget.l,document.s,setup.b) 
  
  lppd.PRINTDLGAPI
  lppd\lStructSize = SizeOf(PRINTDLGAPI) 
  lppd\flags = #PD_ALLPAGES|#PD_HIDEPRINTTOFILE|#PD_NOSELECTION|#PD_RETURNDC|#PD_PRINTSETUP
  
  If setup = 0
    lppd\flags | #PD_RETURNDEFAULT
  EndIf
  
  If PrintDlg_(lppd) = 0
    ProcedureReturn
  EndIf
  
  If lppd\hdc = -1
    ProcedureReturn
  EndIf
  
  *Pointer.DEVMODE = GlobalLock_(lppd\hDevMode) 
  paperlength      = *Pointer\dmPaperLength 
  paperwidth       = *Pointer\dmPaperWidth 
  ppmm.f           = (*Pointer\dmYResolution/10)/2.54
  GlobalFree_(lppd\hDevMode) 
  
  Docinfo.DInfo1 
  Docinfo\cbSize      = SizeOf(DInfo1) 
  Docinfo\lpszDocName = @document.s 
  
  Result = StartDoc_(lppd\hdc,Docinfo) 
  
  leftmargin   = 1
  rightmargin  = 1
  topmargin    = 1
  bottommargin = 1
  
  long.textlength 
  long\flags   = 0 
  MaxLen       = SendMessage_(GadgetID(Gadget),#EM_GETTEXTLENGTHEX,@long,0) 
  OldMapMode   = GetMapMode_(lppd\hdc) 
  SetMapMode_(lppd\hdc,#MM_TWIPS) 
  
  OffsetX = leftmargin*ppmm.f-GetDeviceCaps_(lppd\hdc,#PHYSICALOFFSETX) 
  If OffsetX < GetDeviceCaps_(lppd\hdc,#PHYSICALOFFSETX)
    OffsetX = GetDeviceCaps_(lppd\hdc,#PHYSICALOFFSETX)
  EndIf
  
  OffsetY=-topmargin*ppmm.f+GetDeviceCaps_(lppd\hdc,#PHYSICALOFFSETY) 
  If OffsetY > -GetDeviceCaps_(lppd\hdc,#PHYSICALOFFSETY)
    OffsetY = -GetDeviceCaps_(lppd\hdc,#PHYSICALOFFSETY)
  EndIf
  
  HorzRes=((paperwidth/10-rightmargin))*ppmm.f 
  If HorzRes > GetDeviceCaps_(lppd\hdc,#HORZRES)
    HorzRes = GetDeviceCaps_(lppd\hdc,#HORZRES)
  EndIf
  
  VertRes=-(paperlength/10)*ppmm.f+bottommargin*ppmm.f 
  If VertRes < -GetDeviceCaps_(lppd\hdc,#VERTRES)
    VertRes = -GetDeviceCaps_(lppd\hdc,#VERTRES)
  EndIf
  
  cRect.RECT 
  SetRect_(cRect,OffsetX,OffsetY,HorzRes,VertRes) 
  DPtoLP_(lppd\hdc,cRect,2) 
  SetMapMode_(lppd\hdc,OldMapMode)
  
  FormatRange.FORMATRANGE 
  FormatRange\hdc           = lppd\hdc 
  FormatRange\hdcTarget     = lppd\hdc 
  FormatRange\rc\left       = cRect\left 
  FormatRange\rc\top        = cRect\top 
  FormatRange\rc\right      = cRect\right 
  FormatRange\rc\bottom     = cRect\bottom 
  FormatRange\rcPage\left   = cRect\left 
  FormatRange\rcPage\top    = cRect\top 
  FormatRange\rcPage\right  = cRect\right 
  FormatRange\rcPage\bottom = cRect\bottom 
  
  Repeat 
    Result=StartPage_(lppd\hdc) 
    FormatRange\chrg\cpMax = -1 
    LastChar = SendMessage_(GadgetID(Gadget),#EM_FORMATRANGE,#True,@FormatRange) 
    FormatRange\chrg\cpMin = LastChar 
    SendMessage_(GadgetID(Gadget),#EM_DISPLAYBAND,0,cRect) 
    EndPage_(lppd\hdc) 
  Until LastChar >= MaxLen Or LastChar < 0 
  
  EndDoc_(lppd\hdc) 
  
  SendMessage_(GadgetID(Gadget),#EM_FORMATRANGE,0,0) 
  
EndProcedure  

;/
;/

pw=52
ph=37
ww=pw*4+20
wh=ph*4+50

If OpenWindow(0,0,0,ww,wh,#PB_Window_SystemMenu|#PB_Window_ScreenCentered,"Etiquette ( 52mm x 37mm )")=0:End:EndIf
If CreateGadgetList(WindowID())=0:End:EndIf

hBrush=CreateSolidBrush_($80D0D0)
SetClassLong_(WindowID(),#GCL_HBRBACKGROUND,hBrush)

EditorGadget(0,10,10,pw*4,ph*4)
ButtonGadget(1,10,wh-30,80,22,"Configuration")
ButtonGadget(2,ww-90,wh-30,80,22,"Imprimer")

titre$ = "PRODUCT NAME"
sn$    = "3034218678"
pn$    = "A0830TXB006A"

Texte$ = "{\rtf1{\fonttbl{\f0\fswiss\fcharset0 Arial;}{\f1\fdecor\fprq2\fcharset0 Arial;}}\viewkind4\uc1\pard\qc\f0\fs16\par\fs16 %titre%\par\fs16\par\f1\fs28 %sn%\f0\fs20\par\fs24 %sn%\par\fs16\par\f1\fs28 %pn%\f0\fs20\par\fs24 %pn%}"

Texte$ = ReplaceString(Texte$,"%titre%",titre$)
Texte$ = ReplaceString(Texte$,"%sn%",sn$)
Texte$ = ReplaceString(Texte$,"%pn%",pn$)

SetGadgetText(0,Texte$)

;/
;/

Repeat
  Select WaitWindowEvent()
    Case #PB_Event_CloseWindow : Break
    Case #PB_Event_Gadget
      Select EventGadgetID()
        Case 1 : RichEditPrint(0,"richedit_temp",#True)
        Case 2 : RichEditPrint(0,"richedit_temp",#False)
      EndSelect
  EndSelect
ForEver
Image
Avatar de l’utilisateur
Kwai chang caine
Messages : 6989
Inscription : sam. 23/sept./2006 18:32
Localisation : Isere

Message par Kwai chang caine »

Bonjour Flype

J'ai éssayé ton code, deux ans apres :roll:
En v3.94 et 4.0, j'ai la meme erreur :

Structure no found : PrinTDLGAPI :cry:
gnozal
Messages : 832
Inscription : mar. 07/déc./2004 17:35
Localisation : France
Contact :

Message par gnozal »

Plusieurs autres façons d'imprimer un doc,xls,... :

1 ShellExecute_(0, "print", "mondocument.doc", #Null, "", #SW_HIDE)

2 Autre façon simple : charger le document dans un WebGadget (qui peut être caché) et faire imprimer le WebGadget avec WebObject\ExecWB(#OLECMDID_PRINT, #OLECMDEXECOPT_DONTPROMPTUSER, 0, 0)
Exemples :
http://www.purebasic.fr/english/viewtopic.php?t=13792
http://www.purebasic.fr/english/viewtopic.php?t=18297
Avatar de l’utilisateur
Kwai chang caine
Messages : 6989
Inscription : sam. 23/sept./2006 18:32
Localisation : Isere

Message par Kwai chang caine »

Merci beaucoup GNOZAL de ton aide

Y'a une chose que j'ai pas comprise (Etonnant non ? :D )

Code : Tout sélectionner

#Web_IE = 0

Procedure.s GetKeyString(HKEY_Folder.l, key.s, Subkey.s) 
  Protected OpenKey.l, Type.l, cbData.l, *lpbData, ReturnValue.s 
  cbData = (#MAX_PATH * 2) + 2 
  *lpbData = AllocateMemory(cbData) 
  If RegOpenKeyEx_(HKEY_Folder, key, 0, #KEY_ALL_ACCESS, @OpenKey) = #ERROR_SUCCESS 
    If RegQueryValueEx_(OpenKey, Subkey, 0, @Type, *lpbData, @cbData) = #ERROR_SUCCESS 
      If Type = #REG_SZ 
        ReturnValue = PeekS(*lpbData) 
      EndIf 
    EndIf 
    RegCloseKey_(OpenKey) 
  EndIf 
  FreeMemory(*lpbData) 
  ProcedureReturn ReturnValue 
EndProcedure 

Procedure.l SetKeyString(HKEY_Folder.l, key.s, Subkey.s, Value.s) 
  Protected OpenKey.l, ReturnValue.l 
  If RegOpenKeyEx_(HKEY_Folder, key, 0, #KEY_ALL_ACCESS, @OpenKey) = #ERROR_SUCCESS 
    If RegSetValueEx_(OpenKey, Subkey, 0, #REG_SZ, @Value, Len(Value) + 1) = #ERROR_SUCCESS 
      ReturnValue = #True 
    EndIf 
    RegCloseKey_(OpenKey) 
  EndIf 
  ProcedureReturn ReturnValue 
EndProcedure

; Allows to change the header and footer (you must restore the originals) 
Procedure ModifyIEHeaderFooter(State.l) ; #TRUE : modify , #FALSE : reverse to original 
  Static FirstTime.l, IEHeader.s, IEFooter.s, IELeft.s, IERight.s, IEBottom.s 
  If FirstTime = 0 
    IEHeader = GetKeyString(#HKEY_CURRENT_USER, "Software\Microsoft\Internet Explorer\PageSetup", "header") ; default : "&w&bPage &p de &P" 
    IEFooter = GetKeyString(#HKEY_CURRENT_USER, "Software\Microsoft\Internet Explorer\PageSetup", "footer") ; default : "&u&b&d" 
    IELeft = GetKeyString(#HKEY_CURRENT_USER, "Software\Microsoft\Internet Explorer\PageSetup", "margin_left") ; default : "0.750000" 
    IERight = GetKeyString(#HKEY_CURRENT_USER, "Software\Microsoft\Internet Explorer\PageSetup", "margin_right") ; default : "0.750000" 
    IEBottom = GetKeyString(#HKEY_CURRENT_USER, "Software\Microsoft\Internet Explorer\PageSetup", "margin_bottom") ; default : "0.750000" 
    FirstTime = 1 
  EndIf 
  If State = #True 
    SetKeyString(#HKEY_CURRENT_USER, "Software\Microsoft\Internet Explorer\PageSetup", "header", "AQ-Viewer [Consultation de documents]&b&d") 
    SetKeyString(#HKEY_CURRENT_USER, "Software\Microsoft\Internet Explorer\PageSetup", "footer", "&bPage &p/&P") 
    SetKeyString(#HKEY_CURRENT_USER, "Software\Microsoft\Internet Explorer\PageSetup", "margin_left", "0.400000") 
    SetKeyString(#HKEY_CURRENT_USER, "Software\Microsoft\Internet Explorer\PageSetup", "margin_right", "0.400000") 
    SetKeyString(#HKEY_CURRENT_USER, "Software\Microsoft\Internet Explorer\PageSetup", "margin_bottom", "0.500000") 
  Else 
    SetKeyString(#HKEY_CURRENT_USER, "Software\Microsoft\Internet Explorer\PageSetup", "header", IEHeader) 
    SetKeyString(#HKEY_CURRENT_USER, "Software\Microsoft\Internet Explorer\PageSetup", "footer", IEFooter) 
    SetKeyString(#HKEY_CURRENT_USER, "Software\Microsoft\Internet Explorer\PageSetup", "margin_left", IELeft) 
    SetKeyString(#HKEY_CURRENT_USER, "Software\Microsoft\Internet Explorer\PageSetup", "margin_right", IERight) 
    SetKeyString(#HKEY_CURRENT_USER, "Software\Microsoft\Internet Explorer\PageSetup", "margin_bottom", IEBottom) 
  EndIf 
EndProcedure 
; Set URL 
Procedure WebAfficheURL(Url.s) 
  WebObject.IWebBrowser2 = GetWindowLong_(GadgetID(#Web_IE), #GWL_USERDATA) 
  SetGadgetText(#Web_IE, Url) 
  While WindowEvent() : Wend 
EndProcedure 
 
; PRINTING HTML FILES (WebGadget #Web_IE may be hidden) 
; 
  WebObject.IWebBrowser2 = GetWindowLong_(GadgetID(#Web_IE), #GWL_USERDATA) 
 ; Print many HTML files (filenames in FichiersHTML())  
  ForEach FichiersHTML() 
   WebAfficheURL(FichiersHTML()) 
   ModifyIEHeaderFooter(#True) 
   WebObject\ExecWB(#OLECMDID_PRINT, #OLECMDEXECOPT_DONTPROMPTUSER, 0, 0) 
   ModifyIEHeaderFooter(#False) 
  Next
; Print many HTML files (filenames in FichiersHTML())
FichiersHTML() n'est pas une variable ???
Ou doit je mettre mon fichier HTML??
gnozal
Messages : 832
Inscription : mar. 07/déc./2004 17:35
Localisation : France
Contact :

Message par gnozal »

Kwai chang caine a écrit :FichiersHTML() n'est pas une variable ???
Ou doit je mettre mon fichier HTML??
C'est juste un exemple.
Dans ce cas FichiersHTML() est une linked list (de type string) avec des noms de fichiers comme par exemple "c:\MonChemin\MonFichier.html"
Répondre