ICode9

精准搜索请尝试: 精确搜索
首页 > 其他分享> 文章详细

delphi llPDFLib 常用功能

2022-02-10 12:35:39  阅读:203  来源: 互联网

标签:常用 mm 英寸 delphi PDF 文档 TPDFDocument Pdf 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;

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
      Title := '文档标题';
      Subject := '文档主题';
      Author := '文档作者';
      Creator := '文档生成器';
      Keywords := '文档关键字';
    end;
    Pdf.BeginDoc;
    Pdf.EndDoc;
  finally
    Pdf.Free;
  end;
end;

标签:常用,mm,英寸,delphi,PDF,文档,TPDFDocument,Pdf,llPDFLib
来源: https://www.cnblogs.com/txgh/p/15878537.html

本站声明: 1. iCode9 技术分享网(下文简称本站)提供的所有内容,仅供技术学习、探讨和分享;
2. 关于本站的所有留言、评论、转载及引用,纯属内容发起人的个人观点,与本站观点和立场无关;
3. 关于本站的所有言论和文字,纯属内容发起人的个人观点,与本站观点和立场无关;
4. 本站文章均是网友提供,不完全保证技术分享内容的完整性、准确性、时效性、风险性和版权归属;如您发现该文章侵犯了您的权益,可联系我们第一时间进行删除;
5. 本站为非盈利性的个人网站,所有内容不会用来进行牟利,也不会利用任何形式的广告来间接获益,纯粹是为了广大技术爱好者提供技术内容和技术思想的分享性交流网站。

专注分享技术,共同学习,共同进步。侵权联系[81616952@qq.com]

Copyright (C)ICode9.com, All Rights Reserved.

ICode9版权所有