Jump to content

printing using UDF and a dll


martin
 Share

Recommended Posts

Hmm, good point. I think I'll go with this approach for now, but I think I'll need to handle the issue eventually so I'll leave this issue open.

Who cares whether images that are small enough are printed in landscape or portrait.

The customer that I'm writing the script for.
Link to comment
Share on other sites

I've created a script that will take a selected JPG file and print it. If the image is smaller than the page it just prints it, but if it's larger, I rescale it to fit. I need to know the page height BEFORE I decide if I have to print landscape.

The problem is that the function requires the commands in this order:

_PrintPageOrientation()

_PrintStartPrint()

_PrintGetpageheight()

Which is the exact opposite of what I have to do. How can I get the page size before I set the orientation?

$hp = _PrintDllStart($mmssgg);etc

_PrintPageOrientation($hp,1);start in portrait
_PrintStartPrint($hp,2)
$pght = _PrintGetpageheight($hp)
$pgwd = _PrintGetpageWidth($hp) 
ConsoleWrite("1) ht, wid = " & $pght & ', ' & $pgwd & @CRLF)

;not the aspect ratio we want so
 _PrintAbort($hp);now we haven't printed anything and we can change the orientation

;change to landscape
_PrintPageOrientation($hp,0);landscape
_PrintSetDocTitle($hp,"This is a test page for wysocki")
_PrintStartPrint($hp,2)
$pght = _PrintGetpageheight($hp)
$pgwd = _PrintGetpageWidth($hp)
ConsoleWrite("2) ht, wid = " & $pght & ', ' & $pgwd & @CRLF)

;code and stuff

_PrintEndPrint($hp)


_printDllClose($hp)

EDITED 4th March 2011 to remove incorrect and probably confusing code.

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

Perfect! Thanks for a great UDF, Martin.

A pleasure, glad you like 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

Well, almost perfect...

I'm having problems with changing to landscape after I've already done a startprint. If I should decide (based upon the page and image sizes I get) that I need to abort and go landscape, the image gets rotated ok, but the height and width parameters seem to switch - but not exactly. I tried just changing the height and width parameters but there is also an issue with the offset not being calculated properly (the margins on the page I print look a bit different with the two snippets below). Evidently something is changing besides the orientation, what am I doing wrong?

This works:

#include 'printMGv2.au3'
Global $hp
Local $mmssgg
$hp = _PrintDllStart($mmssgg,'c:\progra~1\autoit3\include\printmg.dll')
if $hp = 0 then
    consolewrite("Error from dllstart = " & $mmssgg & @CRLF)
    Exit
endif
_PrintGetPrinter($hp)
_PrintPageOrientation($hp,0) ;landscape
_PrintStartPrint($hp)
$pght = _PrintGetpageheight($hp)
$pgwd = _PrintGetpageWidth($hp)
_PrintImage($hp, 'x:\testpatt.jpg' , 0, 0, $pgwd , $pght)
_PrintEndPrint($hp)
_printDllClose($hp)

This goes landscape, but the image size is wrong:

#include 'printMGv2.au3'
Global $hp
Local $mmssgg
$hp = _PrintDllStart($mmssgg,'c:\progra~1\autoit3\include\printmg.dll')
if $hp = 0 then
    consolewrite("Error from dllstart = " & $mmssgg & @CRLF)
    Exit
endif
_PrintGetPrinter($hp)
_PrintPageOrientation($hp,1)
_PrintStartPrint($hp)
$pght = _PrintGetpageheight($hp)
$pgwd = _PrintGetpageWidth($hp)
;Decided to switch to landscape...
_PrintAbort($hp)
_PrintPageOrientation($hp,0)
_PrintStartPrint($hp)
_PrintImage($hp, 'x:\testpatt.jpg' , 0, 0, $pgwd , $pght)
_PrintEndPrint($hp)
_printDllClose($hp)
Link to comment
Share on other sites

It looks to me like you are using the page width and height obtained in protrait for the image width and height in landscape. You need to get the page height and width in landscape after you set to landscape as I did (or intended to do) in my last example.

Also, the paper height is not the same as the printable height, and the margins are usually offset left to right in landscape whereas in portrait they are usually offset vertically. Of course that isn't true if your printer can print to the edge of the papare in both directions.

It's also very possible that I have confused you by giving misleading examples.

If you do this

_PrintImage($hp, 'x:\testpatt.jpg' , 0, 0, $pgwd , $pght)

then part of the image will be missing if _PrintGetXOffset or _PrintGetYOffset returns greater than zero. This is because 0,0 is the top left corner of the paper not the printable area.

The printable area top left is

_PrintGetXOffset, _PrintGetYOffset

and the bottom right is

_PrintGetXOffset + _PrintGetPageWidth, _PrintGetYOffset + _PrintGetPageHeight

All dimensions and resolutions must be obtained after setting the appropriate orientation. These are

_PrintGetPageWidth

_PrintGetPageHeight

_PrintGetHorRes

_PrintGetVertRes

_PrintGettextWidth

_PrintGetTextHeight

_PrintGetXOffset

_PrintGetYOffset

_PrintGetPaperHeight

_PrintGetPaperWidth

Because my previous post was very probably confusing I'll try to improve it a little.

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

Very usefull.

However ( there is always one isn't there),

Not all of us have color printers and we need to distinguish lines and rectangles by other than color.

Is it possible for you to add line types such as _ _ _ _ _ or _._._._ or __ __ _ __ __ etc.

or maybe we could specify line types by specifying pen up|down|up|down etc. in increments of tenths of a mm.

Also is it possible for you to add rectangle fill as ||||| or ---- or ////// or \\\\\\ etc.

I am sure you get the idea.

I am going to try and create some functions to do it but I'm sure it will execute a lot faster if it's part of the dll.

Thanks in advance for your help

StuffByDennis

Link to comment
Share on other sites

Very usefull.

However ( there is always one isn't there),

Not all of us have color printers and we need to distinguish lines and rectangles by other than color.

Is it possible for you to add line types such as _ _ _ _ _ or _._._._ or __ __ _ __ __ etc.

or maybe we could specify line types by specifying pen up|down|up|down etc. in increments of tenths of a mm.

Also is it possible for you to add rectangle fill as ||||| or ---- or ////// or \\\\\\ etc.

I am sure you get the idea.

I am going to try and create some functions to do it but I'm sure it will execute a lot faster if it's part of the dll.

Thanks in advance for your help

StuffByDennis

There is no suggestion or requirement in any of my functions that I am aware of for a colour printer; any parameter which is described as 'colour' can be taken to mean any shade of grey as well.

With the functions provided in the udf you can do all the things you want but you will need to write your own functions for the special things as you have suspected.

It is not my intention to try to provide every possible thing everyone wants, but rather to provide the basic most people need and, in general, stop short at adding features in the dll which could be added by using the functions already supplied. It might be slower in the AutoIt script but probably still a lot faster than the time to print the result. Of course, it might be slower to write the code yourself than get someone else to do it :huh2:

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

  • 11 months later...

Hi Martin

I am using this UDF now since a few years. But now I need to rewrite my code to be ready for 64bit. Can you please compile your DLL into a 64Bit Version?

If not can anybody tell me how the function PrintBytesDirect from Martin could be replaced by an API call? I guess it is WritePrinter in winspool.drv but I found no way to get this function working.

Here is an example how it works in VB

http://support.microsoft.com/kb/154078

Thanks

MF

Link to comment
Share on other sites

You need to give me more information. I assume you are having the problem when you call the _PrintSetFont function and you are running it from SciTE rather than compiled.

Can you add the following code after the line in the udf

$vDllAns = DllCall($hD...

Add this

if @error <> 0 then
 msgbox262144, 'DllCall ERROR', '@error = ' & @error)
 exit
endif

and then tell me what the value of @error is.

Also please tell me the dll version you are using and ideally post some small code which reproduces the error.

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

.... Can you please compile your DLL into a 64Bit Version?

..

Thanks

MF

Maybe later this year but I won't be doing it soon.

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

  • 8 months later...

Hi Martin.

A most useful UDF. Thank you.

I am afraid the pesky Zebra drivers are causing me problems too.

If I use _PrintSetPrinter then all functions work properly... but if I use _PrintSelectPrinter then everything just goes screwy from then on... e.g. positioning of text with _PrintText is all over the place!

Oh, and also _PrintGetPrinter doesn't return the (Zebra) printer name either way.

Any chance you might have a look at it? If I can help in any way I will be glad to.

Thanks!

Edited by adrianhudson
Link to comment
Share on other sites

adrianhudson,

I'll have a look this weekend, then I'll let you know what I think.

If it only happens with the Zebra printer I might not be able to find the problem.

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

Adrian,

I have sent you a dll in a PM. It might or might not change things.

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...
  • 2 weeks later...

Hi Martin,

Looking for AutoIt printing UDF's your UDF is one of the 3 I found.

I am programming a labelprinting program with Zedna's barcode examples.

To print correctly on a label, I have to change the printer's default papersize manually for every label.

My workaround is to create a printer for everylabel size I want to print and choose a differnt Windows printer depending on the labelsize I need.

When downloading your UDF, I saw that the latest additions were: _PrintPaperWidth, _PrintPaperHeigh.

However, I can not find them in the Autoit-files you provided.

Can one set the PaperWidth and Height to e.g. 57mm x 19mm with the above commands,

so I can use one Window printer, but change the papersize before printing?

Link to comment
Share on other sites

Hi Firefox,

I really hope you are wrong ;)

When using a program like ZebraDesigner or NiceLabel, I am able to change (create defintion) directly from the program.

(No need to define a whole printerdevice for each label size).

So how do "they" do it?

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