Solved

I need to print Word documents from Delphi

Posted on 2013-01-03
4
951 Views
Last Modified: 2013-01-09
Hello,

I have Delphi 2010 Professional and I need to print Word documents from Delphi.
I read a lot of advice about "TWordApplication" (I quoted one below) but I haven't got such a component.

Take a look at the TWordApplication component on the servers tab of the component palette

  WordApplication1.Connect;
  WordDocument1.PrintOut();  //here is where you decribe all your parameters example: copies
  WordApplication1.Disconnect;
  WordApplication1.Quit;

Can you help me?

Thank you very much
0
Comment
Question by:starhu
4 Comments
 
LVL 36

Expert Comment

by:Geert Gruwez
ID: 38741348
you actually do have such a component if you also have word

you needn't explicitly install it,
you can use the com interface like here
http://delphi.about.com/cs/adptips2003/a/bltip0303_5.htm
0
 
LVL 19

Accepted Solution

by:
Thommy earned 500 total points
ID: 38741608
With ShellExecute you can even print different types of documents without using COM interfaces!!!

Try this...
Print Documents From Delphi - Print PDF, DOC, XLS, HTML, RTF, DOCX, TXT
0
 
LVL 25

Expert Comment

by:Sinisa Vuk
ID: 38742956
I suggest Thommys solution. If you make application for another user or to yourself office/word must me installed before. Even for second solution you must word installed to print real doc document correctly, this solution makes possible to print other extensions
(or doc) with default application (for doc can be LibreOffice).
0
 
LVL 21

Expert Comment

by:developmentguru
ID: 38754550
I feel like I need to voice my recommendation to follow Thommy's advice too.

  The company I am currently working at has, in the past, used a lot of Word automation.  Unfortunately they are making use of word at the same time.  This means we get hundreds of errors per month due to the COM automation of Word.  When the user has a dialog open and you are trying to do the automation, that will cause an error, and that is just one simple way a problem can come up.  Here are a few of the error messages we get every month from EurekaLog:

The RPC server is unavailable.
Unable to run the specified macro.
Word was unable to read this document.  It may be corrupt.
The object invoked has disconnected from its clients.
The caller is dispatching an asynchronous call and cannot make an outgoing call on behalf of this call.
An outgoing call cannot be made since the application is dispatching an input-synchronous call.
The object invoked has disconnected from its clients.
Call was rejected by callee.
(Just to list a few)

  COM automation of Office programs is something that experienced developers know to stay away from.  It causes far more headaches than it solves.

  I have seen it done well in a situation where there would be no user on the machine at the same time, but even then it is slow.  Trying to print invoices, via word automation, the system was able to generate 6 per minute (notice that is not printing them, just generating them).  A good reporting system like Fast Reports can do hundreds, possibly over 1,000, in the same minute.  It can also export to ODF (Open Document Format) which can be opened by word, any of more than a dozen other formats, or printed directly.

  If you have any input into this, please... for your own sanity, stay away from word automation!
0

Featured Post

Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

Join & Write a Comment

Suggested Solutions

Does the idea of dealing with bits scare or confuse you? Does it seem like a waste of time in an age where we all have terabytes of storage? If so, you're missing out on one of the core tools in every professional programmer's toolbox. Learn how to …
In this post we will learn how to connect and configure Android Device (Smartphone etc.) with Android Studio. After that we will run a simple Hello World Program.
In this fifth video of the Xpdf series, we discuss and demonstrate the PDFdetach utility, which is able to list and, more importantly, extract attachments that are embedded in PDF files. It does this via a command line interface, making it suitable …
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…

747 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now