Bonjour à toute l'équipe
J'ai développé un petit programme qui doit imprimer un document sous la forme paysage. Pour l'instant, c'est l'utilisateur qui doit côcher l'option paysage dans la boite de dialogue de l'imprimante. Ce que je souhaite, c'est : imprimer (par défaut) sous la forme paysage sans obliger l'utilisateur à utiliser la boite de dialogue pour choisir cette option.
Merci
Imprimer (forme paysage)
Imprimer (forme paysage)
Win7 (x64) 64 bits Pb 5.72
- falsam
- Messages : 7324
- Inscription : dim. 22/août/2010 15:24
- Localisation : IDF (Yvelines)
- Contact :
Re: Imprimer (forme paysage)
Bonjour Omega. Le document est il généré avec Pure Basic ?
Configuration : Windows 11 Famille 64-bit - PB 6.20 x64 - AMD Ryzen 7 - 16 GO RAM
Vidéo NVIDIA GeForce GTX 1650 Ti - Résolution 1920x1080 - Mise à l'échelle 125%
Vidéo NVIDIA GeForce GTX 1650 Ti - Résolution 1920x1080 - Mise à l'échelle 125%
Re: Imprimer (forme paysage)
Vous voulez dire si l'édition se fait en code pb? la réponse est oui, le programme d'édition est écrit en pb, bien entendu.
Win7 (x64) 64 bits Pb 5.72
- falsam
- Messages : 7324
- Inscription : dim. 22/août/2010 15:24
- Localisation : IDF (Yvelines)
- Contact :
Re: Imprimer (forme paysage)
J'ai cherché sur les différents forums Pure Basic si une solution existait et c'est le cas.
Un include que vous nommerez par exemple PrinterOrientation.pbi : Deux procédures sont présentes.
- GetDefaultPrinter() qui permet de connaitre l'imprimante par défaut.
- SetPrinterOrientation() qui Permet de configurer l'orientation de l'imprimante.
by Lord : http://forums.purebasic.com/german/view ... =6&t=26423
■ L'include PrinterOrientation.pbi
■ Le code de test demo1.pbLes constantes #DMORIENT_LANDSCAPE ou #DMORIENT_PORTRAIT sont définies dans Pure Basic.
PS : Penser à décocher l'option Unicode dans les options du compilateur
Un include que vous nommerez par exemple PrinterOrientation.pbi : Deux procédures sont présentes.
- GetDefaultPrinter() qui permet de connaitre l'imprimante par défaut.
- SetPrinterOrientation() qui Permet de configurer l'orientation de l'imprimante.
by Lord : http://forums.purebasic.com/german/view ... =6&t=26423
■ L'include PrinterOrientation.pbi
Code : Tout sélectionner
Procedure.s GetDefaultPrinter()
Protected PrinterName.s = Space(1000)
Protected Size = 1000
OpenLibrary(1,"Winspool.drv")
CallFunction(1,"GetDefaultPrinterA", @PrinterName, @size)
ProcedureReturn PrinterName
EndProcedure
;
; by Lord : http://forums.purebasic.com/german/viewtopic.php?f=6&t=26423
Structure PRINTER_INFO_2_NEW
*pServerName
*pPrinterName
*pShareName
*pPortName
*pDriverName
*pComment
*pLocation
*pDevMode.DEVMODE
*pSepFile
*pPrintProcessor
*pDatatype
*pParameters
*pSecurityDescriptor.SECURITY_DESCRIPTOR
Attributes.l
Priority.l
DefaultPriority.l
StartTime.l
UntilTime.l
Status.l
cJobs.l
AveragePPM.l
EndStructure
Procedure SetPrinterOrientation(pPrinterName, dmOrientation)
Protected hPrinter
Protected dwNeeded
Protected *pi2.PRINTER_INFO_2_NEW
Protected *pDevMode.DEVMODE
Protected pd.PRINTER_DEFAULTS
Protected bFlag.i
Protected lFlag.i
pd\DesiredAccess = #PRINTER_ALL_ACCESS
bFlag = OpenPrinter_(pPrinterName, @hPrinter, pd)
If Not bFlag Or hPrinter=0
Debug "Fehler: OpenPrinter_()"
ProcedureReturn #False
EndIf
SetLastError_(0)
bFlag=GetPrinter_(hPrinter, 2, 0, 0, @dwNeeded)
If Not bflag And (GetLastError_() <> #ERROR_INSUFFICIENT_BUFFER) Or (dwNeeded=0)
ClosePrinter_(hPrinter)
Debug "Error GetPrinter_()"
ProcedureReturn -1;#False
EndIf
*pi2=AllocateMemory(dwNeeded)
If *pi2=0
ClosePrinter_(hPrinter)
Debug "Error AllocMemomry())"
ProcedureReturn -2;#False
EndIf
bFlag=GetPrinter_(hPrinter, 2, *pi2, dwNeeded, @dwNeeded)
If bFlag=0
FreeMemory(*pi2)
ClosePrinter_(hPrinter)
Debug "Error GetPrinter_()"
ProcedureReturn -3;#False
EndIf
If *pi2\pDevMode = 0
dwNeeded=DocumentProperties_(0, hPrinter, pPrinterName, 0, 0, 0)
If dwNeeded<=0
FreeMemory(*pi2)
ClosePrinter_(hPrinter)
Debug "Error DocumentProperties_()"
ProcedureReturn -4;#False
EndIf
*pDevMode=AllocateMemory(dwNeeded)
If *pDevMode=0
FreeMemory(*pi2)
ClosePrinter_(hPrinter)
Debug "Error AllocMemory()"
ProcedureReturn -5;#False
EndIf
lFlag=DocumentProperties_(0, hPrinter, pPrinterName, *pDevMode, 0, #DM_OUT_BUFFER)
If (lFlag<>#IDOK) ;Or (*pDevMode=0)
FreeMemory(*pDevMode)
FreeMemory(*pi2)
ClosePrinter_(hPrinter)
Debug "Error DocumentProperties_()"
ProcedureReturn -6;#False
EndIf
*pi2\pDevMode=*pDevMode
EndIf
If Not (*pi2\pDevMode\dmFields & #DM_ORIENTATION)
FreeMemory(*pi2)
ClosePrinter_(hPrinter)
If *pDevMode
FreeMemory(*pDevMode)
EndIf
Debug "Fehler: Änderung nicht unterstützt."
ProcedureReturn -7;#False
EndIf
*pi2\pDevMode\dmFields = #DM_ORIENTATION
*pi2\pDevMode\dmOrientation = dmOrientation
*pi2\pSecurityDescriptor = 0
lFlag=DocumentProperties_(0, hPrinter, pPrinterName, *pi2\pDevMode, *pi2\pDevMode, #DM_IN_BUFFER|#DM_OUT_BUFFER)
If lFlag<>#IDOK
FreeMemory(*pi2)
ClosePrinter_(hPrinter)
If *pDevMode
FreeMemory(*pDevMode)
EndIf
Debug "Error DocumentProperties() 2"
ProcedureReturn -8;#False
EndIf
bflag=SetPrinter_(hPrinter, 2, *pi2, 0)
If Not bFlag
FreeMemory(*pi2)
ClosePrinter_(hPrinter)
If *pDevMode
FreeMemory(*pDevMode)
EndIf
Debug "Error SetPrinter_()"
ProcedureReturn -9;#False
EndIf
SendMessageTimeout_(#HWND_BROADCAST, #WM_DEVMODECHANGE, 0, pPrinterName, #SMTO_NORMAL, 1000, 0)
If *pi2
FreeMemory(*pi2)
EndIf
If hPrinter
ClosePrinter_(hPrinter)
EndIf
If *pDevMode
FreeMemory(*pDevMode)
EndIf
ProcedureReturn #True
EndProcedure
Code : Tout sélectionner
EnableExplicit
IncludeFile "printerorientation.pbi"
Define PrinterName.s = GetDefaultPrinter()
Debug "Imprimante par defaut" + PrinterName
SetPrinterOrientation(@PrinterName, #DMORIENT_LANDSCAPE)
Define Result = DefaultPrinter()
If StartPrinting("PureBasic Test")
LoadFont(0, "Arial", 100)
If StartDrawing(PrinterOutput())
DrawingFont(FontID(0))
DrawingMode(#PB_2DDrawing_Transparent)
DrawText(100, 20, "Essai d'impression", RGB(255, 0, 0))
StopDrawing()
EndIf
StopPrinting()
EndIf
PS : Penser à décocher l'option Unicode dans les options du compilateur
Dernière modification par falsam le sam. 15/nov./2014 9:59, modifié 2 fois.
Configuration : Windows 11 Famille 64-bit - PB 6.20 x64 - AMD Ryzen 7 - 16 GO RAM
Vidéo NVIDIA GeForce GTX 1650 Ti - Résolution 1920x1080 - Mise à l'échelle 125%
Vidéo NVIDIA GeForce GTX 1650 Ti - Résolution 1920x1080 - Mise à l'échelle 125%
Re: Imprimer (forme paysage)
bonjour Falsam
Merci pour le partage
Cordialement
Merci pour le partage

Cordialement
Re: Imprimer (forme paysage)
Merci à vous tous, je vais tester.
A bientôt
A bientôt
Win7 (x64) 64 bits Pb 5.72