Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Center text and image placement using TPrinter 1

Status
Not open for further replies.

lespaul

Programmer
Feb 4, 2002
7,083
US
I have a certificate of appreciation that I want to run through the printer and add the person's name and two image files of signatures. (This is for Juror's who serve with the court)

My first question is how can I measure the length of the TEXT of the person's name so I can center it on the certificate? The length function will return the number of characters, is there some way I can use that to determine the width on the page that the name will take so that I can center it?

Secondly, can I send a BMP signature file directly to the printer at a specific location? For instance, the judge's signature needs to be 3.75 inches from the left of the page and 7 inches from the top of the page (landscape orientation).

Thanks for any suggestions!

Leslie
 
Ok, here's what I've got so far:

Code:
Procedure TfrmMain.PrintCertificates(strTermDate : string);
var
PixPerInX, PixPerInY, OffsetX, OffsetY : integer;
signimage : TGraphic;
begin
  with dmJMS.qryTemp do
  begin
    SQL.Clear;
    SQL.Add('SELECT DISTINCT Trim(Proper(FIRSTNAME))  || '' '' || Trim(Proper(LASTNAME)) ' +
    'AS FULLNAME FROM JMPMAIN INNER JOIN JMPNEWHOUR ON ' +
    'JMPMAIN.JURNUM = JMPNEWHOUR.JURNUM WHERE jmpmain.JURNUM = 13657');// TERMDATE = ' + QuotedStr(convertdateback(strTermDate)));
    Active := True;
    If not isempty then
    begin
      while not eof do
      begin
        Printer.Orientation := poLandscape;
        Printer.BeginDoc;
        PixPerInX := GetDeviceCaps(Printer.Handle, LOGPIXELSX);
        PixPerInY := GetDeviceCaps(Printer.Handle, LOGPIXELSY);
        OffsetX := GetDeviceCaps(Printer.Handle, PHYSICALOFFSETX);
        OffsetY := GetDeviceCaps(Printer.Handle, PHYSICALOFFSETY);

        Printer.Canvas.Font.Name := 'Monotype Corsiva';
        Printer.Canvas.Font.Size := 40;
        Printer.Canvas.Font.Style := [];


        SetTextAlign(Printer.Handle, VTA_CENTER);
        Printer.Canvas.TextOut((trunc(5.5 * PixPerInX) - OffsetX), trunc(((3.0) * PixPerInY) - OffsetY), FieldByName('FULLNAME').AsString);
        [COLOR=red]signimage.LoadFromFile('R:\Case Management\JMSv2\Signature Files\jnakamura.bmp');[/color]
        Printer.Canvas.Draw((trunc(3.75 * PixPerInX) - OffsetX), (trunc(7.0 * PixPerInY) - OffsetY), signimage);

        signimage.LoadFromFile('R:\Case Management\JMSv2\Signature Files\msaavedra.bmp');

        Printer.Canvas.Draw((trunc(7.25 * PixPerInX) - OffsetX), (trunc(7.0 * PixPerInY) - OffsetY), signimage);
        Printer.EndDoc;
        Next;
      end;
    end
    else
      ShowMessage('No jurors returned for the term starting' + strTermDate);
  end;
end;

which does everything except the signature graphics, CPU error when it gets to the red line. Am I doing something wrong in my graphic loading? Do I need to initialized signimage somehow?

THanks!

les
 
Use the TextWidth function of TCanvas to obtain the width of a string in pixels for the current font.

Andrew
Hampshire, UK
 
The reason you got a CPU error is that signimage is nil as you haven't created signimage. The Delphi help says
TGraphic is an abstract class that cannot be instantiated.
so you shouldn't be using TGraphic anyway.

The Delphi Help is a wonderful resource. It gives the following example
Code:
procedure TForm1.Button1Click(Sender: TObject);

var
  Bitmap : TBitMap;
begin
  Bitmap := TBitmap.Create;
  try
    with Bitmap do begin
      LoadFromFile('C:\Program Files\Common Files\Borland Shared\Images\Splash\256color\factory.bmp');
      Transparent := True;
      TransParentColor := BitMap.canvas.pixels[50,50];
      Form1.Canvas.Draw(0,0,BitMap);
      TransparentMode := tmAuto;
      Form1.Canvas.Draw(50,50,BitMap);
    end;
  finally
    Bitmap.Free;

  end;
end;
You shouldn't find it too difficult to adapt this example to work with a printer instead of a form.

Andrew
Hampshire, UK
 
Thanks for the information! I looked through the help (but obviously didn't read enough on the TGraphic!), but didn't see any of the information on the TBitmap! Learn something new every day! I was out yesterday, I'll work on this today!

les


Leslie
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top