Page 1 of 1

Printing computer files (RTF, MHT etc.)

Posted: Mon Jul 09, 2007 5:19 pm
by Seymour Clufley
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?

Posted: Mon Jul 09, 2007 5:27 pm
by michaeled314
You can certainly print txt,png,jpg,tiff file formats because of built in librarys to PB, but pdf,doc,rtf would take a bit more work (a lot more). :wink:

Posted: Mon Jul 09, 2007 7:29 pm
by Seymour Clufley
Okay so that's 2 formats off the list, 4 (maybe 6) to go.

Michael, could you (or anyone else :)) be more specific about what will be necessary to print these formats?

BMP
RTF
HTML
MHT


Thanks in advance,
Seymour.

Posted: Mon Jul 09, 2007 8:09 pm
by michaeled314

Code: Select all

If StartPrinting(JobName$)
 If StartDrawing(PrinterOutput())
  DrawImage()
 Endif
Endif

Works w/Images

Code: Select all

 DrawText(x,y,FileReadLine(or something like that))
Works w/txt files on the printeroutput()

Posted: Mon Jul 09, 2007 8:10 pm
by michaeled314
Parse xmls for html related files?

Posted: Mon Jul 09, 2007 8:14 pm
by Inf0Byt3
My idea would be to load them in a web gadget and print the contents. That's the best solution i can think of right now (considering the level of alchool in my blood hehe).

Posted: Mon Jul 09, 2007 9:50 pm
by singo
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

Posted: Mon Jul 09, 2007 10:02 pm
by Seymour Clufley
Singo, that sounds excellent, and I would be very grateful for some code!

Would this method work with all the file formats that MS Word supports?

Posted: Mon Jul 09, 2007 10:15 pm
by singo
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* :shock: 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

Posted: Tue Jul 10, 2007 1:02 am
by singo
Seymour,

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
Hope that helps
Singo

Posted: Tue Jul 10, 2007 12:07 pm
by Shardik
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).

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)

Posted: Tue Jul 10, 2007 11:47 pm
by singo
Shardick,

Thats what I meant (sort of) in my previous post.

Thank you for making that clear.

You have a URL where Acrobat Reader 4 can still be downloaded ?

Regards
Singo

Posted: Thu Jul 12, 2007 11:05 am
by Seymour Clufley
Thanks very much Singo, and everyone else.

I might be back to ask more questions on this when I start work on the program. (Just now there's other stuff to finish.)

Posted: Thu Jul 12, 2007 1:04 pm
by Shardik
singo wrote: You have a URL where Acrobat Reader 4 can still be downloaded ?
http://www.oldversion.com/program.php?n=acrobat