1. 程式人生 > 其它 >delphi SynPDF 新增大綱(書籤)

delphi SynPDF 新增大綱(書籤)

SynPDF 新增大綱(書籤)

屬性和方法

TPdfDocument.UseOutlines

property UseOutlines: boolean;

用於指定PDF文件是否將使用大綱。

TPdfDocument.OutlineRoot

property OutlineRoot: TPdfOutlineRoot;

PDF文件的大綱。只讀屬性。

在使用OutlineRoot屬性之前,必須將UseOutlines設定為True

TPdfDocument.CreateOutline

function CreateOutline(const Title: string; Level: integer; TopPosition: Single): TPdfOutlineEntry;

在當前頁面的指定位置建立大綱節點。

引數

Title 標題。

Level 級別。

TopPosition 相對於頁面底部的偏移量。

返回值

新增的新節點。

大綱樹節點是根據Level級別建立的(Level 為0時是根節點),它被新增到相同級別節點列表的末尾。

TPdfOutlineEntry.Parent

property Parent: TPdfOutlineEntry;

父大綱節點。

TPdfOutlineEntry.Next

property Next: TPdfOutlineEntry;

下一個大綱節點。

TPdfOutlineEntry.Prev

property Prev: TPdfOutlineEntry;

上一個大綱節點。

TPdfOutlineEntry.First

property First: TPdfOutlineEntry;

第一個大綱節點。

TPdfOutlineEntry.Last

property Last: TPdfOutlineEntry;

最後一個大綱節點。

TPdfOutlineEntry.Opened

property Opened: boolean;

是否展開節點。

例子

新增書籤

uses SynPdf;

procedure TForm1.Button6Click(Sender: TObject);
var
  Pdf: TPdfDocumentGDI;
begin
  //建立PDF文件
  Pdf := TPdfDocumentGDI.Create(True);
  //使用書籤,需要設定Create引數為True或者UseOutlines設定為True
  Pdf.UseOutlines := True;
  try
    Pdf.AddPage;
    //新增總書籤(Level為級別,從0開始,TopPosition為位置,從頁面底開始)
    Pdf.CreateOutline('文件開始', 0, Pdf.Canvas.Page.PageHeight);
    //新增第一頁
    with Pdf.VCLCanvas do
    begin
      Font.Name := '宋體';
      Font.Size := 20;
      TextOut(100, 100, '第一頁標題');
      TextOut(100, 200, '第一頁內容');
      Pdf.CreateOutline('第一頁標題', 1, Pdf.Canvas.Page.PageHeight - 100);
    end;
    //新增第二頁
    Pdf.AddPage;
    with Pdf.VCLCanvas do
    begin
      Font.Name := '宋體';
      Font.Size := 20;
      TextOut(100, 100, '第二頁標題');
      TextOut(100, 200, '第二頁內容');
      Pdf.CreateOutline('第二頁標題', 1, Pdf.Canvas.Page.PageHeight - 100);
    end;
    //新增第三頁
    Pdf.AddPage;
    with Pdf.VCLCanvas do
    begin
      Font.Name := '宋體';
      Font.Size := 20;
      TextOut(100, 100, '第三頁標題');
      TextOut(100, 200, '第三頁內容');
      Pdf.CreateOutline('第三頁標題', 1, Pdf.Canvas.Page.PageHeight - 100);
    end;
    //展開書籤
    Pdf.OutlineRoot.First.Opened := True;
    Pdf.SaveToFile('C:\Users\Administrator\Desktop\ceshi.pdf');
  finally
    Pdf.Free;
  end;
end;