Printing computer files (RTF, MHT etc.)
-
Seymour Clufley
- Addict

- Posts: 1266
- Joined: Wed Feb 28, 2007 9:13 am
- Location: London
Printing computer files (RTF, MHT etc.)
Hi,
I'm just starting with PB and I'd like to know if this is possible...
My goal is to make a standalone utility that will read instructions from a plain txt file (the instructions would be a list of file names) and then print all of the files. The file formats would be TXT, RTF, JPG, BMP, HTML, MHT and possibly PDF and DOC.
Ideally, the app would run invisibly - no window and no taskbar icon.
Now I've been researching PB's print commands and - to a newbie's eye - they don't seem sufficient for the task. Should I use Gnozal's LPRINT library?
I'll be honest and say I really don't know what's involved in printing files. Can anyone tell me what I need to know?
I'm just starting with PB and I'd like to know if this is possible...
My goal is to make a standalone utility that will read instructions from a plain txt file (the instructions would be a list of file names) and then print all of the files. The file formats would be TXT, RTF, JPG, BMP, HTML, MHT and possibly PDF and DOC.
Ideally, the app would run invisibly - no window and no taskbar icon.
Now I've been researching PB's print commands and - to a newbie's eye - they don't seem sufficient for the task. Should I use Gnozal's LPRINT library?
I'll be honest and say I really don't know what's involved in printing files. Can anyone tell me what I need to know?
-
michaeled314
- Enthusiast

- Posts: 340
- Joined: Tue Apr 24, 2007 11:14 pm
-
Seymour Clufley
- Addict

- Posts: 1266
- Joined: Wed Feb 28, 2007 9:13 am
- Location: London
-
michaeled314
- Enthusiast

- Posts: 340
- Joined: Tue Apr 24, 2007 11:14 pm
Code: Select all
If StartPrinting(JobName$)
If StartDrawing(PrinterOutput())
DrawImage()
Endif
Endif
Code: Select all
DrawText(x,y,FileReadLine(or something like that))
-
michaeled314
- Enthusiast

- Posts: 340
- Joined: Tue Apr 24, 2007 11:14 pm
If the system you are running this program on has Word installed, you can call the Word.Application com object using the PB PureDisphelper library.
This lets you open doc or rtf files invisibly then print them and then close the instance of word, user would see nothing and would print to default printer.
If you want to try this option let me know and I can post some code.
Singo
This lets you open doc or rtf files invisibly then print them and then close the instance of word, user would see nothing and would print to default printer.
If you want to try this option let me know and I can post some code.
Singo
-
Seymour Clufley
- Addict

- Posts: 1266
- Joined: Wed Feb 28, 2007 9:13 am
- Location: London
Seymour,
Will post some code, it will be sometime in the next few hours as it is early morning here and that code is at work.
Yes it *should*
support any type of file that word supports.
Acrobat 4 & 5 have a /t command line option, but it is unreliable depending on the version. Google pdf commpand line print to see what I mean.
Why don't you download the PB PureDisphelper and try the word example it has to get you started.
Singo
Will post some code, it will be sometime in the next few hours as it is early morning here and that code is at work.
Yes it *should*
Acrobat 4 & 5 have a /t command line option, but it is unreliable depending on the version. Google pdf commpand line print to see what I mean.
Why don't you download the PB PureDisphelper and try the word example it has to get you started.
Singo
Seymour,
Here is code that works for me...
Hope that helps
Singo
Here is code that works for me...
Code: Select all
;Purebasic v4.02 Win
;Prints word document to default printer with no user interaction
;Uses PureDisphelper library
;by Singo 2007 tested on XPSP2
EnableExplicit
dhToggleExceptions(#True) ;#True for error reporting
Global oWord.l = dhCreateObject("Word.Application"), name.s
If oWord
; The document
name = "C:\mydoc.doc"
; If the file exists and has a size greater than zero
If FileSize(name) > 0
; Open the document
dhCallMethod (oWord, "Documents.Open(%s)",@name)
; Print the document no questions
dhCallMethod (oWord, "PrintOut()") ; print the current document no dialog
; Close the document
dhCallMethod (oWord, "Documents.Close %s",@"0") ;0 no save
; Quit Word
dhCallMethod (oWord, "Quit()") ; close Word
dhReleaseObject (oWord)
EndIf
EndIf
End
Singo
To print a PDF document is very easy if you call the Acrobat Reader with undocumented command line parameters:
http://two.pairlist.net/pipermail/repor ... 01158.html
The drawback is that you have to install the rather old Acrobat Reader 4 which was the last one to support the undocumented command line switches. There might be new features in your documents which are not supported by Version 4.
A short test with the code below revealed that Acrobat Reader 7.0.9 also accepts the /t switch, but the Acrobat Reader window is not hidden from the taskbar (as in Version 4) and not closed automatically after finishing the print out (as in Version 4).
http://two.pairlist.net/pipermail/repor ... 01158.html
The drawback is that you have to install the rather old Acrobat Reader 4 which was the last one to support the undocumented command line switches. There might be new features in your documents which are not supported by Version 4.
A short test with the code below revealed that Acrobat Reader 7.0.9 also accepts the /t switch, but the Acrobat Reader window is not hidden from the taskbar (as in Version 4) and not closed automatically after finishing the print out (as in Version 4).
Code: Select all
PDFFilename.S = Chr(34) + "C:\AMI-BIOS Beep Codes.PDF" + Chr(34)
PrinterName.S = "Lexmark C920"
RunProgram("AcroRd32", "/t " + PDFFilename + " " + PrinterName, "", #PB_Program_Hide)
-
Seymour Clufley
- Addict

- Posts: 1266
- Joined: Wed Feb 28, 2007 9:13 am
- Location: London
http://www.oldversion.com/program.php?n=acrobatsingo wrote: You have a URL where Acrobat Reader 4 can still be downloaded ?
