Solved

Printing a word doc in duplex mode using delphi OLE Automation

Posted on 2013-06-28
3
1,277 Views
Last Modified: 2013-07-31
Hello,

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);
var
  Word: variant;

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

begin
   Word := CreateOleObject('Word.Application');
   Word.documents.add('C:\Developpement\Analysis\Print-Doubleface\1.docx');
   SetDuplexMode;

   Word.ActiveDocument.Printout;
end;
0
Comment
Question by:AMS_DEV
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
3 Comments
 
LVL 31

Expert Comment

by:Helen Feddema
ID: 39285164
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.
0
 

Author Comment

by:AMS_DEV
ID: 39285245
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.
0
 

Accepted Solution

by:
Guillaume80 earned 500 total points
ID: 39332729
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.
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Hello everybody This Article will show you how to validate number with TEdit control, What's the TEdit control? TEdit is a standard Windows edit control on a form, it allows to user to write, read and copy/paste single line of text. Usua…
The Selection object is designed for user interaction. It has a Range property, so it can be used in most places that a Range object can. Recorded macros must use the Selection because they are simply copying what the user is doing. A Range prope…
This Micro Tutorial well show you how to find and replace special characters in Microsoft Word. This is similar to carriage returns to convert columns of values from Microsoft Excel into comma separated lists.
In a previous video Micro Tutorial here at Experts Exchange (http://www.experts-exchange.com/videos/1358/How-to-get-a-free-trial-of-Office-365-with-the-Office-2016-desktop-applications.html), I explained how to get a free, one-month trial of Office …

717 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