Re: directly print .doc .xls with Delphi

Posted by webmaster Guido on April 26, 2004
In Reply to: .doc .xls directly to print posted by Giovanni Caramia p12316 on April 26, 2004

: What i want to do is to transform a .doc or .xls into .pdf
: i thought that i can print them using Gosth pdf printer, but how can i print in background ?
: I should like give to user the opportunity to choose a document and after, clicking on a 'transform-button' obtain a .pdf.
-----------------------------------------

Directly printing a file with its "parent" application is easy, such as printing a .doc with MS-Word or an .xls with Excel:
ShellExecute(Handle, 'print', PChar('c:\test\test.doc'), nil, nil, SW_SHOW);
ShellExecute(Handle, 'print', PChar('c:\test\test.xls'), nil, nil, SW_SHOW);

Note that this only works if the user has the parent application installed. For more examples of ShellExecute, see the article "Running an external application" in DelphiLand's section "Code snips" at www.festra.com\eng\mtut01.htm

The application opens briefly, it prints the document, and it automatically closes. But... the file is printed with the *default* printer, and that's not what you want. There might some solutions:

1. Set the default printer to the pdf-printer; print the file; next set the default printer back to its previous setting. I'll try to find out if this is not too complicated.

2. A better solution: send the document directly to the pdf-printer-application. But then this application must accept a command line parameter. I'll try to find out if that is possible.

Can you please let me know the exact name of your pdf-printer? Is it "Gosth", as you wrote? And where can it be found?


Related Articles and Replies:

Delphi FAQ :: Source code :: Tips