• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1427
  • Last Modified:

Printing a word doc in duplex mode using delphi OLE Automation


I am using a printer that supports duplex printing(I am successfully printing double-sided a document using Word - Office 2013). I need to print a word document double-sided using Delphi and my tries have failed so far.
Please let me know if you have a working solution.
Here is the code I am using:

procedure TForm1.b1Click(Sender: TObject);
  Word: variant;

  procedure SetDuplexMode;
    Device, Driver, Port: array[0..80] of Char;
    DevMode: THandle;
    pDevmode: PDeviceMode;
    Printer.GetPrinter(Device, Driver, Port, DevMode);
    if Devmode  <> 0 then begin
      pDevMode := GlobalLock(Devmode);
      if pDevmode <> nil then
        with pDevmode^ do begin
          dmDuplex := DMDUP_VERTICAL;
          dmFields := dmFields or DM_DUPLEX;

   Word := CreateOleObject('Word.Application');

1 Solution
Helen FeddemaCommented:
I am not familiar with Delphi, but one way to get around difficulties with duplexing via code is to make a separate printer item, preset for duplexing.  Then you just print to that printer.  That is what I do for printing from Word or Access.
AMS_DEVAuthor Commented:
Thanks Helen, but I really need someone that can fix my code or give me another code example that works. Or maybe you can show me the code in another language you work with.
The code you are using won't work because you are modifying the printer properties in the context of your Delphi application. (Add a TPrinterSetupDialog and you will see that the duplex mode is activated)
However, each application manages the printer properties independently.

You should therefore find a way to modify those properties through your Word Ole object. I have no knowledge of how you can handle this... As far as I know, it is not possible.

As Helen_Feddema suggested, the best way to get around this is to set up a dedicated printer for duplex printing. On a network, you can use a shared printer.
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now