⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 tabledemo.dpr

📁 生成PDF文档的控件
💻 DPR
字号:
{*******************************************************}
{                                                       }
{       This unit is part of the VISPDF VCL library.    }
{       Written by R.Husske - ALL RIGHTS RESERVED.      }
{                                                       }
{       Copyright (C) 2000-2008, www.vispdf.com         }
{                                                       }
{       e-mail: support@vispdf.com                      }
{       http://www.vispdf.com                           }
{                                                       }
{*******************************************************}

program TableDemo;
{$APPTYPE CONSOLE}
uses
  SysUtils,
  Graphics,
  Classes,
  DB,
  DBTables,
  VPDFDoc;

var
   VPDF: TVPDF;
   PageNum, VertPos: Integer;
   CustomerTable: TTable;

const
   TableName = 'Customer.DB';

   procedure PrintRow( Position: Integer; No, Company, Addr, City: String; ShowBackground : boolean );
   begin
       if ShowBackground then
       begin
           VPDF.CurrentPage.SetRGBColor($FFF3DD);
           VPDF.CurrentPage.Rectangle(50, Position, 520, 20);
           VPDF.CurrentPage.Fill;
           VPDF.CurrentPage.SetRGBColor(clBlack);
       end;
       VPDF.CurrentPage.TextOut(  70, Position, 0, No );
       VPDF.CurrentPage.TextOut( 110, Position, 0, Company );
       VPDF.CurrentPage.TextOut( 300, Position, 0, Addr );
       VPDF.CurrentPage.TextOut( 480, Position, 0, City );
   end;

   procedure PreparePage;
   begin
       VPDF.CurrentPage.SetFont( 'Arial', [fsItalic], 10 );
       VPDF.CurrentPage.TextOut( 50, VertPos, 0, TableName + '  Page'+ IntToStr(PageNum) );
       VPDF.CurrentPage.TextOut( 480, VertPos, 0, DateTimeToSTr(Now) );
       VPDF.CurrentPage.MoveTo( 50, VertPos+15 );
       VPDF.CurrentPage.LineTo( 570, VertPos+15 );
       VPDF.CurrentPage.MoveTo( 50, VertPos+45 );
       VPDF.CurrentPage.LineTo( 570, VertPos+45 );
       VPDF.CurrentPage.Stroke;
       VPDF.CurrentPage.SetFont('Times New Roman', [fsItalic, fsBold], 12);
       VPDF.CurrentPage.SetRGBFillColor(clNavy);
       PrintRow( VertPos + 25, 'No', 'Company', 'Addr', 'City', false);
       VPDF.CurrentPage.SetRGBFillColor(clBlack);
       Inc( VertPos, 20 );
   end;

var
    Back: boolean;

begin
  CustomerTable := TTable.Create(nil);
  try
      CustomerTable.DatabaseName := 'DBDEMOS';   //  Open demo customer
      CustomerTable.TableName := TableName;      //   database table
      CustomerTable.Active := true;              //
      CustomerTable.First;
      VPDF:= TVPDF.Create(nil);
      try
        VPDF.AutoLaunch := true;                                      // PDF file will be shown automatically
        VPDF.FileName := '.\TableDemo.pdf';                           // Set PDF filename
        VPDF.PageLayout := plOneColumn;        
        VPDF.BeginDoc;                                                // Create PDF file
        VPDF.CurrentPage.SetFont('Arial', [fsBold], 24 );             // Set current font
        VPDF.CurrentPage.TextOut(200, 20, 0, 'Customer report'); // Print PDF header
        PageNum := 1;
        VertPos := 60;                                                // Draw and print
        PreparePage;                                                  //  table header
        Back := true;
        while ( not(CustomerTable.Eof) ) do
        begin
            Back := not(Back);
            if ( VertPos > 700 ) then                                 // If end of page then
            begin
                VPDF.AddPage;                                         // Add page, draw and print
                Inc(PageNum);                                         // table header and set
                VertPos := 60;                                        // new print position
                PreparePage;
            end;
            PrintRow( VertPos + 25,                                   // print  row from the current position
                      CustomerTable.FieldValues['CustNo'],
                      CustomerTable.FieldValues['Company'],
                      CustomerTable.FieldValues['Addr1'],
                      CustomerTable.FieldValues['City'],
                      Back
                      );
            Inc( VertPos, 20 );
            CustomerTable.Next;                                       // Go to next record
        end;
        VPDF.EndDoc;                                                 // Close PDF file
      finally
          VPDF.Free;
      end;
  finally
      CustomerTable.Free;
  end;
end.

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -