Jump to content

printing using UDF and a dll


martin
 Share

Recommended Posts

Can this be used to print IE websites? I'm trying to automate printing IE webpages.

See my reply in your thread in General Support.

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

  • 6 months later...

I have been using this for a long time to print labels, Kudos

Just downloaded the November 2009 edition, to fix a label printer problem I was having in Windows 7 as I am trying to port my code to a Windows 7 environment (with bug fixes) :mellow:

The November 2009 edition, fixed my problem, but added another.

For some reason _printselectprinter is changing my default printer to the printer of I want to print to. It's easy enough to program around this, but this doesn't match what the headers say _printselectprinter claims to do. This problem is not OS related as it broke in both XP and Win7.

If you can fix this, I will appreciate it, The work around is to get _printgetprinter before selecting it, then select it back when down. Not pretty.

Thank you

Link to comment
Share on other sites

I have been using this for a long time to print labels, Kudos

Just downloaded the November 2009 edition, to fix a label printer problem I was having in Windows 7 as I am trying to port my code to a Windows 7 environment (with bug fixes) :mellow:

The November 2009 edition, fixed my problem, but added another.

For some reason _printselectprinter is changing my default printer to the printer of I want to print to. It's easy enough to program around this, but this doesn't match what the headers say _printselectprinter claims to do. This problem is not OS related as it broke in both XP and Win7.

If you can fix this, I will appreciate it, The work around is to get _printgetprinter before selecting it, then select it back when down. Not pretty.

Thank you

I will investigate. Do you mean that _printselectprinter changes the deafult printer to the printer you select? That does sound familiar; I think I did that in an attempt to get the function to work on W2000. It should be easy to fix but give me a couple of days.

What was the problem you had that the Nov 2009 version fixed?

EDIT:

Here is a new version. I have added a new optional parameter to _PrintSelectPrinter which is false by default. If set to true it will make the selected printer the default printer.

Could you test it hazed? Or anyone else.

UDF + dll to test

If it's ok then I will remove it from this post and update the downloads which have a link in the first post.

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

I will investigate. Do you mean that _printselectprinter changes the deafult printer to the printer you select? That does sound familiar; I think I did that in an attempt to get the function to work on W2000. It should be easy to fix but give me a couple of days.

What was the problem you had that the Nov 2009 version fixed?

I will test the new code tomorrow, but after investigating, the nov 2009 did not fix my problem. Unfortunately Zebra's latest print driver, when I select it does not pull the customized Label size, but Pagesize = "A4" or something to that. So I need to be able to set a Size width and Height after I open it. _printsetpaperwidth ...etc.

The old XP drivers I have work great, the size & width come from the Printer Defaults. Unfortunately, they won't load on Win 7.

If you know how to do this externally of your dll, I could use this info. :mellow:

Edited by hazed
Link to comment
Share on other sites

EDIT:

Here is a new version. I have added a new optional parameter to _PrintSelectPrinter which is false by default. If set to true it will make the selected printer the default printer.

Could you test it hazed? Or anyone else.

UDF + dll to test

If it's ok then I will remove it from this post and update the downloads which have a link in the first post.

The Switch worked, if True then it sets the default printer, if False it just selects it.

Still having issues with zebra window drivers...and Page size...etc.

Link to comment
Share on other sites

Martin~

I think I found a bug, which is why I'm having problems with the zebra drivers.

I'll enclose my code:

Func startprinter($cpy)
    $hp = _PrintDllStart($mmssgg);this must always be called first
    If $hp = 0 Then
        ConsoleWrite("Error from dllstart = " & $mmssgg & @CRLF)
        Exit
    EndIf
    $printername = $prtr
    $printer = _PrintSelectPrinter($hp, $printername, False)
    ;$printer = -1
    If $printer = -1 Then
        _PrintSetPrinter($hp)
    EndIf
    _PrintStartPrint($hp, $cpy)
    $pght = _PrintGetpageheight($hp) - _PrintGetYOffset($hp)
    $pgwd = _PrintGetpageWidth($hp) ;- _PrintGetXOffset($hp) ; adjusted elsewhere
EndFunc   ;==>startprinter

Notice the commented out "$printer = -1" line. Well the logic goes.

I select the printer, $printername, The default printer setup is loaded

if Select errors, then I open a SetPrinter Dialog.

Startprint with a specified # of copies.

What happens is, Printer is selected, defaults page settings are all messed up and Startprint only prints 1 copy, no matter what.

If I uncomment the "$printer = -1" line and force a setPrinter dialog.

and just select it, as _PrintSelectPrinter($hp, $printername, False) has it selected at this time.

Prints the right number of copies and the Page settings are correct.

If I'm doing something incorrect, please advise

Thank you

Link to comment
Share on other sites

Martin~

I think I found a bug, which is why I'm having problems with the zebra drivers.

I'll enclose my code:

Func startprinter($cpy)
    $hp = _PrintDllStart($mmssgg);this must always be called first
    If $hp = 0 Then
        ConsoleWrite("Error from dllstart = " & $mmssgg & @CRLF)
        Exit
    EndIf
    $printername = $prtr
    $printer = _PrintSelectPrinter($hp, $printername, False)
    ;$printer = -1
    If $printer = -1 Then
        _PrintSetPrinter($hp)
    EndIf
    _PrintStartPrint($hp, $cpy)
    $pght = _PrintGetpageheight($hp) - _PrintGetYOffset($hp)
    $pgwd = _PrintGetpageWidth($hp) ;- _PrintGetXOffset($hp) ; adjusted elsewhere
EndFunc ;==>startprinter

Notice the commented out "$printer = -1" line. Well the logic goes.

I select the printer, $printername, The default printer setup is loaded

if Select errors, then I open a SetPrinter Dialog.

Startprint with a specified # of copies.

What happens is, Printer is selected, defaults page settings are all messed up and Startprint only prints 1 copy, no matter what.

If I uncomment the "$printer = -1" line and force a setPrinter dialog.

and just select it, as _PrintSelectPrinter($hp, $printername, False) has it selected at this time.

Prints the right number of copies and the Page settings are correct.

If I'm doing something incorrect, please advise

Thank you

I don't have that problem but I don't think you are doing anything incorrectly. What OS are you using? Are the paper sizes different for the different printers?

Page height is given by _PrintGetpageheight. The top of the page for printing is at _PrintGetYoffset.

You should be able to print from heights Yoffset to Yoffset + PageHeight. Ie, if you draw a line from 0 at the top to Paperht at the bottom the length of the line will be pageheight starting at yoffset below the top of the paper.

Offsets change depending on printer and paper orientation.

Offsets obtained before the correct printer is selected, or before the correct orientation is selected are likely to be wrong.

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

I don't have that problem but I don't think you are doing anything incorrectly. What OS are you using? Are the paper sizes different for the different printers?

Page height is given by _PrintGetpageheight. The top of the page for printing is at _PrintGetYoffset.

You should be able to print from heights Yoffset to Yoffset + PageHeight. Ie, if you draw a line from 0 at the top to Paperht at the bottom the length of the line will be pageheight starting at yoffset below the top of the paper.

Offsets change depending on printer and paper orientation.

Offsets obtained before the correct printer is selected, or before the correct orientation is selected are likely to be wrong.

I'm using Win7 X64. compiling Autoit code in 32bit Mode. The Zebra Drivers I believe (even though they are Microsoft Certified) Does not act correctly. You sample code where you select a printer, then check the printer you selected, always comes back as "None" if I chose Zebra, but comes back correctly when I choose the HP Laser Printer.

I just find it strange, that it works if I force a SetPrinter command, but not a Selectprinter.

I also find it strange that under XP x32 with old (non-Microsoft certified) drivers...the one that came with the printer works great. But I have to Modernize to the Windows 7 X64 world and these new zebra print drivers aren't working and Zebra hasn't given me much help, other than memtioning that the drivers passed "Microsoft Certification".

I might try to load a machine with Win7 X32 and test, but that will take a day or two :mellow:

Edited by hazed
Link to comment
Share on other sites

It's something with these zebra drivers, I used the "New" Zebra (MS certified) drivers on an XP x32 and I get the same thing, other than _printgetprinter returns the selected printer correctly.

but for it to work, I am forced to Hit an "OK" on a _printsetPrinter.

I'm not sure what's going on with this driver. The old XP drivers works beautiful.

Is their a way to run _printsetPrinter automatically selecting [OK] (possibly all hidden)

I know I'm grasping at straws, but this Zebra driver is terrible.

Link to comment
Share on other sites

It's something with these zebra drivers, I used the "New" Zebra (MS certified) drivers on an XP x32 and I get the same thing, other than _printgetprinter returns the selected printer correctly.

but for it to work, I am forced to Hit an "OK" on a _printsetPrinter.

I'm not sure what's going on with this driver. The old XP drivers works beautiful.

Is their a way to run _printsetPrinter automatically selecting [OK] (possibly all hidden)

I know I'm grasping at straws, but this Zebra driver is terrible.

Well the solution is 3rd party drivers. (Free) SeaGullscientific.com has drivers for Label printers that work with Windows programs. The only issue I had is they print upside down from the Zebra universal drivers that work on XP. The 180 degree portrait needs to be selected on the default print setting.

Everything now works the same on XP as it does Windows 7 as far as the printing goes.

Again, thanks for the help and this UDF and .dll has made debugging this easier. Thank you.

Link to comment
Share on other sites

  • 1 month later...

Hi,

I have downloaded the latest archive "printMGv2_67".

I am trying to create a simple Cheque (check) printing utility.

The Cheque paper sheet is 200mm wide & 80mm height.

How can I define the above paper size independent of the printer's default setting which may be "A4" or "Letter" or "Legal" in some cases.

I would like to create a new paper of size 200mm wide & 80mm height, printing in landscape mode.

Pls help!

Thx

Sanjay

Link to comment
Share on other sites

  • 2 weeks later...

Hi,

I have downloaded the latest archive "printMGv2_67".

I am trying to create a simple Cheque (check) printing utility.

The Cheque paper sheet is 200mm wide & 80mm height.

How can I define the above paper size independent of the printer's default setting which may be "A4" or "Letter" or "Legal" in some cases.

I would like to create a new paper of size 200mm wide & 80mm height, printing in landscape mode.

Pls help!

Thx

Sanjay

Hi there just wondering if you had any luck yet?

Link to comment
Share on other sites

Hi there just wondering if you had any luck yet?

Hi daserraf,

I will not be doing any work on this udf for a while. Maybe in September.

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

  • 2 months later...

hi martin !

i downloaded the latest version (printmg.dll 2.55) and 'SelectPrinter' does not work anymore. it causes an autoit crash (with drwatson). i use xp sp3.

luckily i have an old version, 2.48, which works fine, but 'SelectPrinter' changes the default printer.

maybe you can offer the last stable version of your dll (with working 'SelectPrinter'), or maybe a selection of all versions, so that at least the new downloaders will have the chance to use you fantastic udf ?

thank you !

j.

edit: i just noticed you uploaded this version in october 2010, so i might be the first to encounter this problem.

Edited by jennico
Spoiler

I actively support Wikileaks | Freedom for Julian Assange ! | Defend freedom of speech ! | Fight censorship ! | I will not silence.OixB7.jpgDon't forget this IP: 213.251.145.96

 

Link to comment
Share on other sites

hi martin !

i downloaded the latest version (printmg.dll 2.55) and 'SelectPrinter' does not work anymore. it causes an autoit crash (with drwatson). i use xp sp3.

luckily i have an old version, 2.48, which works fine, but 'SelectPrinter' changes the default printer.

maybe you can offer the last stable version of your dll (with working 'SelectPrinter'), or maybe a selection of all versions, so that at least the new downloaders will have the chance to use you fantastic udf ?

thank you !

j.

edit: i just noticed you uploaded this version in october 2010, so i might be the first to encounter this problem.

Oh, thanks for telling me jennico, I'll have a look at it tonight.

I think that there was a version to detect W2K and the only way I could get SelectPrinter to work for that OS was to change the default printer.

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

did you check 'SelectPrinter' ? can you reproduce the bug ?

i can work around the default printer problem, but the crashing is annoying.

:graduated: j.

Spoiler

I actively support Wikileaks | Freedom for Julian Assange ! | Defend freedom of speech ! | Fight censorship ! | I will not silence.OixB7.jpgDon't forget this IP: 213.251.145.96

 

Link to comment
Share on other sites

hi martin !

i downloaded the latest version (printmg.dll 2.55) and 'SelectPrinter' does not work anymore. it causes an autoit crash (with drwatson). i use xp sp3.

luckily i have an old version, 2.48, which works fine, but 'SelectPrinter' changes the default printer.

maybe you can offer the last stable version of your dll (with working 'SelectPrinter'), or maybe a selection of all versions, so that at least the new downloaders will have the chance to use you fantastic udf ?

thank you !

j.

edit: i just noticed you uploaded this version in october 2010, so i might be the first to encounter this problem.

I don't get an error with either version. The only difference between them is that I added a parameter in dll V2.54 so it should be used with the UDF V2.68 or later if you don't want the selected printer to become the default. If you set the '$fSetAsDefault' parameter to false or omit it then the function in the dll behaves exactly as the versions before 2.54. Are you setting the second parameter to True? If you are then it is my function for setting the deafult printer which is causing the problem for you, but for me it works OK (XP SP3). What OS are you running on?

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

Hello Martin,

many thanks for this very nice and usefull UDF. Today I have downloaded the latest version from you homepage and try to implement a print job to a script. The embedded example works fine so far but when I try to select an existing printer (e. g. PDFCreator) that is not the default one the script crashes. This happens allways, when I use _PrintSelectPrinter($DC,$PrinterName).

When I do no change (no _PrintSelectPrinter() or _PrintSetPrinter()) and create a print job it works fine. When I use _PrintSetPrinter($DC) to change the printer it works fine, too. But I need to change the printer without an user interaction so I had used _PrintSelectPrinter() but this causes the crash.

The DLL version is 2.55, the version of the UDF is 2.67, AutoIt version is 3.3.6.1. My OS is Win7 Ultimate (32Bit).

Have you got an idea how to fix this issue?

Many thanks in advance,

best regards

TheDude

Link to comment
Share on other sites

Hello Martin,

many thanks for this very nice and usefull UDF. Today I have downloaded the latest version from you homepage and try to implement a print job to a script. The embedded example works fine so far but when I try to select an existing printer (e. g. PDFCreator) that is not the default one the script crashes. This happens allways, when I use _PrintSelectPrinter($DC,$PrinterName).

When I do no change (no _PrintSelectPrinter() or _PrintSetPrinter()) and create a print job it works fine. When I use _PrintSetPrinter($DC) to change the printer it works fine, too. But I need to change the printer without an user interaction so I had used _PrintSelectPrinter() but this causes the crash.

The DLL version is 2.55, the version of the UDF is 2.67, AutoIt version is 3.3.6.1. My OS is Win7 Ultimate (32Bit).

Have you got an idea how to fix this issue?

Many thanks in advance,

best regards

TheDude

Hi Martin

this is exactly same problem as mine.

i use win xp sp3, same as you.

'$fSetAsDefault' parameter to false or omit it then the function in the dll behaves exactly as the versions before 2.54

i use the (newest) DLL version 2.55, $sUDFVersion = 'PrintMG.au3 V2.64'

i do not have v 2.54.

Func _PrintSelectPrinter($hDll, $PrinterName)
    $vDllAns = DllCall($hDll, 'int', 'SelectPrinter', 'str', $PrinterName)
    If @error = 0 Then
        Return $vDllAns[0]
    Else
        Return -1
    EndIf

EndFunc   ;==>_PrintSelectPrinter

there is no second param, that's why it crashes ?

cheers j.

Spoiler

I actively support Wikileaks | Freedom for Julian Assange ! | Defend freedom of speech ! | Fight censorship ! | I will not silence.OixB7.jpgDon't forget this IP: 213.251.145.96

 

Link to comment
Share on other sites

.. there is no second param, that's why it crashes ? cheers j.

Probably. The current function in the UDF should be

;needs dll v2.54 or later 
Func _PrintSelectPrinter($hDll, $PrinterName, $fSetAsDefault=false) 
    $vDllAns = DllCall($hDll, 'int', 'SelectPrinter', 'str', $PrinterName,'int',$fSetAsDefault) 
    If @error = 0 Then
        Return $vDllAns[0] 
    Else
        Return -1
  EndIf  EndFunc   ;==>_PrintSelectPrinter

I'll check what gets downloaded because it looks like I've messed up somewhere. EDIT Yes. I have changed the download to correct the fact that the UDF was an old version and had various things missing. I can't edit my old posts for some reason so get the corrected version from here.

Or get the udf here (will be removed from this post once I can change the first post OK)

(Attachment removed as it is now available from the link in the first post.)

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

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...