Jump to content

Recommended Posts

Posted (edited)

I really hope you are wrong ;)

Nop, I have listed the DLL functions like I said, and there is nothing to change the paper size.

So how do "they" do it?

They have included the functions you are looking for in their library, simple as that.

Check if there is a newer version of the DLL.

Br, FireFox.

Edited by FireFox
Posted

I am not spending any time on AutoIt at the moment. I'll have a look to see if I can add setting the page size but if I can't do it within about an hour on Monday then it won't be done for some time.

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.
  • 5 months later...
Posted

Hello Martin,

Tx for your work on the dll. 

I just have a little problem with the _PrintSetFont function. Some colors like black or gray are fine. But if i try to use for instance red(FF0000) i get some kind of blue.

Im using 32bit autoit on 64bit W7

Local $red = 0xFF0000
_PrintSetFont($hp,'Courier New', 12, $red,'bold')

Do you have an idea what could be wrong?

  • Moderators
Posted

jorgev,

At a guess the UDF uses BGR and not RGB - try it this way:

Local $red = 0x0000FF
Does that fix it? :)

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

  • Moderators
Posted

jorgev,

Glad I could help. :)

You might find this post useful. ;)

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

  • 2 months later...
Posted

number of copy can be sent to the printer?

#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)
    Exit
endif

$newselect = _PrintSelectPrinter($hp, "AAXXCCC")
; $newselect = _PrintSelectNUMBER OF COPY ($hp, "30") ??????????????

_PrintPageOrientation($hp,1);landscape
_PrintSetDocTitle($hp,"This is a test page for PDFcreator No. 01")
_PrintStartPrint($hp)
_PrintImage($hp,"test-0.jpg",1,1,400,400)
_PrintEndPrint($hp)
_PrintNewPage($hp);
_printDllClose($hp)

I like IT: php, mysql, codeingiter, css, jquery and AUTOIT

Posted

The number of copies is passed as an optional 2nd parameter to _PrintStartPrint()

So you just replace the line

_PrintStartPrint($hp)

with

Local $NumberOfCopies = 72 ; set the number of copies you need to print

_PrintStartPrint($hp, $NumberOfCopies)

  • 1 month later...
Posted

Quick one is it possible to Print a website to PDF and saved in a predetermined folder using autoit.

I know i sound kinda like sooooooo newbeeeee well I am when it comes to Aitoit.

Regards,

Posted (edited)

You can use the _IE... udf to save the html to a file. Not the thread here to deal with that.

You can use this print udf to set the default printer to a pdf printer.

Then you could use james3ng's function to print the webpage

;james3mg function
Func _PrintHTML($p_file);james3mg print function
    If FileExists($p_file) Then RunWait(@COMSPEC&' /c rundll32.exe ' & @SystemDir & '\mshtml.dll,PrintHTML "' & $p_file & '"',@TempDir,@SW_HIDE)
EndFunc

Also, have a look at Taietels' udf to create pdfs

EDIT: Added following

You can set the default printer using these function rather than use my UDF and the dll which is overkill for just doing this.

;don't know where these functions came from or who wrote them
 
Func PrinterSetAsDefault($PrinterName)
    Local $result, $strComputer, $colEvents,$objWMIService
 
    $CurrentPrinter = GetDefaultPrinter()
    If $currentPrinter = $PrinterName Then Return

    $result = 0
    $strComputer = "."
    $objWMIService = ObjGet("winmgmts:\\" & $strComputer & "\root\cimv2")
    $colEvents = $objWMIService.ExecQuery _
            (StringFormat('Select * From Win32_Printer')); Where DeviceID = "%s"', $PrinterName));TRUE
   
    For $objPrinter in $colEvents
        If $objPrinter.DeviceID = $PrinterName Then
            $objPrinter.SetDefaultPrinter()
            $result = 1
        EndIf

    Next
 
    Return $result

EndFunc
 
Func GetDefaultPrinter()

    Local $result, $strComputer, $colEvents
    $result = ''

    $strComputer = "."
    $objWMIService = ObjGet("winmgmts:\\" & $strComputer & "\root\cimv2")

    $colEvents = $objWMIService.ExecQuery _
            ("Select * From Win32_Printer Where Default = TRUE");TRUE
   

    For $objPrinter in $colEvents
        $result = $objPrinter.DeviceID
    Next

    Return $result
EndFunc
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.
Posted

 

You can use the _IE... udf to save the html to a file. Not the thread here to deal with that.

You can use this print udf to set the default printer to a pdf printer.

Then you could use james3ng's function to print the webpage

;james3mg function
Func _PrintHTML($p_file);james3mg print function
    If FileExists($p_file) Then RunWait(@COMSPEC&' /c rundll32.exe ' & @SystemDir & '\mshtml.dll,PrintHTML "' & $p_file & '"',@TempDir,@SW_HIDE)
EndFunc

Also, have a look at Taietels' udf to create pdfs

EDIT: Added following

You can set the default printer using these function rather than use my UDF and the dll which is overkill for just doing this.

;don't know where these functions came from or who wrote them
 
Func PrinterSetAsDefault($PrinterName)
    Local $result, $strComputer, $colEvents,$objWMIService
 
    $CurrentPrinter = GetDefaultPrinter()
    If $currentPrinter = $PrinterName Then Return

    $result = 0
    $strComputer = "."
    $objWMIService = ObjGet("winmgmts:\\" & $strComputer & "\root\cimv2")
    $colEvents = $objWMIService.ExecQuery _
            (StringFormat('Select * From Win32_Printer')); Where DeviceID = "%s"', $PrinterName));TRUE
   
    For $objPrinter in $colEvents
        If $objPrinter.DeviceID = $PrinterName Then
            $objPrinter.SetDefaultPrinter()
            $result = 1
        EndIf

    Next
 
    Return $result

EndFunc
 
Func GetDefaultPrinter()

    Local $result, $strComputer, $colEvents
    $result = ''

    $strComputer = "."
    $objWMIService = ObjGet("winmgmts:\\" & $strComputer & "\root\cimv2")

    $colEvents = $objWMIService.ExecQuery _
            ("Select * From Win32_Printer Where Default = TRUE");TRUE
   

    For $objPrinter in $colEvents
        $result = $objPrinter.DeviceID
    Next

    Return $result
EndFunc

 

@ Martin.

Thank you for the direction. I have been away from scripting for a couple of days.

I tried the codes and they it works. (here is my codes)

;james3mg function
Local $PrinterName = "PDFCreator"
Local $p_file = "file path\Portfolio.htm"
PrinterSetAsDefault($PrinterName)
_PrintHTML($p_file)

Func _PrintHTML($p_file);james3mg print function
    If FileExists($p_file) Then RunWait(@COMSPEC&' /c rundll32.exe ' & @SystemDir & '\mshtml.dll,PrintHTML "' & $p_file & '"',@TempDir,@SW_HIDE)
EndFunc


;don't know where these functions came from or who wrote them

; setting the default printer
Func PrinterSetAsDefault($PrinterName)
    Local $result, $strComputer, $colEvents,$objWMIService

    $CurrentPrinter = GetDefaultPrinter()
    If $currentPrinter = $PrinterName Then Return

    $result = 0
    $strComputer = "."
    $objWMIService = ObjGet("winmgmts:\\" & $strComputer & "\root\cimv2")
    $colEvents = $objWMIService.ExecQuery _
            (StringFormat('Select * From Win32_Printer')); Where DeviceID = "%s"', $PrinterName));TRUE

    For $objPrinter in $colEvents
        If $objPrinter.DeviceID = $PrinterName Then
            $objPrinter.SetDefaultPrinter()
            $result = 1
        EndIf

    Next

    Return $result

EndFunc

Func GetDefaultPrinter()

    Local $result, $strComputer, $colEvents
    $result = ''

    $strComputer = "."
    $objWMIService = ObjGet("winmgmts:\\" & $strComputer & "\root\cimv2")

    $colEvents = $objWMIService.ExecQuery _
            ("Select * From Win32_Printer Where Default = TRUE");TRUE


    For $objPrinter in $colEvents
        $result = $objPrinter.DeviceID
    Next

    Return $result
EndFunc

Once again thanks.

  • 8 months later...
Posted (edited)

Hello Martin,

I will say, very amazing job here. I am just starting to use this and I'm not sure if it's my sheer ignorance with this UDF or something that's missing, but I'm getting an error when trying to use this UDF:

"C:\Program Files (x86)\AutoIt3\Include\printMGv2.au3" (216) : ==> Variable used without being declared.:
$vDllAns = DllCall($hDll, 'int', 'SetPrinter')
^ ERROR

My code is:

#include <printMGv2.au3>

Local $hp, $mmssgg
 
$hp = _PrintDLLStart($mmssgg)
 
HotKeySet("{F2}", "Print")
HotKeySet("{ESC}", "Quit")
 
While 1
WEnd
 
Func Print()
    If $hp = 0 Then
        MsgBox(0, "", "Error from dllstart = " & $mmssgg & @CRLF)
        Return
    EndIf
    _PrintSetPrinter($hp)
EndFunc
 
Func Quit()
    _PrintDLLClose($hp)
    Exit
EndFunc
Edited by MikahS

Snips & Scripts


My Snips: graphCPUTemp ~ getENVvars
My Scripts: Short-Order Encrypter - message and file encryption V1.6.1 ~ AuPad - Notepad written entirely in AutoIt V1.9.4

Feel free to use any of my code for your own use.                                                                                                                                                           Forum FAQ

 

Posted (edited)

I had:

Opt("MustDeclareVars", 1)
in my original script, and that is what fixed it by taking it out. The above script works. Edited by MikahS

Snips & Scripts


My Snips: graphCPUTemp ~ getENVvars
My Scripts: Short-Order Encrypter - message and file encryption V1.6.1 ~ AuPad - Notepad written entirely in AutoIt V1.9.4

Feel free to use any of my code for your own use.                                                                                                                                                           Forum FAQ

 

  • 1 month later...
  • 5 months later...
  • 2 years later...
Posted (edited)

Just want to update from a user's side:

This dll & udf is still working in 2017 using Win 10 current releases and it still seems to me the best option for complex printing tasks handled by AutoIt.

NONETHELESS there are a few caveats:

1) Since Martin never had time to implement a "set page size" function, this REALLY calls for some additional work for anyone not working with A4 paper sizes! I use this DLL extensively to work with label printers and I can only tell you all the drivers I have used (TMC, Zebra, Novexx, Avery) all had problems with the paper size. It drives you nuts unless you know what to do: Don't use the function to programmatically chose the printer. It will often chose a completely wrong paper size, even if you set everything in the printer defaults (of printer and driver and everywhere). So the quite strange way to overcome this is to use the alternative function and call up the printer selection window. I then wrote a small compiled AutoIt script that is called BEFORE the printer selection function and waits for the printer dialog to open. It then fills out all the necessary values for label sizes, printer head temperature, etc. and closes the windows again. So the user only sees a few windows (printer properties) quickly popping up and closing again. I am afraid (and quite sure!) this is the only way to get Martin's dll to work with label paper sizes in modern Windows versions. For me it now works very reliably.

2) I have found that if you rename your printer, the function to programmatically set the printer sometimes doesn't work. It is a very weird behavior that I can't completely explain, but it drives you nuts if you think you have chosen the correct printer, but actually you have not. A work around here is also the way I have described in 1).

3) YOU NEED TO HAVE A STANDARD PRINTER SET. I came across a Windows Installation where one user has no standard printer set (Win10) and the DLL crashes when selecting a printer (both ways). Just define a standard printer and the crash is gone. 

Good luck!

Jandings

Edited by jandings
  • 2 weeks later...
  • 3 months later...
Posted
On 03/07/2017 at 11:47 AM, jandings said:

Just want to update from a user's side:

This dll & udf is still working in 2017 using Win 10 current releases and it still seems to me the best option for complex printing tasks handled by AutoIt.

NONETHELESS there are a few caveats:

1) Since Martin never had time to implement a "set page size" function, this REALLY calls for some additional work for anyone not working with A4 paper sizes! I use this DLL extensively to work with label printers and I can only tell you all the drivers I have used (TMC, Zebra, Novexx, Avery) all had problems with the paper size. It drives you nuts unless you know what to do: Don't use the function to programmatically chose the printer. It will often chose a completely wrong paper size, even if you set everything in the printer defaults (of printer and driver and everywhere). So the quite strange way to overcome this is to use the alternative function and call up the printer selection window. I then wrote a small compiled AutoIt script that is called BEFORE the printer selection function and waits for the printer dialog to open. It then fills out all the necessary values for label sizes, printer head temperature, etc. and closes the windows again. So the user only sees a few windows (printer properties) quickly popping up and closing again. I am afraid (and quite sure!) this is the only way to get Martin's dll to work with label paper sizes in modern Windows versions. For me it now works very reliably.

2) I have found that if you rename your printer, the function to programmatically set the printer sometimes doesn't work. It is a very weird behavior that I can't completely explain, but it drives you nuts if you think you have chosen the correct printer, but actually you have not. A work around here is also the way I have described in 1).

3) YOU NEED TO HAVE A STANDARD PRINTER SET. I came across a Windows Installation where one user has no standard printer set (Win10) and the DLL crashes when selecting a printer (both ways). Just define a standard printer and the crash is gone. 

Good luck!

Jandings

Could you post your script? I'm on a project and i'm having this same problem!

  • 3 weeks later...
Posted (edited)

+1, i also need to overcome page size. Whatever printing defaults i set on printer properties, printing with printMG.dll always uses A4 size.

Using auto-select printer:

_PrintSelectPrinter($hp, $printer)

No way to get it working properly. If i change _PrintSelectPrinter to

$newselect = _PrintSetPrinter($hp)

.. and from there manually changing page size in printer properties - everything works, then pagesize is correct.

Edited by juzis28
  • 1 month later...
Posted

This is the best option UDF for me, when i have a complex printing tasks.

Unfortunately, the UDF does not support Unicode Encoding. All text is converted to ANSI before printing.

Hope to see an update of dll and this UDF, supporting multi-encoding in the future. :)

Thanks!

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
  • Recently Browsing   0 members

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