title: Delphi Image Print
body: <p>I have an array of TImages each one containing thumbnail of a Image file in a specified directory and their Hint property set to their Image Filename for printing purpose.
  all files are located on a remote server in a shared directory (Example: \192.168.1.50\imgscan\12-14-54\ *.jpg).</p>
  
  <p>also each Image has a corresponding TCheckBox that users can check to mark images for printing.</p>
  
  <p>I use the following code for printing (variable <code>images_index</code> holds the number of images in the selected directory)...</p>
  
  <pre><code>procedure PrintSelectedImages;
    var
      i: integer;
      R1, R2: TRect;
      Picture: TPicture;
      Bitmap: TBitmap;
      Total, done: integer;
  begin
    Total := 0;
    done := 0;
  
    for i := 0 to images_index - 1 do
      if Checks[i].Checked then
        INC(Total);
  
    if Total = 0 then
      begin
        MessageDlg('No Images Selected!', mtInformation, [mbOK], 0);
        Exit;
      end;
  
    Printer.BeginDoc;
  
   if PrintDialog1.Execute then
     begin
  
       for i := 0 to images_index - 1 do
         begin
  
         if Checks[i].Checked then
           begin
  
             try
               Picture := TPicture.Create;
               Picture.LoadFromFile(images[i].Hint);
               Bitmap := TBitmap.Create;
             try
               Bitmap.Width := Picture.Width;
               Bitmap.Height := Picture.Height;
               Bitmap.Canvas.Draw(0, 0, Picture.Graphic);
  
               R1 := Rect(0, 0, Bitmap.Width, Bitmap.Height);
               R2 := Rect(0, 0, Printer.PageWidth, Printer.PageHeight);
               Printer.Canvas.CopyRect(R2, Bitmap.Canvas, R1);
  
               INC(done);
             finally
               Bitmap.Free;
             end;
             finally
               Picture.Free;
             end;
  
            if done &lt; Total  then
              Printer.NewPage;
           end; // if
  
         end;  // i
  
     end;  // if
  
  
    Printer.EndDoc;
  end;
  </code></pre>
  
  <p>Now...
  On Microsoft XPS Document Writer I have no problems and all the pages are printed fine, but on real printers most of the time white papers come out and sometimes only some of the selected images are printed (for example 4 of 10 selected files).</p>
  
  <p>What is the problem with my code? i googled a lot and found nothing!</p>
  
  <p>Thanks.</p>