Posts: 1,000
Threads: 253
Joined: Feb 2008
Ok, so I have data and I want to format and send to a printer.
using "run" with the "print" verb works on TXT and RTF files automatically.
TXT files are too basic for the formatting I want.
RTF is a pain to format the way I want...I have done it in the past, but would like to avoid the rig-a-ma-role of escaping and formatting things.
HTML does not automatically print, it pops up the print dialog. I guess I could trigger the dialog, but that seems ugly to me.
I think there may be a way to do it with winword, but I'm not so interested in burning a license of office on the machine that will be processing...or shifting documents to another machine that does have office.
So...I think I am most interested in perhaps converting HTML to RTF, or using Internet Explorer to print.
How to? Suggestions?
Posts: 9
Threads: 3
Joined: Sep 2013
The "print" verb is set up by some complicated registry entries.
http://msdn.microsoft.com/en-us/library/...s.85).aspx
You could make your own registry entries to create new print verbs, or change existing ones. But it, seems like a lot of trouble.
Also, some random program's installer might change the print verb for some filetype and break it.
How about OpenOffice or LibreOffice and print HTML directly?
swriter.exe -pt "My Printer Name" "c:\my_stuff.html"
(Prints document to named printer and exit).
or just
swriter.exe -p "c:\my_stuff.html"
(Print document to default printer and exit).
Even with HTML you have to escape things, though.
& &
" "
' '
< <
> >
Posts: 1,000
Threads: 253
Joined: Feb 2008
I've come across this a lot out there in the interwebs:
http://msdn.microsoft.com/en-us/library ... -snippet-1
Can't figure out with QM.
Posts: 1,000
Threads: 253
Joined: Feb 2008
I think I'll probably lay it out with RTF looking at it again.
Syntax isn't really that bad:
{\rtf1\ansi\ansicpg1252\deff0{\fonttbl{\f0\fnil\fcharset0 Calibri;}}
\qr\fs52 123456\line
\ql\fs24\tx990\tx1890\tx2790\tx4000
ONE\tab Two\tab THREE\tab FOUR\tab FIVE\line
SIX\tab SEVEN\tab EIGHT\tab NINE\tab Ten\line
\line
Don't forget to escape \{,\},and \\!\line
}
Posts: 12,087
Threads: 142
Joined: Dec 2002
Can print with web browser control, but it is unreliable.
Function
SendHtmlToPrinter
;/
function $urlOrFile [^waitS]
;Sends web page (URL or local file) to the default printer.
;REMARKS
;Uses a hidden web browser control. Loads web page and executes "Print" command, like in Internet Explorer.
;The command is asynchronous. This function must wait until it completes. There is no way to know when, therefore this function just wait waitS seconds. If waitS is omitted or 0, waits 1 s.
;If shows "Script Error" message box, make waitS bigger.
opt noerrorshere 1
int-- t_hax
if !t_hax
,t_hax=CreateWindowEx(0 "ActiveX" F"SHDocVw.WebBrowser" WS_POPUP 0 0 0 0 HWND_MESSAGE 0 _hinst 0)
,atend DestroyWindow t_hax
SHDocVw.WebBrowser wb._getcontrol(t_hax)
wb.Silent=1
VARIANT f=14 ;;navNoHistory|navNoReadFromCache|navNoWriteToCache. See HtmlDoc.CreateDocument.
wb.Navigate(_s.expandpath(urlOrFile) f)
opt waitmsg 1; 0; rep() if(!wb.Busy) break; else 0.01
wb.ExecWB(SHDocVw.OLECMDID_PRINT 2)
if(waitS=0) waitS=1
wait waitS
Also tested command line printing with OpenOffice, works.
Or use run with "print" verb, and let the macro close the print window.
Posts: 1,000
Threads: 253
Joined: Feb 2008
I ended up formatting RTF for this project and it's working pretty good.
Basically I used WordPad to layout my print and then opened the RTF file with Notepad and tweeked so QM could format the RTF style with variables.
Pretty gritty, but works really good.