Page 1 sur 1

[RESOLU] Pb d'impression , les DPI me sortent par les ...

Publié : mer. 29/déc./2010 1:09
par wood51
Bonsoir,
Voilà 2 jours que je cherche un moyen d'imprimer un simple cadre de 10mm(ou plus tant que c'est à égale distance des bords) sur une feuille ou tous simplement d'imprimer à des endroit précis et que tous soit bien à sa place et pas décalé a cause des marges . J'ai essayé plusieurs exemples mais pas moyen d'y arrivé . En plus je crois que me suis perdu avec les DPI,Unités d'impression,mm,pixel et autres dot ... :roll: .
Si quelqu'un pouvait m'expliquer un peu comment je peux faire , ce serait sympa :mrgreen:

Re: Pb d'impression , les DPI me sortent par les narines !!!

Publié : mer. 29/déc./2010 10:49
par kernadec
bonjour
tu peux essayer avec la librairie d'ABBKlaus Dresen "PrinterLib [PB v4]"
ici:http://www.purearea.net/pb/english/index.htm

Cordialement

Re: Pb d'impression , les DPI me sortent par les narines !!!

Publié : mer. 29/déc./2010 12:16
par wood51
Bonjours,
Merci de la réponse :D
J'utilise déjà cet Lib.En fait avec la fonction Print_GetDeviceCaps normalement je devrait connaître tous les infos et pouvoir calculer les marge puis centrer mon impression mais je n'arrive pas a comprendre la conversion d'unité et le calcule des marges.

Re: Pb d'impression , les DPI me sortent par les narines !!!

Publié : mer. 29/déc./2010 20:43
par case
dpi= dot per inch

en français, points par pouce.

1 pouce = 2,54 cm

si tu imprime en 200 dpi cela signifie que tu auras 200 points dans 2.54cm

la taille d'un point sera alors égale a 0.0127 cm

1 cm=0,3937007874015748031496062992126 pouce

donc en 200 dpi toujours tu aura

200*0,3937007874015748031496062992126

soit

78,74015748031496062992125984252 points par cm

Re: Pb d'impression , les DPI me sortent par les narines !!!

Publié : jeu. 30/déc./2010 1:28
par wood51
Merci,Merci !!!
Juste une précision : les unités d'impression , c'est les point ?
Les fonctions Print_GetDeviceCaps(#PHYSICALOFFSETX) et Print_GetDeviceCaps(#PHYSICALOFFSETY) me donne respectivement la marge gauche et haute en point ?
Quand est-il des marge basse et droite ?

En tous cas merci , j'essaye demain !!! :D

Re: Pb d'impression , les DPI me sortent par les narines !!!

Publié : lun. 03/janv./2011 13:03
par kernadec
bonjour wood51

Dans codeArchiv : il y avait ce très bon exemple d'impression de Fred.

Pour les portions colorées dans un cercle FillAréa fonctionne mal avec les imprimantes
mais reste la solution d'utiliser des lignes.

avec aussi l'impression une ListView à partir d'une capture en image de la zone du gadget.

Cordialement

Code : Tout sélectionner

; English forum:
; Author: Rui Carvalho (updated for PB4.00 by blbltheworm)
; Date: 01. March 2003
; OS: Windows
; Demo: Yes

;***************************
;Super Printer - DPI indepent print
;by Rui Carvalho - 2003
;
;Part of GIA - Lift Management Software
;Freeware
;***************************

;rui-carvalho@bigfoot.com

Declare ycm(x.f)
Declare xcm(x.f)
;
;Original printer code by Fred
;

hwnd=OpenWindow(1,0,0,340,280,"test impression listview",#PB_Window_SystemMenu | #PB_Window_ScreenCentered)

ListIconGadget(0,10,10,320,260,"Nom",100,#PB_ListIcon_FullRowSelect |#PB_ListIcon_AlwaysShowSelection )
SendMessage_(GadgetID(0),#LVM_SETEXTENDEDLISTVIEWSTYLE,#LVS_EX_GRIDLINES,#LVS_EX_GRIDLINES)
For i = 1 To 3
  AddGadgetColumn(0,i,"Col : "+Str(i),70)
Next
For i = 0 To 10 : AddGadgetItem(0,-1,"List Item #" + Str(i)+Chr(10)+"pomme"+Chr(10)+"poire"+Chr(10)+"prune") : Next
CreateImage(0,GadgetWidth(0),GadgetHeight(0))

DC=StartDrawing(ImageOutput(0))
For i=1 To 50:WindowEvent():Next i  ; boucle de dessin des boutons sur la fenetre avant screenshot
BitBlt_(DC,0,0,GadgetWidth(0),GadgetHeight(0),GetDC_(hwnd),GadgetX(0),GadgetY(0),#SRCCOPY)
StopDrawing()

Delay(2000)

If PrintRequester()
  
  If StartPrinting("PureBasic Test")
    LoadFont(0, "Arial", ycm(0.4))
    LoadFont(1, "Curlz MT", ycm(1))
    
    If StartDrawing(PrinterOutput())
      FrontColor(RGB(240,220,20))
      Box(xcm(4), ycm(7), xcm(2), ycm(6))               ; draw a 4cm by 7cm square x=2cm y=6cm
      
      DrawingMode(#PB_2DDrawing_Outlined )              ; figures géométriques en traits 
      
      DrawingFont(FontID(0));4mm font size
      
      ; locate at 15cm by 14cm      
      DrawRotatedText(xcm(15), ycm(14), "PUREBASIC IS A LEGEND",90, RGB(255, 0, 255))
      DrawRotatedText(xcm(15), ycm(14), "PUREBASIC IS A LEGEND",39, RGB(0, 0, 255))
      DrawRotatedText(xcm(15), ycm(14), "PUREBASIC IS A LEGEND",347, RGB(0, 255, 0))
      DrawRotatedText(xcm(15), ycm(14), "PUREBASIC IS A LEGEND",296, RGB(255, 255, 0))
      DrawRotatedText(xcm(15), ycm(14), "PUREBASIC IS A LEGEND",244, RGB(255, 0, 0))
      DrawRotatedText(xcm(15), ycm(14), "PUREBASIC IS A LEGEND",193, RGB(240,150,20))
      DrawRotatedText(xcm(15), ycm(14), "PUREBASIC IS A LEGEND",142, RGB(225, 225, 225))
      
      Circle(xcm(15), ycm(14),ycm(6.6),RGB(0,0,255))     ; draw a 15cm by 14cm circle rayon y=5cm
      
      ; locate at 15cm by 5,5cm
      DrawText(xcm(14), ycm(5.5),"PureBasic Printer Test",RGB(0,0,255),RGB(255,255,255))
      
      DrawingFont(FontID(1)); 1 cm font size
      
      ; locate at 7cm by 25cm
      DrawText(xcm(7), ycm(25),"PUREBASIC TEN YEAR ALREADY",RGB(128,128,128),RGB(255,255,255))
      
      
      If LoadImage(1,"..\PureBasic\Examples\Sources\Data\PureBasicLogo.bmp"); The logo bitmap is bigger
        ResizeImage(1, xcm(8), ycm(3))                  ; resize image for 8cm by 3cm
        DrawImage(ImageID(1), xcm(1), ycm(1))           ; draw image at 1cm by 1cm
      Else
        MessageRequester("", "2", 0)
      EndIf
      
      FrontColor(RGB(100,100,100))
      Box(xcm(2), ycm(5), xcm(6), ycm(10))              ; draw a 2cm by 5cm square x=6cm y=10cm
      
      For i=1 To 360
        LineXY(xcm(5), ycm(20),Cos(Radian(342+(i/5)))*(ycm(5))+xcm(5),Sin(Radian(342+(i/5)))*(ycm(5))+ycm(20),RGB(255,0,0))
        LineXY(xcm(5), ycm(20),Cos(Radian(54+(i/5)))*(ycm(5))+xcm(5),Sin(Radian(54+(i/5)))*(ycm(5))+ycm(20),RGB(255,0,255))
        LineXY(xcm(5), ycm(20),Cos(Radian(126+(i/5)))*(ycm(5))+xcm(5),Sin(Radian(126+(i/5)))*(ycm(5))+ycm(20),RGB(0,0,255))
        LineXY(xcm(5), ycm(20),Cos(Radian(198+(i/5)))*(ycm(5))+xcm(5),Sin(Radian(198+(i/5)))*(ycm(5))+ycm(20),RGB(255,255,0))
        LineXY(xcm(5), ycm(20),Cos(Radian(270+(i/5)))*(ycm(5))+xcm(5),Sin(Radian(270+(i/5)))*(ycm(5))+ycm(20),RGB(0,255,0))
      Next i 
      
      Circle(xcm(5), ycm(20),ycm(5),RGB(0,0,0))       ; draw a 5cm by 20cm circle rayon y=5cm
      
      ResizeImage(0, xcm(10), ycm(13))
      DrawImage(ImageID(0), xcm(3), ycm(28)) 
      
      
      StopDrawing()
    EndIf
    
    StopPrinting()
  EndIf
EndIf



;**** the trick !!!! ****

Procedure xcm(x.f)
  
  result = x * (PrinterPageWidth()/21) ; 21cm A4
  ProcedureReturn result
  
EndProcedure


Procedure ycm(x.f)
  
  result = x * (PrinterPageWidth()/29.7) ; 29,7cm A4
  ProcedureReturn result
  
EndProcedure


;Tested with fineprintpdf in multiple DPI's
;and on Xerox DC440 laser printer


Re: Pb d'impression , les DPI me sortent par les narines !!!

Publié : mer. 05/janv./2011 7:28
par wood51
Merci de la réponse , j'avance tout doucement mais sûrement . Merci encore :D

Voilà mon petit bout de code pour tracé un cadre centré tour autour de la page :

Code : Tout sélectionner

hdc= Print_PrintDlg(#PB_Any)
  If(hdc)
  Print_SetUnits(#PRINT_MM)
  dpi_x=GetDeviceCaps_(hdc,#LOGPIXELSX) ;DPI Imprimante
  dot.f=(25.4/dpi_x) ;Taille d'un point en mm
  Page_x.f=Print_GetDeviceCaps(#PHYSICALWIDTH)*dot
  Page_y.f=Print_GetDeviceCaps(#PHYSICALHEIGHT)*dot
  Marge_gauche.f=Print_GetDeviceCaps(#PHYSICALOFFSETX)*dot
  Marge_haute.f=Print_GetDeviceCaps(#PHYSICALOFFSETY)*dot
  Print_Font("Arial",16,#PB_Font_Bold)
  Print_StartPrinting("Bon de livraison")
  Print_Rectangle(20-Marge_gauche,20-Marge_haute,Page_x-40,Page_y-40) ;Cadre de 20mm autour de la page
  Print_DrawText(20-Marge_gauche,25-Marge_haute,Page_x-40,Page_y-40,"BON DE LIVRAISON",#DT_CENTER)
  Print_StopPrinting()
  Else
    MessageRequester("Erreur","Impression Annulée !")
  EndIf