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;


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM