#1 Re: PDF Engine » Beginner questions about making a text box ((Multiline)TextRect?) » 2018-06-10 08:40:04

Oliver, unfortunately I can't test the code with Delphi 2007 myself. However, it may be that the implementation in the link has minor flaws that lead to the first line being overwritten.

I found a similar approach in the Lazarus forum Canvas Text Justified left AND right. Additionally, you must include VCLCanvas in the procedure. A simple Delphi Implementation of RPosEx can be found here or has to be written by yourself.

ln2n9Bw.png

With Hyphenation in Delphi, what AFAIK currently only works with versions <= 2007, results can certainly be improved.

#3 Re: PDF Engine » Beginner questions about making a text box ((Multiline)TextRect?) » 2018-06-07 12:24:28

I'm also a blind fish sometimes. Of course there is already TTextFormat in Delphi 2007, which is preferable to an API call. Since you probably have Unicode in your memo, DrawTextW should at least be used.

      // lText is a local variable of type string
      lText := Memo1.Lines; // because the 2nd arg is var Text: string
      TextRect(Rect1, lText, [tfLeft, tfWordBreak]);

#4 Re: PDF Engine » Beginner questions about making a text box ((Multiline)TextRect?) » 2018-06-07 07:01:58

I hope I understood your problem correctly. With an appropriate resolution of the canvas (only whole numbers can be used here), page margins can be set relatively precisely. The following applies: the higher the resolution, the more precisely it can be positioned.

After you have filled a TRect with appropriate values, you can set the TTextStyle properties of the canvas or use the overloaded method with the TTextStyle argument in TextOut. Unfortunately I only have Delphi 2007 available and therefore depend on the direct API method DrawText.

In your code I have set all four margins of the PDF to 20 mm and output the headline centered. With 2 mm distance the text follows from Memo1.

You can play around with the left and right margins, because the page can take up a little more text than fits into one line in the memo control.

implementation

{$R *.dfm}

uses synPDF;

var
  filename: string;
  pdf: TPdfDocumentGDI;
  page: TPdfPage;
  rect1: TRect;

procedure TForm2.Button1Click(Sender: TObject);
const
  // if you need a finer canvas resolution, use a factor to multiply with
  Factor = 2
  Resolution = 72 * Factor;
  OneMM = Resolution / 25.4; // = 1 mm
begin
  filename := ExtractFilePath(ParamStr(0)) + 'example.pdf';

  pdf := TPdfDocumentGDI.Create();
  try
    pdf.ScreenLogPixels := Resolution;
    page := pdf.AddPage;

    with pdf.VCLCanvas do begin
      Font.Name := 'Times';
      Font.Size := 14 * Factor;

      TextOut((pdf.VCLCanvasSize.cx - TextWidth(Edit1.Text)) div 2,
               Round(20 * OneMM), Edit1.Text);

      with Rect1 do begin
        Left   := Round(20 * OneMM);
        Top    := Round(22 * OneMM + TextHeight(Edit1.Text));
        Right  := pdf.VCLCanvasSize.cx - Round(20 * OneMM);
        Bottom := pdf.VCLCanvasSize.cy - Round(20 * OneMM);
      end;
      Font.Size := 12 * Factor;
      // My Delphi 2007 has no TTextStyle
      DrawText(Handle, PAnsiChar(Memo1.Text), Length(Memo1.Text),
               Rect1, DT_LEFT or DT_WORDBREAK); Text
    end;

    pdf.SaveToFile(filename);
    Shellexecute(Handle, 'open', PChar(filename), '', '', SW_Normal);
  finally
    pdf.Free;
  end;
end;

end.

#5 Re: mORMot 1 » Is it possible to execute multiple SQL statements at once? » 2015-10-05 09:42:31

AFAIK you can execute a SQL script with SQLite3 like.

YourSQLDBSQLite3ConnectionProperties.MainConnection.DB.ExecuteAll(StringFromFile(PathToScript));

Board footer

Powered by FluxBB