Jump to content

printing using UDF and a dll


martin
 Share

Recommended Posts

Martin

Using this method

#Include <PrintWinAPI.au3>

$s_PrinterName = "24x36"
$hPrintDc = _WinAPI_CreateDC("winspool", $s_PrinterName)

$s_DocName = "Printing from AutoIt with WinAPI"
$DocName = DllStructCreate("char DocName[" & StringLen($s_DocName & chr(0)) & "]")
DllStructSetData($DocName, "DocName", $s_DocName & chr(0)); Size of DOCINFO structure
$DOCINFO = DllStructCreate($tagDOCINFO); Structure for Print Document info
DllStructSetData($DOCINFO, "Size", 20); Size of DOCINFO structure
DllStructSetData($DOCINFO, "DocName", DllStructGetPtr($DocName)); Set name of print job (Optional)

; start new print doc
$result = _WinAPI_StartDoc($hPrintDc, $DOCINFO)
; start new page
$result = _WinAPI_StartPage($hPrintDc)

    _GDIPlus_Startup ()
    
    $hGraphic = _GDIPlus_GraphicsCreateFromHDC ($hPrintDc)
    
    $hImage = _GDIPlus_ImageLoadFromFile(@scriptDir & "\24x36.jpg")

    _GDIPLus_GraphicsDrawImageRect($hGraphic, $hImage, 0, 0, 2390,3585)

    _GDIPlus_GraphicsDispose ($hGraphic)
    _GDIPlus_Shutdown ()

; End the page
$result = _WinAPI_EndPage($hPrintDc)
; End the print job
$result = _WinAPI_EndDoc($hPrintDc)
; Delete the printer device context
_WinAPI_DeleteDC($hPrintDc)

Seems to work OK, it uses the preferences, does this help you with what you need to know?

Link to comment
Share on other sites

Martin

Using this method

#Include <PrintWinAPI.au3>

$s_PrinterName = "24x36"
$hPrintDc = _WinAPI_CreateDC("winspool", $s_PrinterName)

$s_DocName = "Printing from AutoIt with WinAPI"
$DocName = DllStructCreate("char DocName[" & StringLen($s_DocName & chr(0)) & "]")
DllStructSetData($DocName, "DocName", $s_DocName & chr(0)); Size of DOCINFO structure
$DOCINFO = DllStructCreate($tagDOCINFO); Structure for Print Document info
DllStructSetData($DOCINFO, "Size", 20); Size of DOCINFO structure
DllStructSetData($DOCINFO, "DocName", DllStructGetPtr($DocName)); Set name of print job (Optional)

; start new print doc
$result = _WinAPI_StartDoc($hPrintDc, $DOCINFO)
; start new page
$result = _WinAPI_StartPage($hPrintDc)

    _GDIPlus_Startup ()
    
    $hGraphic = _GDIPlus_GraphicsCreateFromHDC ($hPrintDc)
    
    $hImage = _GDIPlus_ImageLoadFromFile(@scriptDir & "\24x36.jpg")

    _GDIPLus_GraphicsDrawImageRect($hGraphic, $hImage, 0, 0, 2390,3585)

    _GDIPlus_GraphicsDispose ($hGraphic)
    _GDIPlus_Shutdown ()

; End the page
$result = _WinAPI_EndPage($hPrintDc)
; End the print job
$result = _WinAPI_EndDoc($hPrintDc)
; Delete the printer device context
_WinAPI_DeleteDC($hPrintDc)

Seems to work OK, it uses the preferences, does this help you with what you need to know?

Yes that should be very helpful.

The only other thing I was thinking was can you send the paper size to it?

Yes I am sure I can do that (though I haven't done it yet.)
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.
Link to comment
Share on other sites

  • 3 weeks later...
  • 2 weeks later...

Can anyone post again printMGv2.au3 and printmg.dll package ?

Download in first post are corrupted (?)

[all Get_printmgV2.zip < 1kb]

thank you,

m.

So far whenever someone has said that it's because they didn't read what I wrote above the link.

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.

So have you done that?
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.
Link to comment
Share on other sites

  • 1 month later...

I am writing a program for work and needed bar code font 3 of 9. here's the code I have in case anyone is ever in need of 3 of 9. will take some modification to suit another purpose...

on a side note, still a n00b at this programming stuff... does anyone care to tell me how to continue my long array onto the next line? or do I have to have it all typed on one long line:(

#include<printmgv2.au3>
#include<array.au3>
;add this to the tag program function in the toolbox, must format remainder of tag using printmgv2
global $sErr, $dist, $tag
global $alpha2bin[44][2]=[["*","NSNEWEWEN"],["-"    ,"NSNENEWEW"],["$"  ,"NSNSNSNEN"],["%"  ,"NENSNSNSN"],[" "  ,"NSWENEWEN"],["."  ,"WSNENEWEN"],["/"  ,"NSNSNENSN"],["+"  ,"NSNENSNSN"],["0"  ,"NENSWEWEN"],["1","WENSNENEW"],["2"    ,"NEWSNENEW"],["3"  ,"WEWSNENEN"],["4"  ,"NENSWENEW"],["5"  ,"WENSWENEN"],["6"  ,"NEWSWENEN"],["7"  ,"NENSNEWEW"],["8"  ,"WENSNEWEN"],["9"  ,"NEWSNEWEN"],["A"  ,"WENENSNEW"],["B"  ,"NEWENSNEW"],["C","WEWENSNEN"],["D","NENEWSNEW"],["E","WENEWSNEN"],["F","NEWEWSNEN"],["G","NENENSWEW"],["H","WENENSWEN"],["I","NEWENSWEN"],["J","NENEWSWEN"],["K","WENENENSW"],["L","NEWENENSW"],["M","WEWENENSN"],["N","NENEWENSW"],["O","WENEWENSN"],["P"    ,"NEWEWENSN"],["Q"  ,"NENENEWSW"],["R"  ,"WENENEWSN"],["S","NEWENEWSN"],["T"    ,"NENWEWSN"],["U","WSNENENEW"],["V", "NSWENENEW"],["W", "WSWENENEN"],["X", "NSNEWENEW"],["Y", "WSNEWENEN"],["Z", "NSWEWENEN"]]
#region use the variables in this region to move the barcode around the page
$barheight=100;height of barcode
$barstartx=100;x starting position, recommend 500 less than page width minimum
$bartop=200;top label barcode barcode y position
$barbot=1000;bottom label barcode y position
$barcounter=0;count how far the X coordinate has moved 
#EndRegion
#Region------------------------------------------program region---------------------------------------------------

dircreate(@tempdir&"\as400 tools")
FileInstall("d:\test\printmg.dll",@tempdir&"\as400 tools\printmg.dll",1)
$dll=_printdllstart($sErr,@TempDir&"\as400 tools\printmg.dll")
_printsetprinter($dll);use print select printer and printer ini file printer selections. need to update toolbox with ini creation and modification. add control to hotkey for manual printer selection
_printstartprint($dll)
$width=_printgetpagewidth($dll)
$height=_printgetpageheight($dll)
;call functions to write all the data to the tag, functions need to be written. data comes from screen shot. 

addbarcode("*"&$dist&$tag&"*")
_printendprint($dll)
#EndRegion ---------------------------------------------------------------------------------------------------------
#region defines the functions needed to write the bar code.-------------------nested functions---------------------------------------------
;~ W    Wide - Black
;~ N    Narrow - Black
;~ S    Wide - White
;~ E    Narrow - White
func N()
    _printsetlinewid($dll,1)
    for $i=0 to 5
    _printline($dll,$barstartx+$barcounter+$i,$bartop,$barstartx+$barcounter+$i,$bartop+$barheight)
    _printline($dll,$barstartx+$barcounter+$i,$barbot,$barstartx+$barcounter+$i,$barbot+$barheight)
    Next
    $barcounter=$barcounter+5
    EndFunc
func W()
    _printsetlinewid($dll,1)
    for $i=0 to 9 
    _printline($dll,$barstartx+$barcounter+$i,$bartop,$barstartx+$barcounter+$i,$bartop+$barheight)
    _printline($dll,$barstartx+$barcounter+$i,$barbot,$barstartx+$barcounter+$i,$barbot+$barheight)
    Next    
    $barcounter=$barcounter+10
EndFunc
func S()
    $barcounter=$barcounter+10
EndFunc
func E()
    $barcounter=$barcounter+5
EndFunc
func addbarcode($tagnum)
for $j=1 to 11
local $where=_arraysearch($alpha2bin,stringmid($tagnum,$j,1))
for $i=1 to 9
    $switch=stringmid($alpha2bin[$where][1],$i,1)
    Switch $switch
        case $switch="N"
            N()
        case $switch="W"
            W()
        Case $switch="S"
            S()
        case $switch="E"
            E()
    EndSwitch
next
$barcounter=$barcounter+5
Next
EndFunc
#EndRegion
Edited by DangerousDan
Link to comment
Share on other sites

I am writing a program for work and needed bar code font 3 of 9. here's the code I have in case anyone is ever in need of 3 of 9. will take some modification to suit another purpose...

on a side note, still a n00b at this programming stuff... does anyone care to tell me how to continue my long array onto the next line? or do I have to have it all typed on one long line:(

Thanks for the example DangerousDan.

To break a line into 2 or more end the break with a space followed by an underscore (there must be a space before the underscore)

global $alpha2bin[44][2]=[["*","NSNEWEWEN"],["-"    ,"NSNENEWEW"],["$"  ,"NSNSNSNEN"], _
               ["%" ,"NENSNSNSN"],[" "  ,"NSWENEWEN"],["."  ,"WSNENEWEN"],["/"  ,"NSNSNENSN"],["+"  ,"NSNENSNSN"],["0"  ,"NENSWEWEN"],

If you want to make the break mid way through a string you must make 2 strings which you concatenate.

$longString = "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa" & _
                              "bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb"
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.
Link to comment
Share on other sites

awesome, thanks for the help. and thanks for the print UDF:) you mentioned in one of the posts, or someone did, about a convert to inches option. how do I do that?:)

The print UDF uses tenths of a millimetre. If you want to use inches then you need to multiply your dimensions by 25.4 and divide returned dimensions by 25.4.

Global Const $MMTOINCH = 1/25.4, $INCHTOMM = 25.4

$twid1 = _PrintGetTextWidth($hDll,$sWText)*$MMTOINCH 
_PrintText($hDll,$sText,$x*$INCHTOMM ,$iy*$INCHTOMM)

But sometimes there is no point. For example, if you want to print text in the middle of the page then the process is

get the page width

get the text width

print the text at 0.5*(pagewidth - textwidth)

and the units are irrelevant. In these cases converting between inches and mm is like someone who travels to America, converts the price of the goods from Dollars to Euros then works out how many Dollars that is to pay for it.

You could modify the udf to deal with inches of course, though I won't be supportung it :)

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.
Link to comment
Share on other sites

one more thing (hopefully) ... I can't select the "fixedsys" font using printsetfont. I need a font that has equal spacing for all characters so my form isn't screwed up by a bunch of w's or m's lol. is this a windows issue(appears to be) or does your dllcall require a TTF font? I'm not smart enough to guess lol.

code I am using:

_printsetfont($dll,"FixedSys","18","0","")

_printtext($dll,"text123",50,300,0)

results are in Arial, from what I can gather just by looking. definitely not fixedsys.

Link to comment
Share on other sites

one more thing (hopefully) ... I can't select the "fixedsys" font using printsetfont. I need a font that has equal spacing for all characters so my form isn't screwed up by a bunch of w's or m's lol. is this a windows issue(appears to be) or does your dllcall require a TTF font? I'm not smart enough to guess lol.

code I am using:

_printsetfont($dll,"FixedSys","18","0","")

_printtext($dll,"text123",50,300,0)

results are in Arial, from what I can gather just by looking. definitely not fixedsys.

I think you are correct that fixedsys doesn't print with my dll so I'll send you a test dll which I think fixes it. If it does work for you then I'll have to decide what to do with the dll. As far as I can see at the moment, it looks like I have to specify not only FixedSys but specify that it is a fixed space font otherwise Windows seems to substitute Arial. This might be because fixedsys is not often used now and was replaced by San Serif (I think but I could be wrong).

Other fixed space fonts, like Courier New and Terminal do seem to work. (Courier New is more of a fixed space font than fixedsys because even bold characters are the same width.)

If you want a few others have a look at this page which might help.

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.
Link to comment
Share on other sites

really I am looking for a font that will be included with all Windows systems, no matter how bare. We use thin clients with XP and PC's with XP and 2000. Some of the thin clients have a "workstation" classification that have the smallest and least of everything, including available fonts. so far the thin clients have been the biggest issue, hence the code for "3 of 9" to replace the 3of9.ttf I got off the internet a few months back. the font width is a secondary issue for the text as some of the fields have as many as 40 characters, that's not too bad at 18point when the letters are I's but when they are W's. lol while I don't anticipate any string of text to be all one letter (ever) we do use all 40 characters at times.

Link to comment
Share on other sites

the new DLL works just fine. I can control size and style with the fixedsys font. awesome stuff martin. thanks again for your help.

is there any way to force the print dialogue box to be the active window? it keeps opening in the background, and the script pauses until the window is closed so no winactivate...

Edited by DangerousDan
Link to comment
Share on other sites

This looks like exactly what I need for a project I'm working on. Unfortunately I can't seem to retrieve a working file could someone please...

Check to make sure when they can still download the files from the first post and that they are not 276 bytes of a zip file with shortcut in it.

Or point me somewhere I can find the needed dll.

Thanks

AutoIt changed my life.

Link to comment
Share on other sites

This looks like exactly what I need for a project I'm working on. Unfortunately I can't seem to retrieve a working file could someone please...

Check to make sure when they can still download the files from the first post and that they are not 276 bytes of a zip file with shortcut in it.

Or point me somewhere I can find the needed dll.

Thanks

But ***???

It's meant to be 276 bytes with a shortcut in it!! Use the shortcut as a .. shortcut and it will download the files.

I'm fairly sure this question has been answered a few times in this thread already. Can you make sure you have read the quote from the first post

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.

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.
Link to comment
Share on other sites

Sorry,

Perhaps the number of times its been asked could mean a more standard method would be easier to follow. The first thing I want to do when I see something from someone known to do good work is check it out. Then read the thread after I'm more farmilar with it. You could save yourself some time and clearly some annoyance by including a ReadMe.txt or posting the links directly. Compressing a link (wich actually made it bigger) looks like a mistake at first.

Thanks for all your help,

AutoIt changed my life.

Link to comment
Share on other sites

Sorry,

Perhaps the number of times its been asked could mean a more standard method would be easier to follow. The first thing I want to do when I see something from someone known to do good work is check it out. Then read the thread after I'm more farmilar with it. You could save yourself some time and clearly some annoyance by including a ReadMe.txt or posting the links directly. Compressing a link (wich actually made it bigger) looks like a mistake at first.

Thanks for all your help,

Well you might be right of course but to me it seems reasonable to tell someone what they must do before they do it, and so I wrote the instructions above the link. I'll take up your suggestion about a readme, I should have thought of that myself. Thanks.

Even so, I find it difficult to understand that someone who wants to get printMG and unzips a file to get a link called GET_printMG would not think that perhaps there was some connection.

(The standard method you mention would presumably be to have a link to a zip file for everything rather than have to do it in 2 stages. That means either I use up all my available space on the forums with a big zip file, or I make a link directly to the download in which case I have no idea if anyone ever downloads it.)

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.
Link to comment
Share on other sites

fwiw: your instructions are difficult to understand, and the only way I figured it out was by reading the thread:)

I saw this morning that the activate window function is used in your .au3 file, any reason why it does not work consistently, as I described above? Would it possibly correct the issue if I move that while statement to my au3 file? i'll try it anyway, just thought there might be some reason behind it.

on a another note: your dll only allows printing to tray 1? even when I have the printer split to two "printers" by installing it twice and setting tray options the program will only print to tray 1. any way to set the tray?

This stuff is great, even if I have to add a second printer for some applications this is like a godsend compared to what I was using before I discovered your dll:) thanks again for your help.

Edited by DangerousDan
Link to comment
Share on other sites

fwiw: your instructions are difficult to understand, and the only way I figured it out was by reading the thread:)

I saw this morning that the activate window function is used in your .au3 file, any reason why it does not work consistently, as I described above? Would it possibly correct the issue if I move that while statement to my au3 file? i'll try it anyway, just thought there might be some reason behind it.

on a another note: your dll only allows printing to tray 1? even when I have the printer split to two "printers" by installing it twice and setting tray options the program will only print to tray 1. any way to set the tray?

This stuff is great, even if I have to add a second printer for some applications this is like a godsend compared to what I was using before I discovered your dll:) thanks again for your help.

I have tried to improve the instructions and I have added a readme to the initial download to explain what to do. If you can try it and let me know if you think it helps, or could be improved, I would be grateful.

At the moment there is no option for a second tray although it is somewhere on my todo list. Some printers have more than 2 trays. because I needs a couple of hours of continual concentration to make this change and other changes I want to make it will have to wait till the end of the year I regret.

Where do you mean that I have used "the activate window function"? I don't know what that is.

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.
Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...