Jump to content
Sign in to follow this  

simple script to print a input test to printer

Recommended Posts


I have discovered this incredible tool, but i have not much time to spend on writin code ;-(

so if someone have the solution to my need ..

I need a simple gui who have a input box to enter a text and a print button to print the text to the default printer, but the text printed must be at the right place on the paper

so how to deal with that ?


Share this post

Link to post
Share on other sites

Here's one way, the formatting and making sure the text ends where want is up to you, I'm sure there's other ways to print like wordpad

#include <GUIConstants.au3>

Opt("MustDeclareVars", 1)


Func _Main()
    Local $edit, $btn_print, $btn_exit, $msg
    GUICreate("Print It", 500, 500)
    $edit = GUICtrlCreateEdit('AutoIt v3 is a freeware BASIC-like scripting language designed for automating the' & @CRLF & _
            'Windows GUI.  It uses a combination of simulated keystrokes, mouse movement and' & @CRLF & _
            'window/control manipulation in order to automate tasks in a way not possible or reliable' & @CRLF & _
            'with other languages (e.g. VBScript and SendKeys).' & @CRLF & @CRLF & _
            'AutoIt was initially designed for PC "roll out" situations to configure thousands of PCs,' & @CRLF & _
            'but with the arrival of v3 it is also well suited to performing home automation and the' & @CRLF & _
            'scripting of repetitive tasks.', 10, 10, 480, 400)
    $btn_print = GUICtrlCreateButton("Print", 10, 420, 90, 20)
    $btn_exit = GUICtrlCreateButton("Exit", 110, 420, 90, 20)

    GUISetState(@SW_SHOW)       ; will display an empty dialog box

    ; Run the GUI until the dialog is closed
    While 1
        $msg = GUIGetMsg()
        Switch $msg
            Case $GUI_EVENT_CLOSE, $btn_exit
            Case $btn_print

EndFunc   ;==>_Main

; Description:      _CreateTempFileName
; Parameter(s):  location - where to create the temp file
;                     path = custom path to create temp file in
; Requirement:
; Return Value(s):  Returns a randomly generated temporary file name
;                     If error then @error is set and empty string is returned
; User CallTip:  _CreateTempFileName([location[,path]]) Creates a temp file
; Author(s):            Gary Frost
; Note(s):
; 0 = Windows temp folder or Windows folder if temp folder doesn't exist
; 1 = System folder (not recommended)
; 2 = path to the temporary files folder
; 3 = Custom path (must pass path with this value)
Func _CreateTempFileName($i_CreateWhere = 2, $s_Path = '')
    Local $fso = ObjCreate("Scripting.FileSystemObject")
    Local $tfolder, $tname
    Local Enum $WindowsFolder, $SystemFolder, $TemporaryFolder, $CustomFolder
    Switch $i_CreateWhere
        Case $WindowsFolder
            If FileExists(@WindowsDir & "\temp") Then
                $tfolder = @WindowsDir & "\temp"
                $tfolder = @WindowsDir
        Case $SystemFolder ; not widely used, don't recommend using this location
            $tfolder = @SystemDir
        Case $TemporaryFolder
            $tfolder = @TempDir
        Case $CustomFolder
            If @NumParams < 2 Then Return SetError(1, 1, "")
            $s_Path = StringReplace($s_Path, "/", "\")
            If StringRight($s_Path, 1) = "\" Then $s_Path = StringTrimRight($s_Path, 1)
            $tfolder = $s_Path
        Case Else
            Return SetError(1, 1, "")
    $tname = $tfolder & "\" & $fso.GetTempName ()
    Local $h_file = FileOpen($tname, 1)
    If $h_file = -1 Then Return SetError(1, 1, "")
    Return $tname
EndFunc   ;==>_CreateTempFileName

Func _NotePadPrintIt($str_input)
    Local $s_temp = _CreateTempFileName()

    Local $h_temp = FileOpen($s_temp, 1)
    If $h_temp = -1 Then Return SetError(-1, -1, 0)
    FileWrite($h_temp, $str_input)
    RunWait("NOTEPAD /P " & $s_temp, '', @SW_HIDE)
EndFunc   ;==>_NotePadPrintIt

SciTE for AutoItDirections for Submitting Standard UDFs


Don't argue with an idiot; people watching may not be able to tell the difference.


Share this post

Link to post
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
Sign in to follow this  

  • Create New...