Jump to content

printing using UDF and a dll


martin
 Share

Recommended Posts

hmm,

it seems that gdi32.dll ('GetDeviceCaps','CreateFont') offers all that is needed without extra dll, doesn't it ?

it enables you to print exact positions and "real" fontsizes, moreover, with a DC handle to the monitor you can display the printjob with (almost) exact ("real") dimensions on the screen.

this is very very interesting. it just awaits someone to code UDFs for it (GRS has already begun to do it).

but - i still don't see how to save a print to file...

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,

if you could make a printtofile function, that would be nice. though i admit it might be complicated (needs to be .rtf format, i guess ?). but i definitely think this should be featured.

my idea with the protocoll was just loudly thinking how this could be managed by normal means, if you do not make a printtofile command. but this is not what i meant primarily.

another question: how can i set a color to the text ? i can colorate a line, but not the text ?

thanx j.

You set the line colour with _PrintSetLineCol.

You set the font colour with _PrintSetFont which also lets you set the font, the font size and the font style. _PrintText allows you to specify the angle.

I assume that if you print to file then you would save it as a bmp or jpg. Then if you want to print it later you just print that image. I don't think it would be complicated, but how would you use it or what would you use it for?

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

Hello

Just wanna say I think this is really great, and I hope these functions will be fully integrated in auto-it (as include).

Anyway, I found a small bug - When I press "Cancel" to a print, the printer still prints it?

And, I would like to know if there is any kind of documentation of the calls you can make and parametres that they can be called with?

Link to comment
Share on other sites

Hello

Just wanna say I think this is really great, and I hope these functions will be fully integrated in auto-it (as include).

I'm glad you like it.

This udf and dll will never be included in the AuoIt package. Many AutoIt printing functions have been developed which use the Windows API. At the moment this udf is possibly easier to use but hopefully that will not always be the case.

Anyway, I found a small bug - When I press "Cancel" to a print, the printer still prints it?

I need much more information to give a sensible reply ^_^.

Where are you pressing Cancel? What function did you call which showed the Cancel button and what code have you written to allow for the Cancel button being pressed? Which versions are you using? Can you show any sample code which reproduces the problem?

And, I would like to know if there is any kind of documentation of the calls you can make and parametres that they can be called with?

The UDF has information for the functions, you just need to read it and then experiment with the functions and ask if you get stuck.
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

Hi Martin,

I'm using your UDF for printing.

But I have now the following problem:

I'm printing an image on a page.

The size of the image is variable and depending on the

size I'm setting the Page Orientation to landscape oder portrait.

But I'd like to know the Page size and the X/Y-Offset of the printer.

The problem is, that I can't ask for this information if the _PrintStartPrint($DLL) is not

set! Because, if I set _PrintStartPrint($DLL) then I can't change the Page Orientation.

Is it possible to use _PrintStartPrint($DLL) and get the information, and then abort this

printing job? Because, if I simply write _PrintEndPrint($DLL) then it sends an empty

print job (thats ok since it is its function). Can I abort this empty printjob in the script or

"load" the printer, so I can get my information?

Here is my Code for this part:

;~  _PrintStartPrint($hp)

    $PageHeight = _PrintGetPageHeight($hp)
    $PageWidth = _PrintGetPageWidth($hp)
    $PageXoffset = _PrintGetXOffset($hp)
    $PageYoffset = _PrintGetYOffset($hp)
    
;~  _PrintEndPrint($hp)

    _PrintStartPrint($hp)

        $PrintImageWid = $ImageWid / ($dpi/2.54) * 100
        If $PrintImageWid > 1900 Then 
            If $PrintImageWid > 2770 Then $PrintImageWid = 2770 
            $PrintImageHt = $ImageHt / ($dpi/2.54) * 100
            If $PrintImageHt > 1700 Then $PrintImageHt = 1700
            $logo_x = 2500
            _PrintPageOrientation($hp,0)
        Else        
            $PrintImageHt = $ImageHt / ($dpi/2.54) * 100
            If $PrintImageHt > 2770 Then $PrintImageHt = 2770
            $logo_x = 1650
            _PrintPageOrientation($hp,1)
        EndIf

    _PrintImage($hp, $CaptureFile, 100, 300, $PrintImageWid, $PrintImageHt)

    _PrintEndPrint($hp)
    _printDllClose($hp)

I'm sorry for my bad english

Thanks

Prajoss

Edited by Prajoss
Link to comment
Share on other sites

Hi Martin,

I'm using your UDF for printing.

But I have now the following problem:

I'm printing an image on a page.

The size of the image is variable and depending on the

size I'm setting the Page Orientation to landscape oder portrait.

But I'd like to know the Page size and the X/Y-Offset of the printer.

The problem is, that I can't ask for this information if the _PrintStartPrint($DLL) is not

set! Because, if I set _PrintStartPrint($DLL) then I can't change the Page Orientation.

Is it possible to use _PrintStartPrint($DLL) and get the information, and then abort this

printing job? Because, if I simply write _PrintEndPrint($DLL) then it sends an empty

print job (thats ok since it is its function). Can I abort this empty printjob in the script or

"load" the printer, so I can get my information?

Here is my Code for this part:

;~  _PrintStartPrint($hp)

    $PageHeight = _PrintGetPageHeight($hp)
    $PageWidth = _PrintGetPageWidth($hp)
    $PageXoffset = _PrintGetXOffset($hp)
    $PageYoffset = _PrintGetYOffset($hp)
    
;~  _PrintEndPrint($hp)

    _PrintStartPrint($hp)

        $PrintImageWid = $ImageWid / ($dpi/2.54) * 100
        If $PrintImageWid > 1900 Then 
            If $PrintImageWid > 2770 Then $PrintImageWid = 2770 
            $PrintImageHt = $ImageHt / ($dpi/2.54) * 100
            If $PrintImageHt > 1700 Then $PrintImageHt = 1700
            $logo_x = 2500
            _PrintPageOrientation($hp,0)
        Else        
            $PrintImageHt = $ImageHt / ($dpi/2.54) * 100
            If $PrintImageHt > 2770 Then $PrintImageHt = 2770
            $logo_x = 1650
            _PrintPageOrientation($hp,1)
        EndIf

    _PrintImage($hp, $CaptureFile, 100, 300, $PrintImageWid, $PrintImageHt)

    _PrintEndPrint($hp)
    _printDllClose($hp)

I'm sorry for my bad english

Thanks

Prajoss

Hi Prajoss, welcome to the AutoIt forums ^_^

I'm surprised I haven't included an Abort function already.

Can you add this to the UDF

;aborts printing
;returns 0 on success
;returns -1 if not already printing
;returns -2 if could not execute the dll call
 Func _PrintAbort($hDll)
     $vDllAns = DllCall($hDll, 'int', 'AbortPrint');
     If @error = 0 Then
         Return $vDllAns[0]
     Else
         Return -2
     EndIf
    
 
 EndFunc  ;==>_PrintGetPrinter

And try the dll from here.

I would be grateful if you could let me know the result.

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

Hi Prajoss, welcome to the AutoIt forums ^_^

I'm surprised I haven't included an Abort function already.

Can you add this to the UDF

;aborts printing
;returns 0 on success
;returns -1 if not already printing
;returns -2 if could not execute the dll call
 Func _PrintAbort($hDll)
     $vDllAns = DllCall($hDll, 'int', 'AbortPrint');
     If @error = 0 Then
         Return $vDllAns[0]
     Else
         Return -2
     EndIf
    
 
 EndFunc;==>_PrintGetPrinter

And try the dll from here.

I would be grateful if you could let me know the result.

Thx for the welcome ;)

I've tested it and it works fine! (every return is returned like it should be returned :D)

Thanks you helped me a lot

Edit:

EndFunc ;==>_PrintGetPrinter

should be

EndFunc ;==>_PrintAbort

or? :( Edited by Prajoss
Link to comment
Share on other sites

Thx for the welcome ^_^

I've tested it and it works fine! (every return is returned like it should be returned :( )

Thanks you helped me a lot

Edit:

That's good, I'll make it part of the standard version.

should be or? ;)

Not sure what that bit means but the rest read fine to me.
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 only wanted to say, that your Comment at the end of the

_PrintAbort function does not fit

Oh I see, yes you're right. It will be correct in the real version 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.
Link to comment
Share on other sites

I'm glad you like it.

This udf and dll will never be included in the AuoIt package. Many AutoIt printing functions have been developed which use the Windows API. At the moment this udf is possibly easier to use but hopefully that will not always be the case.

I know that these specific files will not be included, I was thinking more of the basic functions within them ^_^

I need much more information to give a sensible reply ;).

Where are you pressing Cancel? What function did you call which showed the Cancel button and what code have you written to allow for the Cancel button being pressed? Which versions are you using? Can you show any sample code which reproduces the problem?

Whenever the "Choose printer" dialog comes up, and you press cancel of or close the window, the printer spits out a page anyway. It seems to me that a sort of GUIregistermessage("Event_Close") or similar was used (sorry for bad code, just an example).

The UDF has information for the functions, you just need to read it and then experiment with the functions and ask if you get stuck.

I am kinda stuck now. Is there any way to restrict a _PrintLine to a specific width and then insert newlines down the page if it's too wide? - Or some kinda _Printtextbox or something?

Edit: Sorry for bad quote - please read very carefully to understand fully :(

Edited by Edifice
Link to comment
Share on other sites

I am kinda stuck now. Is there any way to restrict a _PrintLine to a specific width and then insert newlines down the page if it's too wide? - Or some kinda _Printtextbox or something?

Edit: Sorry for bad quote - please read very carefully to understand fully ^_^

I think you mean _PrintText not _PrintLine which draws a straight line.

There is no _printTextBox equivalent, but the functions are there to enable you to do it.

First there are the functions like _PrintGetPageWidth and _PrintGetPageHeight.

Then you can use _PrintGetTextHeight to decide on the vertical line spacing, _PrintGetTexWidth to see how wide the printed text will be and _PrintText to actually print the text. By having a loop and using functions like StringMid you can print any length of text over as many lines as need in a rectangle anywhere on the page.

Or, you could put the text in an edit which automatically wraps the text. Read the first line of text using the GuiEdit udf, and see how wide this will be on the printed page using _PrintGetTextWidth. Adjust the width of the edit untill the printed width is what you want and then print all the lines. The edit doesn't need to be visible.

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

  • 3 weeks later...

New function added to print from a Bitmap without needing to use a file.

_PrintImageFromDC

First post updated with a new link for the download.

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

  • 4 weeks later...

can you provide some examples of text wrapping please?

I think you mean _PrintText not _PrintLine which draws a straight line.

There is no _printTextBox equivalent, but the functions are there to enable you to do it.

First there are the functions like _PrintGetPageWidth and _PrintGetPageHeight.

Then you can use _PrintGetTextHeight to decide on the vertical line spacing, _PrintGetTexWidth to see how wide the printed text will be and _PrintText to actually print the text. By having a loop and using functions like StringMid you can print any length of text over as many lines as need in a rectangle anywhere on the page.

Or, you could put the text in an edit which automatically wraps the text. Read the first line of text using the GuiEdit udf, and see how wide this will be on the printed page using _PrintGetTextWidth. Adjust the width of the edit untill the printed width is what you want and then print all the lines. The edit doesn't need to be visible.

Link to comment
Share on other sites

can you provide some examples of text wrapping please?

Sorry but I do not have any examples.

The suggestions I have already made, which you quoted, are all I have.

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

Sorry but I do not have any examples.

The suggestions I have already made, which you quoted, are all I have.

I am currently working on a function (It's just a hobby and I'm working kinda slow.)

This is what I have so far:

Dim $startpoint = 1

Dim $lenght = 83

Dim $text = "123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789"

Dim $line = "123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123"

Dim $var = 0

Dim $result = stringcompare($text, $line, 2)

Dim $result2 = 1

Dim $empty = ""

If $result > 0 Then

while $result2 > 0

$var = StringMid($text, $startpoint, $lenght)

$result2 = Stringcompare($var, $empty, 2)

If $result2 > 0 Then

MsgBox(0, "Chopping up text into lines", $var)

EndIf

$startpoint = $startpoint + 83

;Print $var onto paper

;Move one line down

WEnd

EndIf

I would be very glad if you could incorporate it into the rest, otherwise I will just send you an example when I finish it (I'm hoping to be able to progress a bit faster during the next few weeks)

Link to comment
Share on other sites

I am currently working on a function (It's just a hobby and I'm working kinda slow.)

This is what I have so far:

Dim $startpoint = 1

Dim $lenght = 83

Dim $text = "123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789"

Dim $line = "123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123"

Dim $var = 0

Dim $result = stringcompare($text, $line, 2)

Dim $result2 = 1

Dim $empty = ""

If $result > 0 Then

while $result2 > 0

$var = StringMid($text, $startpoint, $lenght)

$result2 = Stringcompare($var, $empty, 2)

If $result2 > 0 Then

MsgBox(0, "Chopping up text into lines", $var)

EndIf

$startpoint = $startpoint + 83

;Print $var onto paper

;Move one line down

WEnd

EndIf

I would be very glad if you could incorporate it into the rest, otherwise I will just send you an example when I finish it (I'm hoping to be able to progress a bit faster during the next few weeks)

I don't see how that will help anyone wanting to wrap text so that it fits into a given width.
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

martin, Posted Image from me for nice job. Thanks.

Thanks Yashied. I've learnt a lot from you, so if I've done something which helps you I'm very pleased.

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

Added functions

_PrintGetPaperWidth

_PrintGEtPaperHeight

for the physical paper size in the printer.

(The functions _PrintGetPageWidth and _PrintGetPageHeight only return the printable dimensions.)

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