Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

I need to print a Word document from my application 2

Status
Not open for further replies.

doctorjellybean

Programmer
May 5, 2003
145
0
0
I have achieved the most important goal, which was to populate some Word documents with data from my application. I managed this with the aid of Bookmarks in Word, and the OLEServer in Delphi.

Now what I would like as the topping on the cake, is being able to print the same document from the program. From what I understand, the program connects to the document to fill the data in, it doesn't actually load the doc. Therefore, is there a way to connect to the doc file and print it? Ideally I would like the printer dialog displayed so that I can select the printer, pages, etc.

Thanks in advance.
 
I'm glad you found my suggestion to use Bookmarks helpful.

To print, just use Word. To populate the Bookmarks, you should already have the document open in Word (controlled via Delphi). You can then get Word to display its Print DialogBox. I can't show any sample code because I don't currently have any version of Delphi installed.
 
Code:
When you are automating Word you do have the document open.  You'll likely just have to invoke the print method of the application or active document.

    * [URL unfurl="true"]http://www.djpate.freeserve.co.uk/AutoWord.htm[/URL]

I actually saw this page a few days ago. Like other pages which I have seen, none of them deal with printing. I have tried WordDoc.Print but that doesn't display the printer dialog so that I can select the printer, pages, no of copies, etc.
 
As a friend of mine said "Now why wouldn't they have Delphi examples?!?" .........

Thanks Daddy :) Going to see if the examples can be adapted for Delphi.
 
quick sample:

Code:
procedure TForm1.Button1Click(Sender: TObject);
var 
  Word: OleVariant;
  Dlg : OleVariant;
  Returnval : Integer;

begin
 Word := CreateOleObject('Word.Application');
 Word.Visible := True;
 Word.Documents.Add(EmptyParam, EmptyParam);
 Dlg := Word.Application.Dialogs.Item(wdDialogFilePrint);
 ReturnVal := Dlg.Display;
end;

best thing is to import the word type library and add it to the uses list, or else the wdDialogFilePrint constant is not known.

if you don't have word on your development machine, this is the value: wdDialogFilePrint = $00000058;

/Daddy

-----------------------------------------------------
What You See Is What You Get
Never underestimate tha powah of tha google!
 
Actually (in D2009 at least) you don't have to import the library, it's in WordXP.pas and you can just include that in your uses clause. Source can be found in InstallationDir\OCX\Servers.

LongHairCook
---------------------------
Never trust a skinny cook!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top