procedure TForm4.FormCloseQuery(Sender: TObject; var CanClose: boolean);
begin
MyBitmap.Free;
myImage.Free;
end;
procedure TForm4.FormResize(Sender: TObject);
begin
loadTemplate(Sender);
end;
procedure TForm4.Timer1Timer(Sender: TObject);
begin
loadTemplate(Sender);
end;
procedure TForm4.loadTemplate(Sender: TObject);
begin
// if bitmap already Create-ed then start fresh
if MyBitmap <> nil then
MyBitmap.Destroy;
// create bmp object
MyBitmap := TBitmap.Create;
//setup default page
MyCanvas.Width:=720;
MyCanvas.height:=935;
MyBitmap.SetSize(720, 935);
MyBitmap.Canvas.FillRect(0,0,MyBitmap.Width,MyBitmap.Height);
// call paint function
MyCanvasPaint(Sender);
end;
procedure TForm4.MyCanvasPaint(Sender: TObject);
var
textarea: TRect;
mytext: string;
mytextstyle: TTextStyle;
begin
// make sure canvas is same size as bmp
// this is here in case we dynamically adjust page size
if MyCanvas.Width<>MyBitmap.Width then begin
MyCanvas.Width:=MyBitmap.Width;
Exit;
end;
if MyCanvas.Height<>MyBitmap.Height then begin
MyCanvas.Height:=MyBitmap.Height;
Exit;
end;
// Background - line around page
MyBitmap.Canvas.Brush.Color := clWhite;
MyBitmap.Canvas.Pen.Color := clSilver;
MyBitmap.Canvas.Rectangle(5, 5, 715, 930);
// set report title
MyBitmap.Canvas.Font.Name:='Arial';
MyBitmap.Canvas.Font.Size:=24;
MyBitmap.Canvas.Font.Style := [fsBold];
MyBitmap.Canvas.Font.Color:=clBlack;
MyBitmap.Canvas.Brush.Color := clNone;
MyBitmap.Canvas.TextOut(180, 50, 'This is the Report Title');
// rectangle header line
MyBitmap.Canvas.Brush.Color:=clRed;
MyBitmap.Canvas.Pen.Color := clNone;
MyBitmap.Canvas.Pen.Style := psSolid;
MyBitmap.Canvas.Rectangle(Bounds(50, 100, 620, 4));
// paragraph of text
mytext:='This is a sentence where I can contain it in a rectangle and even have it be multi-line. '
+ 'This is a sentence where I can contain it in a rectangle and even have it be multi-line.';
textarea:=Rect(50,140,620,200);
{reset font styles}
MyBitmap.Canvas.Font.Style := [];
{set new font style}
MyBitmap.Canvas.Font.Name := 'Times New Roman';
MyBitmap.Canvas.Font.Size:=14;
MyBitmap.Canvas.Font.Style := [fsItalic];
MyBitmap.Canvas.Font.Color:=clBlue;
mytextstyle := MyBitmap.Canvas.TextStyle;
mytextstyle.Wordbreak:=True;
mytextstyle.SingleLine:=False;
//load image
myImage:= TBitmap.Create;
myImage.LoadFromFile(BMP_FNAME);
MyBitmap.Canvas.Draw(50, 240, myImage);
// render bmp
MyBitmap.Canvas.TextRect(textarea, 50 {lf for txtarea}, 140 {top for txtarea}, mytext, mytextstyle);
MyCanvas.Canvas.Draw(0,0,MyBitmap);
end;