title: Delphi duplex printing
body: <p>I have a PVC card printer which prints on both sides of a card at the same time.
  take a look at this question: <a href="https://stackoverflow.com/questions/28382356/delphi-double-side-printer">Delphi double-side printer</a></p>
  
  <p>I managed to enable the duplex printing mode of the printer. now the problem is that the first page which is the front side of the card is printed fine but the back side which is the second page is printed in black and white and a very low quality. something like a monochrome bitmap.</p>
  
  <p>this is the output of my program which is printed using MS XPS document printer.
  as you can see there is no problem here, but when I select the PVC printer, I have problems in printing the back side.</p>
  
  <p>Left page is the front side of the card which is printed fine but the right page is the back side of the card and is printed in black and white and a very low quality.</p>
  
  <p><img src="https://i.stack.imgur.com/pEFOn.png" alt="Left page is the front side which is printed fine."></p>
  
  <pre><code>var
    i, j: integer;
    ppix,ppiy,mmx,mmy: integer;
    XForm: TXForm;
    Device, Driver, Port: array[0..80] of Char;
    DevMode: THandle;
    pDevmode: PDeviceMode;
    insert_comm: wideString;
  begin
    with PrintDialog1 do
  if Execute then
    begin
  
      with printer do
        begin
  
          GetPrinter(Device, Driver, Port, DevMode);
          if Devmode &lt;&gt; 0 then begin
             // lock it to get pointer to DEVMODE record
            pDevMode := GlobalLock(Devmode);
          if pDevmode &lt;&gt; nil then
            try
              with pDevmode^ do begin
                dmDuplex := DMDUP_VERTICAL;
                dmFields := dmFields or DM_DUPLEX;
              end;
  
              BeginDoc;
  
              ppix:=GetDeviceCaps(Handle,LOGPIXELSX);
              ppiy:=GetDeviceCaps(Handle,LOGPIXELSY);
              mmx:=round(ppix/25.4);
              mmy:=round(ppiy/25.4);
  
              SetGraphicsMode(Canvas.Handle, GM_ADVANCED);
              XForm.eM11 := Cos(DegToRad(270));
              XForm.eM12 := Sin(DegToRad(270));
              XForm.eM21 := -Sin(DegToRad(270));
              XForm.eM22 := Cos(DegToRad(270));
              XForm.eDx := (PageWidth div 2) - ((54 * mmy) div 2);
              XForm.eDy := 85 * mmx;
              SetWorldTransform(Canvas.Handle, XForm);
  
  
              // Here I draw the front side of the Card
  
  
              // New page for back side
              NewPage;
  
              SetGraphicsMode(Canvas.Handle, GM_ADVANCED);
              XForm.eM11 := Cos(DegToRad(270));
              XForm.eM12 := -Sin(DegToRad(270));
              XForm.eM21 := Sin(DegToRad(270));
              XForm.eM22 := Cos(DegToRad(270));
              XForm.eDx := (PageHeight div 2);
              XForm.eDy := 0;
              SetWorldTransform(Canvas.Handle, XForm);
  
  
              // Here I draw the back side of the Card
  
              EndDoc;
  
              try
                bmp.Destroy;
              except
              end;
  
  
            finally
              // unlock devmode handle.
              GlobalUnlock(Devmode);
            end;
          end; { If }
  
  
        end;
  end;
  </code></pre>
  
  <p>Thank you.</p>