Jump to content

Print file doubt


Recommended Posts

1st excuse me if my english isnt good and u cant understand what i mean.

im trying to do an APP to generate a file or just print directly to some predifined paper sheets i allready have

those sheets have a grid allready printed and what i need is when i print it fills those grid cells on the sheet,

for ex. on 10cm width and 15cm height on the paper sheet print date and on 10cm width and 18cm height print Time

i've searche the _printfile function but i dont think thats the way to follow, any nice ideas? im really stuck here...

thanks in advance

Link to comment
Share on other sites

1st excuse me if my english isnt good and u cant understand what i mean.

im trying to do an APP to generate a file or just print directly to some predifined paper sheets i allready have

those sheets have a grid allready printed and what i need is when i print it fills those grid cells on the sheet,

for ex. on 10cm width and 15cm height on the paper sheet print date and on 10cm width and 18cm height print Time

i've searche the _printfile function but i dont think thats the way to follow, any nice ideas? im really stuck here...

thanks in advance

I started playing with this a little while ago and always intended to go back to it. I made a dll which does the printing, and I tested a few things with a basic Autoit script. I haven't made a udf for it and there are lots of things to be done yet. This is what it can do so far

Tell you the page width or height, tell you the horizontal or vertical resolution. (Not needed for what you want)

Start a print session

set the font name and size and colour

print a string at position x,y (defaults to printing from last position)

end a print session.

That's all I've done and I am unlikely to do much more at the moment. If you are happy to try my dll then I can send a small example of how to use it, but the UDF and more functions will have to wait a bit.

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 started playing with this a little while ago and always intended to go back to it. I made a dll which does the printing, and I tested a few things with a basic Autoit script. I haven't made a udf for it and there are lots of things to be done yet. This is what it can do so far

Tell you the page width or height, tell you the horizontal or vertical resolution. (Not needed for what you want)

Start a print session

set the font name and size and colour

print a string at position x,y (defaults to printing from last position)

end a print session.

That's all I've done and I am unlikely to do much more at the moment. If you are happy to try my dll then I can send a small example of how to use it, but the UDF and more functions will have to wait a bit.

Can you tell me what API functions did you used in your DLL?

With Autoit's DllCall and DllStruct it could be done also without external DLL surely.

Thanks.

Link to comment
Share on other sites

Can you tell me what API functions did you used in your DLL?

With Autoit's DllCall and DllStruct it could be done also without external DLL surely.

Thanks.

Yes I am sure it could be done without a dll, and that would definitely be better. It would also be smaller. The only API call I used was DeviceGetCaps and the rest was using Delphi functions, so the dll itself is really trivial. I only offered it to kamikaz3 because it was pretty much a ready-made solution that I had already played with, and he needed something and hadn't got any answers to his post. I am not such a good programmer that I would find it so easy to do with API calls in AutoIt without a lot more effort and time. As it happens kamikaz3 has managed to use my dll to solve his problem, but that doesn't mean it's the best approach.

It looks like such a UDF using API calls would be very useful though because printing is a bit limited in AtuIt without something like the Word udf for example. My dll can set the font name, style , size and colour, print at a coordinate, find the text dimensions, draw a line from a,b to c,d and a few other things. I will have a look at what's needed using the API now that you've given me a nudge, but I'm a bit apprehensive.

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 needed this a while ago, and in my research, I found the a DLL located on this web page:

http://pragmaticlee.safedataisp.net (Look for PrinterObject2.zip) There isn't a lot of documentation, and I don't see much about licensing on his website, so you should get permission from the author before using.

You have to register the .dll before you are able to use it.

I modified the author's sample code to make an Autoit sample. Try running the code below (remembre to register the .dll first!). And I think you'll see the possibilities.

I apologize that it's poorly documented, but hopefully it will help you.

;===============================================================================
;
; Script Name:   testPrintDLL.au3
;
;===============================================================================
;

$oPrn = ObjCreate("RxVB.PrinterObject")
    $oprn.InitializePrinter()
    $oprn.Orientation = 1
    $oprn.ColorMode = 2
    $oprn.Copies = 1
    $oprn.FontName = 'Arial'
    $oprn.FontSize = 12
    $oprn.AppTitle = 'PrinterObject_Demo'
    $red = $oprn.ConvertToRGB(255,0,0)
    $black = $oprn.ConvertToRGB(0,0,0)
    $blue = $oprn.ConvertToRGB(1,125,255)
      $oprn.CurrentY = .5

    $oprn.PrintLine($oprn.Ver)

    $oprn.PrintLine('This Was Printed On' & $oprn.PrName)

    $text = 'The GetCaps Method Was Used To Gather The Following Data For Portrait'
    $cap_array = $oprn.GetCaps
    $oprn.PrintLine($text)
    $oprn.PrintLine('dpix =' & $cap_array[1])
    $oprn.PrintLine('dpiy =' & $cap_array[2])
    $oprn.PrintLine('MarginLeft =' & $cap_array[3] / $cap_array[1] & 'Inches')
    $oprn.PrintLine('MarginRight =' & $cap_array[4] / $cap_array[1] & 'Inches')
    $oprn.PrintLine('PrintAreaHorz =' & $cap_array[5] / $cap_array[1] & 'Inches')
    $oprn.PrintLine('PrintAreaVert =' & $cap_array[6] / $cap_array[2] & 'Inches')
    $oprn.PrintLine('PhysWidth =' & $cap_array[7] / $cap_array[1] & 'Inches')
    $oprn.PrintLine('PhysHeight =' & $cap_array[8] / $cap_array[2] & 'Inches')
    $margin_left = $cap_array[3] / $cap_array[1]
    $print_area_horz = $cap_array[5] / $cap_array[1]
    $physical_width = $cap_array[7] / $cap_array[1]
    $margin_right = $physical_width - $print_area_horz - $margin_left

    $paper_center = $print_area_horz / 2

    $th = $oprn.TextHeight('A')
    $oprn.CurrentY = $oprn.CY + $th

    $text = 'This is a string of text in Arial 14 pt'
    $oprn.PrintLine($text)
    $tw = $oprn.TextWidth($text)
    $th = $oprn.TextHeight($text)
    $oprn.PrintLine('Its width is' &  $tw & '. Its height is' &$th & '.')

    $oprn.FontSize = 10
    $text = 'This is a string of text in Arial 10 pt'
    $oprn.PrintLine($text)
    $tw = $oprn.TextWidth($text)
    $th = $oprn.TextHeight($text)
    $oprn.PrintLine('Its width is' & $tw & '. Its height is' & $th & '.')

    $text = 'This text is in Bold'
    $oprn.FontBold = True
    $oprn.PrintLine($text)
    $oprn.FontBold = False

    $text = 'This text is in Italic'
    $oprn.FontItalic = True
    $oprn.PrintLine($text)
    $oprn.FontItalic = False

    $text = 'This text is in StrikeThru'
    $oprn.FontStrikeThru = True
    $oprn.PrintLine($text)
    $oprn.FontStrikeThru = False

    $text = 'This text is in UnderLine'
    $oprn.FontUnderLine = True
    $oprn.PrintLine($text)
    $oprn.FontUnderline = False

    $text = 'This text is in Bold, Italic, StrikeThru, & Underline'
    $oprn.FontBold = True
    $oprn.FontItalic = True
    $oprn.FontStrikeThru = True
    $oprn.FontUnderLine = True
    $oprn.PrintLine($text)
    $oprn.FontBold = False
    $oprn.FontItalic = False
    $oprn.FontStrikeThru = False
    $oprn.FontUnderLine = False

    $text = 'This Line Is Centered'
    $tw = $oprn.TextWidth($text)


    $oprn.CurrentX = $paper_center - ($tw / 2)
    $oprn.PrintLine($text)

    $curX = $oprn.CX
    $curY = $oprn.CY
    $oprn.PrintLineS('CurrentX Before This Line =' & $curX & '. CurrentY =' & $curY & '. ')
    $curX = $oprn.CX
    $curY = $oprn.CY
    $oprn.ForeColor = $red
    $oprn.PrintLine('CurrentX After The First Text Was =' & $curX & '. CurrentY =' & $curY & '. ')
    $oprn.ForeColor = $black
    $oprn.PrintLine('')
    $oprn.PrintLine('')
    
    $oprn.FontUnderline = False
    $oprn.FontName = 'Arial'
    $oprn.FontSize = 10
    
    $oprn.PrintLine('The Following Table Was Printed With TABS')
    dim $names[3], $headers[3]
    $headers[1] = 'First Name'
    $headers[2] = 'Last Name'
    $names[1] = 'Lee,Peedin'
    $names[2] = 'Leeanderthal,Peedin'
    $names[0] = 2

     $oprn.PrintLineT($headers[1],1)
     $oprn.PointSet( $oprn.CX, $oprn.CY,$black)
     $oprn.PrintLineT($headers[2],2)
     $oprn.PointSet( $oprn.CX, $oprn.CY,$black)
     $oprn.PrintLine('')
     $oprn.PointSet( $oprn.CX, $oprn.CY,$black)
     For $aa = 1 to $names[0]
        $n = StringSplit($names[$aa],",")
         $oprn.PrintLineT($n[1],1)
         $oprn.PointSet( $oprn.CX, $oprn.CY,$black)
         $oprn.PrintLineT($n[2],2)
         $oprn.PointSet( $oprn.CX, $oprn.CY,$black)
         $oprn.PrintLine('')
         $oprn.PointSet( $oprn.CX, $oprn.CY,$black)
     Next
     
     $oprn.PrintLine(' ')
    $save_curX =  $oprn.CX
    $save_curY =  $oprn.CY
    $text = 'Use DrawLine To Create Square Corner Boxes'
    $oprn.PrintLine($text)
    $curY =  $oprn.CY + .1
    $curX =  $oprn.CX + .1

     $oprn.DrawLine($curX,$curY,$curX+2,$curY)            ; --Top
     $oprn.DrawLine($curx,$curY,$curX,$curY+2)            ; --Left
     $oprn.DrawLine($curX,$curY+2,$curX+2,$curY+2)        ; --Bottom
     $oprn.DrawLIne($curX+2,$curY,$curX+2,$curY+2)        ; --Right

     $oprn.CurrentY = $curY + 2.1
     $oprn.CurrentX = 0
    $text = 'Use DrawLineC To Create Colored-Square Corner Boxes'
     $oprn.PrintLine($text)
    $curY =  $oprn.CY + .1
    $curX =  $oprn.CX + .1

     $oprn.DrawLineC($curX,$curY,$curX+2,$curY,$blue)      ; --Top
     $oprn.DrawLineC($curX,$curY,$curX,$curY+2,$blue)      ; --Left
     $oprn.DrawLineC($curX,$curY+2,$curX+2,$curY+2,$blue)  ; --Bottom
     $oprn.DrawLIneC($curX+2,$curY,$curX+2,$curY+2,$blue)  ; --Right
     

    
   Exit

Good Luck !!!

Link to comment
Share on other sites

I needed this a while ago, and in my research, I found the a DLL located on this web page:

http://pragmaticlee.safedataisp.net (Look for PrinterObject2.zip) There isn't a lot of documentation, and I don't see much about licensing on his website, so you should get permission from the author before using.

This looks good and my first reaction was that I needn't have done my UDF. :P But I decided that the best approach was to try and do better :), so I've added jpgs, bmps and icons, text at any angle with transparent background, landscape and so on. The only things I haven't done so far that I think the pramgmaticlee dll does is arcs and filled areas. The other difference is that mine is all done in mm rather than inches although that could be set as an option. The udf in example scripts.

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

  • 10 months later...

I am somewhat new to AutoIt, but have been trying to create a UDF for printing that does not require a DLL external to the OS.

PrintWinAPI.au3

Sample output:

Example.au3

CODE
#Include <PrintWinAPI.au3>

; Create a printer device context

$s_DefaultPrinter = _GetDefaultPrinter()

$s_PrinterName = InputBox("AutoIt API Printing", "Enter printer name", $s_DefaultPrinter)

If $s_PrinterName = "" Then Exit

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

; get pixel and twips info

$PixelsPerInchY = _WinAPI_GetDeviceCaps($hPrintDc, $__WINAPCONSTANT_LOGPIXELSY) ; Get Pixels Per Inch Y

$TwipsPerPixelY = 1440 / $PixelsPerInchY

$PixelsPerInchX = _WinAPI_GetDeviceCaps($hPrintDc, $__WINAPCONSTANT_LOGPIXELSX) ; Get Pixels Per Inch X

$TwipsPerPixelX = 1440 / $PixelsPerInchX

; get page width and height

$cWidthPels = _WinAPI_GetDeviceCaps($hPrintDc, $HORZRES) ; Get Pixels Per Inch X

$cHeightPels = _WinAPI_GetDeviceCaps($hPrintDc, $VERTRES) ; Get Pixels Per Inch Y

; set docinfo

$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)

; create font

$DESIREDFONTSIZE = 16

$hFont = _WinAPI_CreateFont((($DESIREDFONTSIZE * -20) / $TwipsPerPixelY), 0, 0, 0, $FW_NORMAL, True, True, False _

, $DEFAULT_CHARSET, $OUT_DEFAULT_PRECIS, $CLIP_DEFAULT_PRECIS, $DEFAULT_QUALITY, $DEFAULT_PITCH, 'Verdona')

; set newfond, save old font

$hFontOld = _WinAPI_SelectObject($hPrintDc, $hFont)

; print centered test message

$s_TextOut = "This is a test..."

$OutSize = _WinAPI_GetTextExtentPoint32($hPrintDc, $s_TextOut)

; Compute the starting point for the text-output operation(centered)

$xLeft = (($cWidthPels / 2) - (DllStructGetData($OutSize,"X") / 2))

; Compute the starting point for the text-output 2 lines down

$yTop = DllStructGetData($OutSize,"Y") * 2

; Send text

$result = _WinAPI_TextOut($hPrintDc, $xLeft, $yTop, $s_TextOut)

; create font structure, rotated 180 degrees

$lf = DllStructCreate($tagLOGFONT)

$DESIREDFONTSIZE = 12

DllStructSetData($lf, "Escapement", 2700)

DllStructSetData($lf, "Height", (($DESIREDFONTSIZE * -20) / $TwipsPerPixelY))

DllStructSetData($lf, "Italic", False)

DllStructSetData($lf, "Underline", False)

DllStructSetData($lf, "FaceName", "Arial")

; set font

$hLF = _WinAPI_CreateFontIndirect($lf)

$result = _WinAPI_SelectObject($hPrintDc, $hLF)

; Send rotated text to printer, starting at location 1000, 1000

$xLeft = 1000

$yTop = 1000

$s_TextOut = "Testing...123"

$result = _WinAPI_TextOut($hPrintDc, $xLeft, $yTop, $s_TextOut)

; update font

_WinAPI_DeleteObject($hLF)

DllStructSetData($lf, "Escapement", 2250)

$hLF = _WinAPI_CreateFontIndirect($lf)

$result = _WinAPI_SelectObject($hPrintDc, $hLF)

; Send rotated text to printer, starting at location 1000, 1000

$result = _WinAPI_TextOut($hPrintDc, $xLeft, $yTop, $s_TextOut)

; update font

_WinAPI_DeleteObject($hLF)

$hLF = _WinAPI_CreateFont((($DESIREDFONTSIZE * -20) / $TwipsPerPixelY), 0, 1800, 0, $FW_NORMAL, False, False, False _

, $DEFAULT_CHARSET, $OUT_DEFAULT_PRECIS, $CLIP_DEFAULT_PRECIS, $DEFAULT_QUALITY, $DEFAULT_PITCH, 'Arial')

$result = _WinAPI_SelectObject($hPrintDc, $hLF)

; Send rotated text to printer, starting at location 1000, 1000

$result = _WinAPI_TextOut($hPrintDc, $xLeft, $yTop, $s_TextOut)

; update font

_WinAPI_DeleteObject($hLF)

$hLF = _WinAPI_CreateFont((($DESIREDFONTSIZE * -20) / $TwipsPerPixelY), 0, 1500, 0, $FW_NORMAL, False, False, False _

, $DEFAULT_CHARSET, $OUT_DEFAULT_PRECIS, $CLIP_DEFAULT_PRECIS, $DEFAULT_QUALITY, $DEFAULT_PITCH, 'Arial')

$result = _WinAPI_SelectObject($hPrintDc, $hLF)

; Send rotated text to printer, starting at location 1000, 1000

$result = _WinAPI_TextOut($hPrintDc, $xLeft, $yTop, $s_TextOut)

; update font

_WinAPI_DeleteObject($hLF)

$hLF = _WinAPI_CreateFont((($DESIREDFONTSIZE * -20) / $TwipsPerPixelY), 0, 1200, 0, $FW_NORMAL, False, False, False _

, $DEFAULT_CHARSET, $OUT_DEFAULT_PRECIS, $CLIP_DEFAULT_PRECIS, $DEFAULT_QUALITY, $DEFAULT_PITCH, 'Arial')

$result = _WinAPI_SelectObject($hPrintDc, $hLF)

; Send rotated text to printer, starting at location 1000, 1000

$result = _WinAPI_TextOut($hPrintDc, $xLeft, $yTop, $s_TextOut)

; update font

_WinAPI_DeleteObject($hLF)

$hLF = _WinAPI_CreateFont((($DESIREDFONTSIZE * -20) / $TwipsPerPixelY), 0, 900, 0, $FW_NORMAL, False, False, False _

, $DEFAULT_CHARSET, $OUT_DEFAULT_PRECIS, $CLIP_DEFAULT_PRECIS, $DEFAULT_QUALITY, $DEFAULT_PITCH, 'Arial')

$result = _WinAPI_SelectObject($hPrintDc, $hLF)

; set textcolor, save last textcolor

$iColorOld = _WinAPI_SetTextColor($hPrintDc, 0xFF0000)

; Send rotated text to printer, starting at location 1000, 1000

$result = _WinAPI_TextOut($hPrintDc, $xLeft, $yTop, $s_TextOut)

; update font

_WinAPI_DeleteObject($hLF)

$hLF = _WinAPI_CreateFont((($DESIREDFONTSIZE * -20) / $TwipsPerPixelY), 0, 600, 0, $FW_NORMAL, False, False, False _

, $DEFAULT_CHARSET, $OUT_DEFAULT_PRECIS, $CLIP_DEFAULT_PRECIS, $DEFAULT_QUALITY, $DEFAULT_PITCH, 'Arial')

$result = _WinAPI_SelectObject($hPrintDc, $hLF)

; set textcolor, save last textcolor

$result = _WinAPI_SetTextColor($hPrintDc, 0x00FF00)

; Send rotated text to printer, starting at location 1000, 1000

$result = _WinAPI_TextOut($hPrintDc, $xLeft, $yTop, $s_TextOut)

; update font

_WinAPI_DeleteObject($hLF)

$hLF = _WinAPI_CreateFont((($DESIREDFONTSIZE * -20) / $TwipsPerPixelY), 0, 300, 0, $FW_NORMAL, False, False, False _

, $DEFAULT_CHARSET, $OUT_DEFAULT_PRECIS, $CLIP_DEFAULT_PRECIS, $DEFAULT_QUALITY, $DEFAULT_PITCH, 'Arial')

$result = _WinAPI_SelectObject($hPrintDc, $hLF)

; set textcolor, save last textcolor

$result = _WinAPI_SetTextColor($hPrintDc, 0x0000FF)

; Send rotated text to printer, starting at location 1000, 1000

$result = _WinAPI_TextOut($hPrintDc, $xLeft, $yTop, $s_TextOut)

; update font

_WinAPI_DeleteObject($hLF)

$hLF = _WinAPI_CreateFont((($DESIREDFONTSIZE * -20) / $TwipsPerPixelY), 0, 0, 0, $FW_BOLD, False, False, False _

, $DEFAULT_CHARSET, $OUT_DEFAULT_PRECIS, $CLIP_DEFAULT_PRECIS, $DEFAULT_QUALITY, $DEFAULT_PITCH, 'Arial')

$result = _WinAPI_SelectObject($hPrintDc, $hLF)

; set textcolor, save last textcolor

$result = _WinAPI_SetTextColor($hPrintDc, 0x0)

; Send rotated text to printer, starting at location 1000, 1000

$result = _WinAPI_TextOut($hPrintDc, $xLeft, $yTop, $s_TextOut)

; set textcolor

$result = _WinAPI_SetTextColor($hPrintDc, 0x0000FF)

; restore original font

$result = _WinAPI_SelectObject($hPrintDc, $hFontOld)

; restore original color

$result = _WinAPI_SetTextColor($hPrintDc, $iColorOld)

; delete fonts

_WinAPI_DeleteObject($hFont)

_WinAPI_DeleteObject($hLF)

; create pens to draw with (PenStyle, Width, RGB-Color)

$hPen0 = _WinAPI_CreatePen($PS_SOLID, 0, 0x000000)

$hPen1 = _WinAPI_CreatePen($PS_DASH, 0, 0x000000)

$hPen2 = _WinAPI_CreatePen($PS_DOT, 0, 0x000000)

$hPen3 = _WinAPI_CreatePen($PS_DASHDOT, 0, 0x000000)

$hPen4 = _WinAPI_CreatePen($PS_DASHDOTDOT, 0, 0x000000)

$hPen5 = _WinAPI_CreatePen($PS_SOLID, 20, 0x000000)

$hPen6 = _WinAPI_CreatePen($PS_SOLID, 40, 0x000000)

$hPen7 = _WinAPI_CreatePen($PS_SOLID, 40, 0x0000FF)

$hPen8 = _WinAPI_CreatePen($PS_SOLID, 40, 0x00FF00)

$hPen9 = _WinAPI_CreatePen($PS_SOLID, 40, 0xFF0000)

; set starting point

$LastPoint = DllStructCreate($tagPOINT)

$result = _WinAPI_MoveToEx($hPrintDc, 1000, 2000, $LastPoint)

; select pen, save old pen

$hPenOld = _WinAPI_SelectObject($hPrintDc, $hPen2)

; draw line

$result = _WinAPI_LineTo($hPrintDc, 1100, 3000)

; select pen

$result = _WinAPI_SelectObject($hPrintDc, $hPen4)

; draw line

$result = _WinAPI_LineTo($hPrintDc, 1200, 2000)

; select pen

$result = _WinAPI_SelectObject($hPrintDc, $hPen3)

; draw line

$result = _WinAPI_LineTo($hPrintDc, 1300, 3000)

; select pen

$result = _WinAPI_SelectObject($hPrintDc, $hPen1)

; draw line

$result = _WinAPI_LineTo($hPrintDc, 1400, 2000)

; select pen

$result = _WinAPI_SelectObject($hPrintDc, $hPen0)

; draw line

$result = _WinAPI_LineTo($hPrintDc, 1500, 3000)

; select pen

$result = _WinAPI_SelectObject($hPrintDc, $hPen5)

; draw line

$result = _WinAPI_LineTo($hPrintDc, 1600, 2000)

; select pen

$result = _WinAPI_SelectObject($hPrintDc, $hPen6)

; draw line

$result = _WinAPI_LineTo($hPrintDc, 1700, 3000)

; select pen

$result = _WinAPI_SelectObject($hPrintDc, $hPen7)

; draw line

$result = _WinAPI_LineTo($hPrintDc, 1800, 2000)

; select pen

$result = _WinAPI_SelectObject($hPrintDc, $hPen8)

; draw line

$result = _WinAPI_LineTo($hPrintDc, 1900, 3000)

; select pen

$result = _WinAPI_SelectObject($hPrintDc, $hPen9)

; draw line

$result = _WinAPI_LineTo($hPrintDc, 2000, 2000)

; draw arch connected from current point

$result = _WinAPI_SetArcDirection($hPrintDc, $AD_CLOCKWISE)

$result = _WinAPI_ArcTo($hPrintDc, 2500, 2000, 3000, 2500, 2500, 2500, 3000, 2500)

; select pen

$result = _WinAPI_SelectObject($hPrintDc, $hPen4)

; draw arch

$result = _WinAPI_Arc($hPrintDc, 2500, 1000, 3500, 1500, 0, 0, 0, 0)

; select pen

$result = _WinAPI_SelectObject($hPrintDc, $hPen5)

; create brush

$hBrush = _WinAPI_CreateSolidBrush(0x0000FF)

; select brush

$hBrushOld = _WinAPI_SelectObject($hPrintDc, $hBrush)

; draw rectangles

$result = _WinAPI_Rectangle($hPrintDc, 3500, 2000, 4500, 2500)

$result = _WinAPI_RoundRect($hPrintDc, 3500, 2600, 4500, 3100, 200, 200)

; draw circle

$result = _WinAPI_Ellipse($hPrintDc, 3300, 1800, 3700, 2200)

; restore original brush

$result = _WinAPI_SelectObject($hPrintDc, $hBrushOld)

; select pen

$result = _WinAPI_SelectObject($hPrintDc, $hPen2)

$result = _WinAPI_Arc($hPrintDc, 3300, 1900, 3700, 2300, 0, 0, 0, 0)

;

; End the page

$result = _WinAPI_EndPage($hPrintDc)

; start new page

$result = _WinAPI_StartPage($hPrintDc)

; print centered test message

$s_TextOut = "This is page 2"

$OutSize = _WinAPI_GetTextExtentPoint32($hPrintDc, $s_TextOut)

; Compute the starting point for the text-output operation(centered)

$xLeft = (($cWidthPels / 2) - (DllStructGetData($OutSize,"X") / 2))

; Compute the starting point for the text-output 2 lines down

$yTop = DllStructGetData($OutSize,"Y") * 2

; Send text

$result = _WinAPI_TextOut($hPrintDc, $xLeft, $yTop, $s_TextOut)

; delete pens

_WinAPI_DeleteObject($hPen0)

_WinAPI_DeleteObject($hPen1)

_WinAPI_DeleteObject($hPen2)

_WinAPI_DeleteObject($hPen3)

_WinAPI_DeleteObject($hPen4)

_WinAPI_DeleteObject($hPen5)

_WinAPI_DeleteObject($hPen6)

_WinAPI_DeleteObject($hPen7)

_WinAPI_DeleteObject($hPen8)

_WinAPI_DeleteObject($hPen9)

; delete brush

_WinAPI_DeleteObject($hBrush)

; restore original pen

$result = _WinAPI_SelectObject($hPrintDc, $hPenOld)

; restore original brush

$result = _WinAPI_SelectObject($hPrintDc, $hBrushOld)

; End the page

$result = _WinAPI_EndPage($hPrintDc)

; End the print job

$result = _WinAPI_EndDoc($hPrintDc)

; Delete the printer device context

_WinAPI_DeleteDC($hPrintDc)

Func _GetDefaultPrinter()

$s_TempDeviceID = ""

If @OSTYPE = "WIN32_NT" Then

Local $objWMIService = ObjGet("winmgmts:\\.\root\CIMV2")

If Not @error = 0 Then

; error

Else

Local $wbemFlagReturnImmediately = 0x10

Local $wbemFlagForwardOnly = 0x20

Local $colItems = $objWMIService.ExecQuery("SELECT * FROM Win32_Printer", "WQL", $wbemFlagReturnImmediately + $wbemFlagForwardOnly)

If IsObj($colItems) then

For $objItem In $colItems

If $s_TempDeviceID = "" Then $s_TempDeviceID = $objItem.DeviceID

If $objItem.Default Then $s_TempDeviceID = $objItem.DeviceID

Next

Else

;Msgbox(262192,"WMI Output","No WMI Objects Found for class: " & "Win32_Printer" )

Endif

EndIf

EndIf

Return $s_TempDeviceID

EndFunc

I have not been able to add the ability to print images or to change paper orientation.

It would be great if someone could help add these two features or expand it to include any others.

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