Printing computer files (RTF, MHT etc.)

Just starting out? Need help? Post your questions and find answers here.
Seymour Clufley
Addict
Addict
Posts: 1266
Joined: Wed Feb 28, 2007 9:13 am
Location: London

Printing computer files (RTF, MHT etc.)

Post 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?
michaeled314
Enthusiast
Enthusiast
Posts: 340
Joined: Tue Apr 24, 2007 11:14 pm

Post 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:
Seymour Clufley
Addict
Addict
Posts: 1266
Joined: Wed Feb 28, 2007 9:13 am
Location: London

Post 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.
michaeled314
Enthusiast
Enthusiast
Posts: 340
Joined: Tue Apr 24, 2007 11:14 pm

Post 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()
michaeled314
Enthusiast
Enthusiast
Posts: 340
Joined: Tue Apr 24, 2007 11:14 pm

Post by michaeled314 »

Parse xmls for html related files?
Inf0Byt3
PureBasic Fanatic
PureBasic Fanatic
Posts: 2236
Joined: Fri Dec 09, 2005 12:15 pm
Location: Elbonia

Post 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).
None are more hopelessly enslaved than those who falsely believe they are free. (Goethe)
User avatar
singo
User
User
Posts: 35
Joined: Mon Apr 23, 2007 4:50 am
Location: Nabiac NSW Australia

Post 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
Seymour Clufley
Addict
Addict
Posts: 1266
Joined: Wed Feb 28, 2007 9:13 am
Location: London

Post 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?
User avatar
singo
User
User
Posts: 35
Joined: Mon Apr 23, 2007 4:50 am
Location: Nabiac NSW Australia

Post 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
User avatar
singo
User
User
Posts: 35
Joined: Mon Apr 23, 2007 4:50 am
Location: Nabiac NSW Australia

Post 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
User avatar
Shardik
Addict
Addict
Posts: 2067
Joined: Thu Apr 21, 2005 2:38 pm
Location: Germany

Post 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)
User avatar
singo
User
User
Posts: 35
Joined: Mon Apr 23, 2007 4:50 am
Location: Nabiac NSW Australia

Post 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
Seymour Clufley
Addict
Addict
Posts: 1266
Joined: Wed Feb 28, 2007 9:13 am
Location: London

Post 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.)
User avatar
Shardik
Addict
Addict
Posts: 2067
Joined: Thu Apr 21, 2005 2:38 pm
Location: Germany

Post by Shardik »

singo wrote: You have a URL where Acrobat Reader 4 can still be downloaded ?
http://www.oldversion.com/program.php?n=acrobat
Post Reply