TPrintPreview save pages to a single jpg

Please post bug reports, feature requests, or any question regarding the DELPHI AREA products here.

TPrintPreview save pages to a single jpg

Postby zeduardo2000 » November 4th, 2008, 1:22 pm

Hi, i´m using TPrintPreview to previsualize a rtf with 4 pages and images. I need to save all this 4 pages all togheter and save to a single jpg. Something like a bitmap with 800x3200 pixels...

Could someone help me on this task.
Thanks in advance.
José Eduardo
zeduardo2000
Member
Member
 
Posts: 2
Joined: November 4th, 2008, 1:07 pm

Re: TPrintPreview save pages to a single jpg

Postby Kambiz » November 4th, 2008, 6:13 pm

Each page in Print Preview is a Metafile image, so that you can easily draw it on every canvas including bitmap canvas.

The following procedure draws pages of Print Preview on a 800x3200 pixels bitmap, then convert the bitmap to JPEG, and then save it in to a file.

Code: Select all
procedure SavePagesAsJPEG(PrintPreview: TPrintPreview; const FileName: String);
var
  Bitmap: TBitmap;
  Rect: TRect;
  H, I: Integer;
  JPEG: TJPEGImage;
begin
  Bitmap := TBitmap.Create;
  try
    // draw pages on the bitmap
    Bitmap.Width := 800;
    Bitmap.Height := 3200;
    H := Bitmap.Height div PrintPreview.TotalPages;
    SetRect(Rect, 0, 0, Bitmap.Width, H);
    for I := 1 to PrintPreview.TotalPages do
    begin
      Bitmap.Canvas.StretchDraw(Rect, PrintPreview.Pages[I]);
      OffsetRect(Rect, 0, H);
    end;
    // convert bitmap to jpeg, and save it to file
    JPEG := TJPEGImage.Create;
    try
      JPEG.Assign(Bitmap);
      JPEG.JPEGNeeded;
      JPEG.SaveToFile(FileName);
    finally
      JPEG.Free;
    end;
  finally
    Bitmap.Free;
  end;
end;


Here, you will see print preview pages in General Demo as JPEG image that is created using the above procedure. To have 4 pages like your case, I set paper size in General Demo to "A5 Rotated".

Pages.jpg
JPEG image of all print preview pages.
Pages.jpg (247.38 KiB) Viewed 757 times
Kambiz
User avatar
Kambiz
Administrator
Administrator
 
Posts: 2408
Joined: March 7th, 2003, 7:10 pm

Re: TPrintPreview save pages to a single jpg

Postby zeduardo2000 » November 5th, 2008, 11:53 am

when/if you come to brasil, remember me to pay you a cup of tea or a coke. ;-)
Thanks a LOT !
zeduardo2000
Member
Member
 
Posts: 2
Joined: November 4th, 2008, 1:07 pm


Return to DELPHI AREA Products

Who is online

Users browsing this forum: No registered users and 2 guests

cron