Field Example

Top  Previous  Next

Example:

 

procedure TForm1.Button1Click(Sender: TObject);

var pdf : TWPPDFPrinter;  res : Integer;

    i, x, y, h, hh, w : Integer;

    can : TCanvas;

begin

    pdf := TWPPDFPrinter.Create(nil);

    try

      pdf.Filename := PDFName.Text;

      pdf.AutoLaunch := true;

      pdf.BeginDoc;

 

         res := Screen.PixelsPerInch;

         pdf.StartPage(

           Round( 21 * res / 2.54 ),

           Round( 29.7 * res / 2.54 ),

           res, res, 0

           );

         x := Round( 3 * res / 2.54 );

         y := Round( 3 * res / 2.54 );

         h := Round( 1 * res / 2.54 );

         can := pdf.Canvas;

         hh := Round( 0.7 * res / 2.54 );

         can.Font.Height :=  -hh;

         can.Font.Name := 'Arial';

         // ---

         can.TextOut(x,y, SomeText.Text);

         inc(y,h);

         for i:=1 to StrToIntDef(FIELDCOUNT.Text, 1do

         begin

           can.TextOut(x,y, Format('%d:', [i]));

           w := Round( 1.5 * res / 2.54 );

 

           pdf.DrawTextField(

                  Edit1Text.Text + IntToStr(i),

                  Rect( x+w, y, x + Round( 5 * res / 2.54 ), y + hh),

                  Edit1Name.Text  + IntToStr(i)

               );

 

           pdf.DrawCheckbox(  Rect( x+Round( 6 * res / 2.54 ), y, x + Round( 6 * res / 2.54 )+hh, y + hh)  ,

             Check1.Checked,

             Check1Name.Text + IntToStr(i)

           );

 

 

           inc(y, h);

         end;

          // ---

         pdf.EndPage;

         pdf.EndDoc;

 

    finally 

      pdf.Free;

    end;

end;