saving TPrintview as JPEG, BMP, TIFF

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

saving TPrintview as JPEG, BMP, TIFF

Postby LarryK » May 7th, 2005, 3:17 pm

TPrintview
THANK YOU for creating such a terrific component.
I use it to create medical notes because my handwriting is illegible. Really.

I would like to save the TPrintview document to a file that my Turbopower APRO fax server can poll and fax out later in the day, but APRO fax only can load/fax files in BMP, TIFF, JPEG formats.

Can you point me to a source for a component to save the TPrintview document in any of these formats. Thanks

Larry
LarryK
Active Member
Active Member
 
Posts: 6
Joined: May 7th, 2005, 3:11 pm

Postby Radagast » May 7th, 2005, 9:11 pm

Can't you simply create bitmap (TBitmap I think) and rewrite all text from this component to it? Or set constant size and position and use screenshot? Maybe these are stupid questions but I haven't seen this component yet.
Radagast
Active Member
Active Member
 
Posts: 24
Joined: May 1st, 2005, 9:32 pm
Location: Poland

Postby LarryK » May 7th, 2005, 10:41 pm

The reason I am using tPrintview is because my document is a very complex compound document with images, frames with different sized text and the like. And, once created, there is no procedure like SaveToBitmapFile.
LarryK
Active Member
Active Member
 
Posts: 6
Joined: May 7th, 2005, 3:11 pm

Postby Radagast » May 8th, 2005, 12:59 pm

I've downloaded it and I'll look at it. But I really think that screenshot or something like that should work. Or if you can print it (and I think it is made for this) you can print it into pdf file, so maybe there's also option to print to bitmap. You should try in system options (or search for program to printng into bmp).
Radagast
Active Member
Active Member
 
Posts: 24
Joined: May 1st, 2005, 9:32 pm
Location: Poland

Postby Kambiz » May 9th, 2005, 12:32 pm

Async Pro has a fax driver, which you can use it to directly print documents on the virtual fax.

In the other hand, you can use the Pages property of PrintPreview to convert each page (which is a metafile) to a bitmap and/or jpeg image.
Kambiz
User avatar
Kambiz
Administrator
Administrator
 
Posts: 2429
Joined: March 7th, 2003, 7:10 pm

Postby LarryK » May 12th, 2005, 11:38 am

Thanks Kambiz - - - but converting the pages to jpeg is exactly the step I want, but don't know how to do !

Printing to the fax driver forces a dialog to pop up and the application I am working on will store documents created during the day and fax them out, unattended, at night with no users in the building.


Larry.
LarryK
Active Member
Active Member
 
Posts: 6
Joined: May 7th, 2005, 3:11 pm

Postby Kambiz » May 12th, 2005, 12:28 pm

I hope the following code be helpful.

Code: Select all
procedure SavePreviewPageAsBitmap(Preview: TPrintPreview;
  PageNo: Integer; const FileName: String);
var
  Metafile: TMetafile;
  Bitmap: TBitmap;
  JPEG: TJPEGImage;
begin
  Metafile := Preview.Pages[PageNo];
  if Metafile <> nil then
  begin
    Bitmap := TBitmap.Create;
    try
      Bitmap.Width := Metafile.Width;
      Bitmap.Height := Metafile.Height;
      Bitmap.Canvas.Draw(0, 0, Metafile);
      Bitmap.SaveToFile(FileName);
    finally
      Bitmap.Free;
    end;
  end;
end;

procedure SavePreviewPageAsJpeg(Preview: TPrintPreview;
  PageNo: Integer; const FileName: String);
var
  Metafile: TMetafile;
  Bitmap: TBitmap;
  JPEG: TJPEGImage;
begin
  Metafile := Preview.Pages[PageNo];
  if Metafile <> nil then
  begin
    Bitmap := TBitmap.Create;
    try
      Bitmap.Width := Metafile.Width;
      Bitmap.Height := Metafile.Height;
      Bitmap.Canvas.Draw(0, 0, Metafile);
      JPEG := TJPEGImage.Create;
      try
        JPEG.Assign(Bitmap);
        JPEG.JPEGNeeded;
        JPEG.SaveToFile(FileName);
      finally
        JPEG.Free;
      end;
    finally
      Bitmap.Free;
    end;
  end;
end;

procedure TMainForm.Button1Click(Sender: TObject);
begin
  SavePreviewPageAsBitmap(PrintPreview, 1, 'C:\test.bmp');
  SavePreviewPageAsJpeg(PrintPreview, 1, 'C:\test.jpg');
end;
Kambiz
User avatar
Kambiz
Administrator
Administrator
 
Posts: 2429
Joined: March 7th, 2003, 7:10 pm

Postby LarryK » May 13th, 2005, 1:43 am

T H A N K Y O U K A M B I Z ! ! !
I really appreciate the example code.
It will take me a few weeks to work it into my existing program.....coding is not my "day job"

Larry.
LarryK
Active Member
Active Member
 
Posts: 6
Joined: May 7th, 2005, 3:11 pm


Return to DELPHI AREA Projects

Who is online

Users browsing this forum: No registered users and 1 guest

cron