Page loading

Share your opinion
What do you think about gambaslinux.fr?
 
Interesting
It miss some informations
Excellent website
Results
WIDGETS GAMBAS
GAMBAS 3 SOFTWARES
TUTORIALS
Library
Printer and Gambas - Print from a textedit box

Imprimer à partir d'une TextEdit




Il existe une solution simple pour imprimer une TextEdit. Le texte étant du code HTML, il suffit de copier le fichier dans un contrôle WebBrowser et de mettre une commande d'impression Javascript.


Dans votre projet, ajouter:


Une TextArea

Un WebBrowser (vous devez avoir le composant gb.qt.kde.html coché dans votre projet).


Ces deux objets ont la propriété Visible à FALSE et la propriété Javascript du WebBrowser à TRUE.


Créer votre bouton d'impression et ajouter ceci:


TextArea1.Clear

fichierimprimer = Application.Path & "/temp.print"

IF Exist(fichierimprimer) THEN KILL fichierimprimer

TextArea1.Text = TextEdit1.Text

changercode(TextArea1.Text)

TextArea1.Text = Textcode

TextArea1.Text = Replace(TextArea1.Text, "


hFile = OPEN fichierimprimer FOR WRITE CREATE

PRINT #hFile, TextArea1.Text

CLOSE #hFile

webPrint.Path = Trim(fichierimprimer)


Explications:


Nous effaçons le contenu de la TextArea:


TextArea1.Clear


Nous nommons un fichier qui sera imprimé grâce au contrôle WebBrowser:


fichierimprimer = Application.Path & "/temp.print"


S'il existe, nous l'effaçons:


IF Exist(fichierimprimer) THEN KILL fichierimprimer


Nous copions le contenu de la TextEdit dans la TextArea:


TextArea1.Text = TextEdit1.Text


Nous transformons tous les caractères particuliers ou avec accent (Restons Français) en équivalents html:


changercode(TextArea1.Text)

TextArea1.Text = Textcode


Nous écrivons le code d'impression Javascript: body onload='window.print()'


TextArea1.Text = Replace(TextArea1.Text, "


Nous créons le fichier à imprimer:


hFile = OPEN fichierimprimer FOR WRITE CREATE

PRINT #hFile, TextArea1.Text

CLOSE #hFile


Nous importons le fichier dans le WebBrowser qui déclenche automatiquement l'impression:


webPrint.Path = Trim(fichierimprimer)



Il ne faut pas oublier de mettre nos variables au début de notre commande ou au début de notre Form:


fichierimprimer AS String

hfile AS File


Et enfin inclure dans notre Form.Class, la fonction changercode():


PRIVATE SUB changercode(mettre AS String)

'Les A

'-------

mettre = Replace(mettre, "À", "À")

mettre = Replace(mettre, "Á", "Á")

mettre = Replace(mettre, "Â", "Â")

mettre = Replace(mettre, "Ã", "Ã")

mettre = Replace(mettre, "Ä", "Ä")

mettre = Replace(mettre, "Å", "Å")

mettre = Replace(mettre, "Æ", "Æ")

mettre = Replace(mettre, "à", "à")

mettre = Replace(mettre, "á", "á")

mettre = Replace(mettre, "â", "â")

mettre = Replace(mettre, "ã", "ã")

mettre = Replace(mettre, "æ", "æ")

'Les C

'-------

mettre = Replace(mettre, "¢", "¢")

mettre = Replace(mettre, "Ç", "Ç")

mettre = Replace(mettre, "ç", "ç")


'Les E

'-------

mettre = Replace(mettre, "È", "È")

mettre = Replace(mettre, "É", "É")

mettre = Replace(mettre, "Ê", "Ê")

mettre = Replace(mettre, "Ë", "Ë")

mettre = Replace(mettre, "è", "è")

mettre = Replace(mettre, "é", "é")

mettre = Replace(mettre, "ê", "ê")

mettre = Replace(mettre, "ë", "ë")


'Les I

'------

mettre = Replace(mettre, "Ì", "Ì")

mettre = Replace(mettre, "Í", "Í")

mettre = Replace(mettre, "Î", "Î")

mettre = Replace(mettre, "Ï", "Ï")

mettre = Replace(mettre, "ì", "ì")

mettre = Replace(mettre, "í", "í")

mettre = Replace(mettre, "î", "î")

mettre = Replace(mettre, "ï", "ï")


'Les O

'------

mettre = Replace(mettre, "Ò", "Ò")

mettre = Replace(mettre, "Ó", "Ó")

mettre = Replace(mettre, "Ô", "Ô")

mettre = Replace(mettre, "Õ", "Õ")

mettre = Replace(mettre, "Ö", "Ö")

mettre = Replace(mettre, "Ø", "Ø")

mettre = Replace(mettre, "ò", "ò")

mettre = Replace(mettre, "ó", "ó")

mettre = Replace(mettre, "ô", "ô")

mettre = Replace(mettre, "õ", "õ")

mettre = Replace(mettre, "ö", "ö")

mettre = Replace(mettre, "ø", "ø")


'Les U

'-------

mettre = Replace(mettre, "Ù", "Ù")

mettre = Replace(mettre, "Ú", "Ú")

mettre = Replace(mettre, "Û", "Û")

mettre = Replace(mettre, "Ü", "Ü")

mettre = Replace(mettre, "ù", "ù")

mettre = Replace(mettre, "ú", "ú")

mettre = Replace(mettre, "û", "û")

mettre = Replace(mettre, "ü", "ü")

'Les fractions

'----------------

mettre = Replace(mettre, "¼", "¼")

mettre = Replace(mettre, "½", "½")

mettre = Replace(mettre, "¾", "¾")

'TM, COPYRIGHT, REG

'--------------------------

mettre = Replace(mettre, "™", "™")

mettre = Replace(mettre, "©", "©")

mettre = Replace(mettre, "®", "®")

'Divers

'--------

mettre = Replace(mettre, "ƒ", "&nfnof;")

mettre = Replace(mettre, "… ", "…")

mettre = Replace(mettre, "† ", "†")

mettre = Replace(mettre, "‡", "‡")

mettre = Replace(mettre, "ˆ", "ˆ")

mettre = Replace(mettre, "‰", "‰")

mettre = Replace(mettre, "Š", "Š")

mettre = Replace(mettre, "š", "š")

mettre = Replace(mettre, "Œ", "Œ")

mettre = Replace(mettre, "œ", "œ")

mettre = Replace(mettre, "•", "•")

mettre = Replace(mettre, "–", "–")

mettre = Replace(mettre, "˜", "˜")

mettre = Replace(mettre, "¡", "¡")

mettre = Replace(mettre, "£", "£")

mettre = Replace(mettre, "¤", "¤")

mettre = Replace(mettre, "¥", "¥")

mettre = Replace(mettre, "¦", "¦")

mettre = Replace(mettre, "§", "§")

mettre = Replace(mettre, "¨", "¨")

mettre = Replace(mettre, "ª", "ª")

mettre = Replace(mettre, "¬", "¬")

mettre = Replace(mettre, "¯", "¯")

mettre = Replace(mettre, "°", "°")

mettre = Replace(mettre, "±", "±")

mettre = Replace(mettre, "¹", "¹")

mettre = Replace(mettre, "²", "²")

mettre = Replace(mettre, "³", "³")

mettre = Replace(mettre, "´", "´")

mettre = Replace(mettre, "µ", "µ")

mettre = Replace(mettre, "·", "·")

mettre = Replace(mettre, "¸", "¸")

mettre = Replace(mettre, "º", "º")

mettre = Replace(mettre, "»", "»")

mettre = Replace(mettre, "¿", "¿")

Textcode = mettre


END




























Si vous avez bien tout copié, vous devez avoir un écran d'impression lorsque vous cliquez sur votre bouton Imprimer:


Pour imprimer en couleur et imprimer les images, configurez ici:


Vous avez également la possibilité de créer directement un fichier PDF.


Fait le 25/09/09 par taoteblues


Creation date : 11/10/2009 @ 15:03
Last update : 11/10/2009 @ 15:14
Category : Printer and Gambas
Page read 5626 times


Print the article Print the article


react.gifReactions to this article


Reaction #1 

by Gambix 13/10/2009 @ 16:22

Heu ????

Public Sub Button_Click()


Draw.Begin(Printer)
Draw.Text(TextArea.Text, 50, 50, Printer.With, Printer.Height)
Draw.End


End

Ensuite j'expliquerais a quoi sert gb.report :)

QUICK MENU
SEARCH




LANGUAGE
COMPONENTS
Other
LANGUAGE
Where, who?
VISITS

   visitors

   visitors online

ARCHIVES GAMBAS 1/2
^ Top ^