• delphi llPDFLib 常用功能


    llPDFLib 常用功能

    属性和方法

    TPDFDocument.Create

    constructor Create(AOwner: TComponent); override;
    

    创建并初始化 TPDFDocument 的一个实例。

    参数

    AOwner 建立组件与其所有者的关系。

    TPDFDocument.BeginDoc

    procedure BeginDoc;
    

    开始一个新的PDF文档。在创建的文档中添加第一页。

    TPDFDocument.EndDoc

    procedure EndDoc;
    

    结束PDF文档的创建工作。将所有未保存的数据重置到输出流。

    TPDFDocument.NewPage

    procedure NewPage;
    

    在PDF文档中添加新页面,并将 Canvas 传输到此页面。

    TPDFDocument.FileName

    property FileName: string;
    

    创建的PDF文档的名称。

    如果指定了OutputStream,该值将被忽略。

    TPDFDocument.AutoLaunch

    property AutoLaunch: Boolean;
    

    指定在默认PDF查看器中创建后是否打开生成的PDF文件。

    TPDFDocument.Canvas

    property Canvas: TCanvas;
    

    标准TCanvas,可以作为标准HDC操作。

    TPDFDocument.CurrentPage

    property CurrentPage: TPDFPage;
    

    文档中的当前页,可以用绘图操作。

    TPDFDocument.DocumentInfo

    property DocumentInfo: TPDFDocInfo;
    

    属性定义有关PDF文档的信息。

    TPDFDocInfo.Author

    property Author: string;
    

    指定生成文档中的作者。

    TPDFDocInfo.Creator

    property Creator: string;
    

    指定生成文档中的生成器。

    TPDFDocInfo.Keywords

    property Keywords: string;
    

    指定生成文档中的关键字。

    TPDFDocInfo.Subject

    property Subject: string;
    

    指定生成文档的主题。

    TPDFDocInfo.Title

    property Title: string;
    

    指定生成文档的标题。

    TPDFPage.Size

    property Size: TPDFPageSize;
    

    页面大小。

    TPDFCanvas.Height

    property Height: Integer;
    

    Canvas 的高度。

    TPDFCanvas.Width

    property Width: Integer;
    

    Canvas 的宽度。

    TPDFPageSize

    确定页面的大小。

    unit

    llPDFTypes

    TPDFPageSize = (
      psLetter,
      psA4,
      psA3,
      psLegal,
      psB5,
      psC5,
      ps8x11,
      psB4,
      psA5,
      psFolio,
      psExecutive,
      psEnvB4,
      psEnvB5,
      psEnvC6,
      psEnvDL,
      psEnvMonarch,
      psEnv9,
      psEnv10,
      psEnv11
    );
    
    • psLetter 216 x 279 mm/8.5 x 11 英寸
    • psA4 210 x 297 mm/8.3 x 11.7 英寸
    • psA3 297 x 420 mm/11.7 x 16.5 英寸
    • psLegal 216 x 356 mm/8.5 x 14 英寸
    • psB5 176 x 250 mm/6.9 x 9.8 英寸
    • psC5 162 x 229 mm/6.4 x 9.0 英寸
    • ps8x11 8 x 11 英寸
    • psB4 250 x 353 mm/9.8 x 13.9 英寸
    • psA5 148 x 210 mm/5.8 x 8.3 英寸
    • psFolio 210 x 330 mm/8.27 x 13 英寸
    • psExecutive 184 x 267 mm/7.25 x 10.5 英寸
    • psEnvB4 250 x 353 mm/9.8 x 13.9 英寸
    • psEnvB5 176 x 250 mm/6.9 x 9.8 英寸
    • psEnvC6 114 x 162 mm/4.5 x 6.4 英寸
    • psEnvDL 110 x 220 mm/4.4 x 8.8 英寸
    • psEnvMonarch 190.5 x 98.4 mm/7.5 x 3.875 英寸
    • psEnv9 225.4 x 98.4 mm/8.875 x 3.875 英寸
    • psEnv10 241.3 x 104.8 mm/9.5 x 4.125 英寸
    • psEnv11 263.5 x 114.3 mm/10.375 x 4.5 英寸

    例子

    创建文档

    uses llPDFDocument;
    
    procedure TForm1.Button1Click(Sender: TObject);
    var
      Pdf: TPDFDocument;
    begin
      Pdf := TPDFDocument.Create(nil);
      try
        //设置生成PDF文件后打开该文件
        Pdf.AutoLaunch := True;
        //设置生成的文件名
        Pdf.FileName := 'C:\Users\Administrator\Desktop\ceshi.pdf';
        //开始创建新PDF文档,并添加第一页
        Pdf.BeginDoc;
        //结束PDF文档的创建
        Pdf.EndDoc;
      finally
        Pdf.Free;
      end;
    end;
    

    操作Canvas

    uses llPDFDocument;
    
    procedure TForm1.Button2Click(Sender: TObject);
    var
      Pdf: TPDFDocument;
    begin
      Pdf := TPDFDocument.Create(nil);
      try
        //创建PDF文档
        Pdf.AutoLaunch := True;
        Pdf.FileName := 'C:\Users\Administrator\Desktop\ceshi.pdf';
        Pdf.BeginDoc;
        //通过Canvas输出内容
        with Pdf.Canvas do
        begin
          Pen.Color := clRed;
          Pen.Width := 2;
          Brush.Color := clInfoBk;
          Rectangle(100, 100, 400, 200);
          Font.Name := '宋体';
          Font.Size := 20;
          TextOut(200, 120, '测试内容');
          Pen.Color := clYellow;
          Pen.Width := 5;
          MoveTo(100, 250);
          LineTo(400, 250);
        end;
        //添加新页面,Canvas指向新增页面
        Pdf.NewPage;
        with Pdf.Canvas do
        begin
          Font.Name := '宋体';
          Font.Size := 20;
          TextOut(200, 120, '新增页面');
        end;
        Pdf.EndDoc;
      finally
        Pdf.Free;
      end;
    end;
    

    添加页面

    uses llPDFDocument, llPDFTypes;
    
    procedure TForm1.Button3Click(Sender: TObject);
    var
      Pdf: TPDFDocument;
    begin
      Pdf := TPDFDocument.Create(nil);
      try
        //创建PDF文档
        Pdf.AutoLaunch := True;
        Pdf.FileName := 'C:\Users\Administrator\Desktop\ceshi.pdf';
        //开始创建新PDF文档,添加第一页
        Pdf.BeginDoc;
        //设置页面纸张
        Pdf.CurrentPage.Size := psA4;
        //添加新页面,当前页指向新增页面
        Pdf.NewPage;
        //设置页面自定义纸张
        Pdf.CurrentPage.Width := 300;
        Pdf.CurrentPage.Height := 400;
        //结束PDF文档的创建。
        Pdf.EndDoc;
      finally
        Pdf.Free;
      end;
    end;
    

    添加文档信息

    uses llPDFDocument{$IFNDEF UNICODE}, llPDFMisc{$ENDIF};
    
    procedure TForm1.Button4Click(Sender: TObject);
    var
      Pdf: TPDFDocument;
    begin
      Pdf := TPDFDocument.Create(nil);
      try
        //创建PDF文档
        Pdf.AutoLaunch := True;
        Pdf.FileName := 'C:\Users\Administrator\Desktop\ceshi.pdf';
        //设置文档的信息
        with Pdf.DocumentInfo do
        begin
          {$IFDEF UNICODE}
          Title := '文档标题';
          Subject := '文档主题';
          Author := '文档作者';
          Creator := '文档生成器';
          Keywords := '文档关键字';
          {$ELSE}
          Title := UnicodeChar('文档标题', GB2312_CHARSET);
          Subject := UnicodeChar('文档主题', GB2312_CHARSET);
          Author := UnicodeChar('文档作者', GB2312_CHARSET);
          Creator := UnicodeChar('文档生成器', GB2312_CHARSET);
          Keywords := UnicodeChar('文档关键字', GB2312_CHARSET);
          {$ENDIF}
        end;
        Pdf.BeginDoc;
        Pdf.EndDoc;
      finally
        Pdf.Free;
      end;
    end;
    
  • 相关阅读:
    Apriori 算法-如何进行关联规则挖掘
    Nginx 常用命令
    Nginx Location匹配规则
    Nginx 负载均衡
    angular 路由传参的三种方式
    JAVA中final关键字的作用
    Python函数参数和注解是什么
    JMeter测试计划配置项解析
    JMeter元件作用域实践指南
    原来Python函数只是个对象
  • 原文地址:https://www.cnblogs.com/txgh/p/15878537.html
Copyright © 2020-2023  润新知