1. 程式人生 > 其它 >delphi llPDFLib 文件設定

delphi llPDFLib 文件設定

llPDFLib 文件設定

屬性和方法

TPDFDocument.OutputStream

property OutputStream: TStream;

設定了此屬性,則生成文件的輸出在流中,而不是在檔案中。

TPDFDocument.OnePass

property OnePass: Boolean;

直接建立文件。

建立大型文件時建議使用此屬性。當建立下一個頁面時,畫布的內容將被直接寫入輸出流。與此相關的是無法更改 CurrentPageIndex

如果指定了OutputStream,該值將被忽略。

TPDFDocument.Compression

property Compression: TCompressionType;

指定是否對PDF文件中畫布的內容使用壓縮。

TPDFDocument.NonEmbeddedFonts

property NonEmbeddedFonts: TStringList;

設定不被嵌入到文件中的TTF字型列表。

TPDFDocument.Printing

property Printing: Boolean;

判斷元件是否正在建立新文件。

TPDFDocument.Abort

procedure Abort;

停止建立PDF文件。傳送到檔案的所有資料都將丟失。

TCompressionType

指定頁面內容壓縮。

unit

llPDFTypes

TCompressionType = (
  ctNone,
  ctFlate
);
  • ctNone 不壓縮

  • ctFlate 使用平面壓縮排行壓縮

例子

輸出到流

uses llPDFDocument;

procedure TForm1.Button12Click(Sender: TObject);
var
  Pdf: TPDFDocument;
  Stream: TMemoryStream;
begin
  Pdf := TPDFDocument.Create(nil);
  Stream := TMemoryStream.Create;
  try
    //設定文件輸出流
    Pdf.OutputStream := Stream;
    Pdf.BeginDoc;
    Pdf.EndDoc;
    //將流中的內容輸出到檔案
    Stream.SaveToFile('C:\Users\Administrator\Desktop\ceshi.pdf');
  finally
    Stream.Free;
    Pdf.Free;
  end;
end;

設定不嵌入字型

procedure TForm1.Button13Click(Sender: TObject);
var
  Pdf: TPDFDocument;
begin
  Pdf := TPDFDocument.Create(nil);
  try
    //建立PDF文件
    Pdf.AutoLaunch := True;
    Pdf.FileName := 'C:\Users\Administrator\Desktop\ceshi.pdf';
    //設定不嵌入文件的字型(只能設定TTF字型,可以減小文件的大小)
    Pdf.NonEmbeddedFonts.Add('Tahoma');
    Pdf.NonEmbeddedFonts.Add('Arial');
    Pdf.BeginDoc;
    with Pdf.Canvas do
    begin
      Font.Name := 'Tahoma';
      Font.Size := 20;
      TextOut(100, 100, 'Tahoma');
      Font.Name := 'Arial';
      Font.Size := 20;
      TextOut(100, 150, 'Arial');
    end;
    Pdf.EndDoc;
  finally
    Pdf.Free;
  end;
end;

停止建立文件

procedure TForm1.Button14Click(Sender: TObject);
var
  Pdf: TPDFDocument;
  I: Integer;
begin
  Pdf := TPDFDocument.Create(nil);
  try
    //建立PDF文件
    Pdf.AutoLaunch := True;
    Pdf.FileName := 'C:\Users\Administrator\Desktop\ceshi.pdf';
    Pdf.BeginDoc;
    with Pdf.Canvas do
    begin
      for I := 0 to 50 do
        TextOut(100, 50 + I * 20, IntToStr(I));
    end;
    //停止建立文件
    if Pdf.Printing then Pdf.Abort;
  finally
    Pdf.Free;
  end;
end;

建立大檔案

uses llPDFDocument, llPDFTypes;

procedure TForm1.Button15Click(Sender: TObject);
var
  Pdf: TPDFDocument;
  I, J: Integer;
begin
  Pdf := TPDFDocument.Create(nil);
  try
    //建立PDF文件
    Pdf.AutoLaunch := True;
    Pdf.FileName := 'C:\Users\Administrator\Desktop\ceshi.pdf';
    //直接建立文件,建立大型文件時使用(設定OutputStream後不起作用)
    Pdf.OnePass := True;
    //壓縮內容
    Pdf.Compression := ctFlate;
    Pdf.BeginDoc;
    for I := 1 to 1000 do
    begin
      if I <> 1 then
        Pdf.NewPage;
      with Pdf.Canvas do
      begin
        Font.Name := '宋體';
        Font.Size := 11;
        for J := 1 to 50 do
          TextOut(20, J * 20, IntToStr(I) + '頁' + IntToStr(J) + '行 *******************');
      end;
    end;
    Pdf.EndDoc;
  finally
    Pdf.Free;
  end;
end;