Jump to content
Sign in to follow this  
jrumbaug

How can I send a text string to a printer?

Recommended Posts

jrumbaug

I am looking for the recomended way to send a text string to a printer, I have not found a function like PRINT( cText) in Autoit3 help nor have I found a COM example. Please point me in the right direction.

Thank you in advance

Jim Rumbaugh

Edited by jrumbaug

Share this post


Link to post
Share on other sites
Fire

Hi .

I`m sure this will give you some idea how it can be done.(Of course with more stuff In AutoitScript)

#RequireAdmin
If FileExists(@ScriptDir&"\Printers.ini") Then
    FileDelete(@ScriptDir&"\Printers.ini")
 
RunWait("cmd.exe /c " & "wmic printer get name >>"&@ScriptDir&"\Printers.ini",@ScriptDir,@SW_HIDE)
MsgBox(64,"Printers!","Available Printers On your System : " & FileRead(@ScriptDir&"\Printers.ini"))
EndIf

And then

with listview or etc control you can choose your printer + select your filename which would be printed

And use standart

WIN print utility (for more info print /?).

edit:Always i forgot about #RequireAdmin :mellow:

Edited by Sh3llC043r

[size="5"] [/size]

Share this post


Link to post
Share on other sites
Fulano

I'm pretty sure you can replace:

If FileExists(@ScriptDir&"\Printers.ini") Then
    FileDelete(@ScriptDir&"\Printers.ini")
 
RunWait("cmd.exe /c " & "wmic printer get name >>"&@ScriptDir&"\Printers.ini",@ScriptDir,@SW_HIDE)

with:

RunWait("cmd.exe /c " & "wmic printer get name >"&@ScriptDir&"\Printers.ini",@ScriptDir,@SW_HIDE)

#fgpkerw4kcmnq2mns1ax7ilndopen (Q, $0); while ($l = <Q>){if ($l =~ m/^#.*/){$l =~ tr/a-z1-9#/Huh, Junketeer's Alternate Pro Ace /; print $l;}}close (Q);[code] tag ninja!

Share this post


Link to post
Share on other sites
Fire

Fulano.

I use :

If FileExists(@ScriptDir&"\Printers.ini") Then
 FileDelete(@ScriptDir&"\Printers.ini")
endif

condition for clear result when the script secondly executed.

Witout it script can double printer names...


[size="5"] [/size]

Share this post


Link to post
Share on other sites
Fulano

As I understand it, the > operator overwrites the contents of the file, the >> operator appends. So the second time it would wipe out the contents of the file, replacing it with the new input.

I'm not familiar with the implementation of these, but it would make sense that using the system command for overwriting would be faster than deleting and then recreating the file.


#fgpkerw4kcmnq2mns1ax7ilndopen (Q, $0); while ($l = <Q>){if ($l =~ m/^#.*/){$l =~ tr/a-z1-9#/Huh, Junketeer's Alternate Pro Ace /; print $l;}}close (Q);[code] tag ninja!

Share this post


Link to post
Share on other sites
Fire

Yeah right. My apogolises.

I had not paid attention:)

Sorry Fulano.


[size="5"] [/size]

Share this post


Link to post
Share on other sites
Fulano

Yeah right. My apogolises.

I had not paid attention:)

Sorry Fulano.

Np, people catch me all the time with this kinda stuff :mellow:


#fgpkerw4kcmnq2mns1ax7ilndopen (Q, $0); while ($l = <Q>){if ($l =~ m/^#.*/){$l =~ tr/a-z1-9#/Huh, Junketeer's Alternate Pro Ace /; print $l;}}close (Q);[code] tag ninja!

Share this post


Link to post
Share on other sites
martin

I am looking for the recomended way to send a text string to a printer, I have not found a function like PRINT( cText) in Autoit3 help nor have I found a COM example. Please point me in the right direction.

Thank you in advance

Jim Rumbaugh

If you want more control over printing text or anything else then have a look at the link in my signature for a printing UDF. The first post of that thread also gives links to other threads for printing.


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.

Share this post


Link to post
Share on other sites
Yoriz

If its just simple printing your after, put your text in a text file and use _FilePrint from the UDF 'File Management'.


GDIPlusDispose - A modified version of GDIPlus that auto disposes of its own objects before shutdown of the Dll using the same function Syntax as the original.EzMySql UDF - Use MySql Databases with autoit with syntax similar to SQLite UDF.

Share this post


Link to post
Share on other sites
jrumbaug

@Yoriz ... Thanks, I have considered something similar, I will look into it further.

@Martin ... Thanks, There is A LOT of stuff there. I may of looked over a simple answer, or there may not be a simple answer. It will take me a couple of days to sort through it all. (This is my "lunch time" project. Eat and program. That's how I relax )

Jim Rumbaugh

Share this post


Link to post
Share on other sites
jrumbaug

From Martin's suggestion, I see he has posted a set of printing UDFs. If I am reading it right, I need to get printMGv2.au3 and "INCLUDE" it in my script. I believe the UDF _PrintText() will do what I want, though I see there are a few other functions I need to include to make it work the way I wish. I hope to post my own UDF later that does a simple printing, like:

_MyPrintUDF("A page prints on the default printer with this text on it")

Share this post


Link to post
Share on other sites
martin

If I am reading it right, I need to get printMGv2.au3 and "INCLUDE" it in my script.

Correct

I believe the UDF _PrintText() will do what I want, though I see there are a few other functions I need to include to make it work the way I wish.

Yes, the example shows you what can be done and how. Selecting or setting the printer isn't needed if you want to use the default printer or if you only have one.


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.

Share this post


Link to post
Share on other sites
jrumbaug

I am making progress. I have a working _PrintTextWinAPI() function..... but...

on one computer the time to execute is less than 0.5 seconds, on another it varied from 6 to over 25 seconds...

Once I #include <PrintTextWinAPI.AUG> I start getting "duplicate declaration" errors even though I have used #include-once

It's coming. I just gotta learn a few more things

Jim Rumbaugh

Share this post


Link to post
Share on other sites
jrumbaug

This project is now over.

I completed (kinda) my UDF PrintTextWinAPI(). It compiled OK. It would print OK. BUT, on my old machine where I am doing the programing, it took 25 seconds to print. Second, it would only print one line even if the text string had @CRLF. I know that was how the PrintWinAPI() functions described it, but I hoped I would not need to define EVERY line.

I do not plan to use my version PrintTextWinAPI()

Instead I am happy to just send the text to NOTEPAD just like in the tutorial. It works good enough. (note, a page of text scrolls on the screen slowly. It reminds me of watching a 2400baud modem conection in the 90's

this question is finished

Jim Rumbaugh

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  

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.