Sign in to follow this  
Followers 0
martin

printing using UDF and a dll

237 posts in this topic

#1 ·  Posted (edited)

This is a printing UDF which allows you to print text in any font, size and colour at any position on the page, draw lines, curves, elipses, pies in any colour, and print images. Useful for labels, reports, graphs and standard forms. Can also print barcodes. It uses my printmg.dll. It is not intended to do the sorts of thing you can do with the Word UDF by big_daddy.

Note the dll is 32 bit and so only works with 32 bit applications.

printout from the code in the example in the download.

Functions available are -
Start using/Finish using the UDF
_PrintDllStart _PrintDllClose
_PrintVersion - Returns version of UDF or dll
_PrintSetTitle
Printer control
_PrintStartPrint
_PrintAbort
_PrintEndPrint
_PrintNewPage
Printer selection, getting & setting parameters
_PrintListPrinters - lists all installed printers
_PrintSetPrinter - manual printer selection dialogue
_PrintSelectPrinter - programmatically set the printer.
_PrintGetPageWidth
_PrintGetPaperWidth
_PrintGetPageHeight
_PrintGetPaperHeight
_PrintGetHorRes
_PrintGetVertRes
_PrintGetXOffset
_PrintGetYOffset
_PrintPageOrientation - set portrait or landsacpe
Text printing
_PrintSetFont - Font, size, attributes and colour
_PrintText - At x,y and angle.
_PrintGetextWidth
_PrintGetTextHeight
Graphics
_PrintSetLineCol
_PrintSetLIneWid
_PrintSetBrushCol - sets the colour used for filling
_PrintLine
_PrintEllipse - Filled ellipse or circle
_PrintPie - for filled pie slice
_PrintArc - Elliptical or circular arcs
_PrintRectangle - filled rectangle
_PrintRoundedRectangle
_PrintImage - prints jpg, bmp and ico files (Has problems with some icons bigger than 64 x 64)
_PrintImageFromDC

Latest change = 25th February 2011
Added example to the download which was missing.

Get the UDF, dll and example from here.
=================================================================
See also these udf's for printing from AutoIt using the Windows API and not using a dll.
by GRS - http://www.autoitscript.com/forum/topic/...m-autoit/page__view__findpost_
by Prog@ndy -http://www.autoitscript.com/forum/topic/...gdi-udfs/page__view__findpost_

and this one which embeds a dll in the script for creating pdf files.
printing to a pdf by taietel see

Edited by martin
2 people like this

Serial port communications UDF Includes functions for binary transmission and reception.printing UDF Useful for graphs, forms, labels, reports etc.Add User Call Tips to SciTE for functions in UDFs not included with AutoIt and for your own scripts.Functions with parameters in OnEvent mode and for Hot Keys One function replaces GuiSetOnEvent, GuiCtrlSetOnEvent and HotKeySet.UDF IsConnected2 for notification of status of connected state of many urls or IPs, without slowing the script.

Share this post


Link to post
Share on other sites



This is a simple example of printing using my print UDF which uses a dll. It is not intended to do the sorts of thing you can do with the Word UDF by big daddy, but it allows you to print text in any font, size and colour and to draw straight lines in any colour. Useful for labels, reports and so on.

#include 'printMGv2.au3'
Global $hp
Local $mmssgg,$marginx,$marginy
$hp = _PrintDllStart($mmssgg);this must always be called first
if $hp = 0 then consolewrite("Error from dllstart = " & $mmssgg & @CRLF)
ConsoleWrite('dll version is' & _PrintVersion($hp,1) & @CRLF)

_PrintSetPrinter($hp);choose the printer if you don't want the default printer
_PrintStartPrint($hp)
$title = 'Printing with a dll'
$twid = _PrintGetTextWidth($hp,$title)
$tht = _PrintGetTextHeight($hp,$title)
_PrintSetLineWid($hp,10)
_PrintSetLineCol($hp,0x00ff00)
$pw = _PrintGetPageWidth($hp)
$tx = Int(($pw - $twid) /2)
$ty = 100
_PrintText($hp,$title,$tx,$ty)
;Draw a box around the text
_PrintLine($hp,$tx-50,$ty-50,$tx + $twid + 50,$ty - 50)
_PrintLine($hp,$tx + $twid + 50,$ty - 50,$tx + $twid + 50,$ty + $tht + 50)
_PrintLine($hp,$tx - 50,$ty + $tht + 50,$tx-50,$ty-50)
_PrintSetLineCol($hp,0x0000ff)
_PrintLine($hp,$tx + $twid + 50,$ty + $tht + 50,$tx - 50,$ty + $tht + 50)

_PrintEndPrint($hp)
_PrintDllClose($hp);this must always be called last

Functions available are -

_PrintDllStart

_PrintDllClose

_PrintSetPrinter

_PrintGetPageWidth

_PrintGetPageHeight

_PrintGetHorRes

_PrintGetVertRes

_PrintStartPrint

_PrintSetFont

_PrintNewPage

_PrintEndPrint

_PrintText

_PrintGetextWidth

_PrintGetTextHeight

_PrintLine

_PrintGetXOffset

_PrintGetYOffset

_PrintSetLineCol

_PrintSetLIneWid

The link below is for a compressed link. If you download it, extract the link then double click on it and it will get the zip containing the UDF and the dll.

The whole thing is a bit underdeveloped.

If there is any interest then I will put some effort into it.

(Yes, I know it would be better if I didn't use a dll.)

Great job! :)

Share this post


Link to post
Share on other sites

Great job! :)

Thanks Gif, I hope it works for people.

First post is updated with additions.


Serial port communications UDF Includes functions for binary transmission and reception.printing UDF Useful for graphs, forms, labels, reports etc.Add User Call Tips to SciTE for functions in UDFs not included with AutoIt and for your own scripts.Functions with parameters in OnEvent mode and for Hot Keys One function replaces GuiSetOnEvent, GuiCtrlSetOnEvent and HotKeySet.UDF IsConnected2 for notification of status of connected state of many urls or IPs, without slowing the script.

Share this post


Link to post
Share on other sites

Hi!

Run OK on a french-XP.

Thanks.

:)

Share this post


Link to post
Share on other sites

Hi!

Run OK on a french-XP.

Thanks.

:)

Naturelment!


Serial port communications UDF Includes functions for binary transmission and reception.printing UDF Useful for graphs, forms, labels, reports etc.Add User Call Tips to SciTE for functions in UDFs not included with AutoIt and for your own scripts.Functions with parameters in OnEvent mode and for Hot Keys One function replaces GuiSetOnEvent, GuiCtrlSetOnEvent and HotKeySet.UDF IsConnected2 for notification of status of connected state of many urls or IPs, without slowing the script.

Share this post


Link to post
Share on other sites

#6 ·  Posted (edited)

Hi!

What is the statut (licensing...) of the DLL?

Can I use with freedom?

Edited by Michel Claveau

Share this post


Link to post
Share on other sites

OK in french-XP

Naturelment!

I want said than I had try with accent & euro caracter, with success.

I don't had try with "Arial Unicode" & very specials unicodes caracters.

(* sorry for my bad english *)

Share this post


Link to post
Share on other sites

#8 ·  Posted (edited)

What is the statut (licensing...) of the DLL?

Can I use with freedom?

The dll is for you to use as you want. If it causes any problems at all then I will try to fix it but I do not take any responsibility for any problems and I make no guarantees about its capabilities or fitness for purpose.

I want said than I had try with accent & euro caracter, with success.

I don't had try with "Arial Unicode" & very specials unicodes caracters.

I haven't tried any special Unicode examples either.

Edited by martin

Serial port communications UDF Includes functions for binary transmission and reception.printing UDF Useful for graphs, forms, labels, reports etc.Add User Call Tips to SciTE for functions in UDFs not included with AutoIt and for your own scripts.Functions with parameters in OnEvent mode and for Hot Keys One function replaces GuiSetOnEvent, GuiCtrlSetOnEvent and HotKeySet.UDF IsConnected2 for notification of status of connected state of many urls or IPs, without slowing the script.

Share this post


Link to post
Share on other sites

The dll is for you to use as you want.

OK. I want sell it 1,000,000,000,000$ (or more).

Thanks. :P

For info, I had try to call the DLL with (from) Python (+ctypes).

And it's run perfectly. :)

Share this post


Link to post
Share on other sites

OK. I want sell it 1,000,000,000,000$ (or more).

Thanks. :P

Oooh, it's worth much more than that!

For info, I had try to call the DLL with (from) Python (+ctypes).

And it's run perfectly. :)

I wrote it because I thought it would be useful for AutoIters, but it can be used with anything. Nice to know it worked with Python.


Serial port communications UDF Includes functions for binary transmission and reception.printing UDF Useful for graphs, forms, labels, reports etc.Add User Call Tips to SciTE for functions in UDFs not included with AutoIt and for your own scripts.Functions with parameters in OnEvent mode and for Hot Keys One function replaces GuiSetOnEvent, GuiCtrlSetOnEvent and HotKeySet.UDF IsConnected2 for notification of status of connected state of many urls or IPs, without slowing the script.

Share this post


Link to post
Share on other sites

Re

I don't find anyway for PageSet (type / size).

Lapse of memory?

Too much difficult?

Am I blind?

Share this post


Link to post
Share on other sites

I found a little error.

in printMGv2.au3, for _PrintRectangle, you write "Ellipse" in lieu of "Rectangle" (in DLL.call)

(the word rectangle is good in the DLL)

Share this post


Link to post
Share on other sites

#13 ·  Posted (edited)

Re

I don't find anyway for PageSet (type / size).

Lapse of memory?

Too much difficult?

Am I blind?

You should be able to set the page if you use _PrintSetPrinter. Next to the combobox to choose a printer there should be a Properties button. This will access the printer properties and you should be able to set the page size.

If this doesn't work let me know.

Edit: spelling

Edited by martin

Serial port communications UDF Includes functions for binary transmission and reception.printing UDF Useful for graphs, forms, labels, reports etc.Add User Call Tips to SciTE for functions in UDFs not included with AutoIt and for your own scripts.Functions with parameters in OnEvent mode and for Hot Keys One function replaces GuiSetOnEvent, GuiCtrlSetOnEvent and HotKeySet.UDF IsConnected2 for notification of status of connected state of many urls or IPs, without slowing the script.

Share this post


Link to post
Share on other sites

#14 ·  Posted (edited)

I found a little error.

in printMGv2.au3, for _PrintRectangle, you write "Ellipse" in lieu of "Rectangle" (in DLL.call)

(the word rectangle is good in the DLL)

Thanks :) Now fixed. Mod uploaded.

Edited by martin

Serial port communications UDF Includes functions for binary transmission and reception.printing UDF Useful for graphs, forms, labels, reports etc.Add User Call Tips to SciTE for functions in UDFs not included with AutoIt and for your own scripts.Functions with parameters in OnEvent mode and for Hot Keys One function replaces GuiSetOnEvent, GuiCtrlSetOnEvent and HotKeySet.UDF IsConnected2 for notification of status of connected state of many urls or IPs, without slowing the script.

Share this post


Link to post
Share on other sites

:)

A bug!

_PrintPageOrientation(.. break AutoIt (with Python : "exception code 0xeedfade")

Share this post


Link to post
Share on other sites

#16 ·  Posted (edited)

:)

A bug!

_PrintPageOrientation(.. break AutoIt (with Python : "exception code 0xeedfade")

Yes it is a sort of bug. The page orientation should only be set before _PrintStartPrint or after _PrintEndPrint, so did you try changing the orientation after a _PrintStartPrint?

I will make it so that if _PrintStartPrint is active then _PrintPageOrientation returns an error.

Edited by martin

Serial port communications UDF Includes functions for binary transmission and reception.printing UDF Useful for graphs, forms, labels, reports etc.Add User Call Tips to SciTE for functions in UDFs not included with AutoIt and for your own scripts.Functions with parameters in OnEvent mode and for Hot Keys One function replaces GuiSetOnEvent, GuiCtrlSetOnEvent and HotKeySet.UDF IsConnected2 for notification of status of connected state of many urls or IPs, without slowing the script.

Share this post


Link to post
Share on other sites

Hi, Martin!

You are right : call Portrait (orientation) before PrinterBegin run correctly.

Apologies for trouble.

Share this post


Link to post
Share on other sites

This is the most useful UDF I have ever had

I'll use it to fill pre-printed forms in my company.

Thanks for sharing

regards

Share this post


Link to post
Share on other sites

This is the most useful UDF I have ever had

I'll use it to fill pre-printed forms in my company.

Thanks for sharing

regards

Oh, thanks, it's always nice to know it's been useful. :)

(When I see a reply in my threads I expect to find there has been a problem! Better not speak too soon though.)


Serial port communications UDF Includes functions for binary transmission and reception.printing UDF Useful for graphs, forms, labels, reports etc.Add User Call Tips to SciTE for functions in UDFs not included with AutoIt and for your own scripts.Functions with parameters in OnEvent mode and for Hot Keys One function replaces GuiSetOnEvent, GuiCtrlSetOnEvent and HotKeySet.UDF IsConnected2 for notification of status of connected state of many urls or IPs, without slowing the script.

Share this post


Link to post
Share on other sites

Great work!

Nearly what I was looking for but.... If I have a text file, can your DLL and UDF can be used to change the default printer and print the file?

Thanks

Sean

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0