PDFium 提取文檔內容
屬性和方法
TPdf.BitmapCount
property BitmapCount: Integer;
PDF 頁面內的 PDF 圖像對象數。
TPdf.Bitmap[]
property Bitmap[Index: Integer]: TBitmap;
指定 PDF 圖像對象的位圖數據。 索引值必須是 0 到 BitmapCount - 1。
TPdf.Title
property Title: WString;
PDF 文檔中的標題。只讀屬性。
TPdf.Subject
property Subject: WString;
PDF 文檔中的主題。只讀屬性。
TPdf.Author
property Author: WString;
PDF 文檔中的作者。只讀屬性。
TPdf.Keywords
property Keywords: WString;
PDF 文檔中的關鍵字。只讀屬性。
TPdf.Creator
property Creator: WString;
PDF 文檔中的生成器。只讀屬性。
TPdf.Producer
property Producer: WString;
PDF 文檔中的創建工具。只讀屬性。
TPdf.ModifiedDate
property ModifiedDate: WString;
PDF 文檔中的上次修改時間。只讀屬性。
TPdf.CreationDate
property CreationDate: WString;
PDF 文檔中的創建時間。只讀屬性。
TPdf.Text
function Text(StartIndex: Integer = 0; Count: Integer = MaxInt): WString;
從頁面中提取文本字符串。
參數
StartIndex 字符開始索引。從 0 開始的。
Count 提取數量。
返回值
提取的字符串
StartIndex 和 Count 參數確定要提取的字符。
例子
提取文本
在窗體上放置TPdf組件Pdf1 和 TMemo組件Memo1
procedure TForm1.Button7Click(Sender: TObject);
var
I: Integer;
begin
try
//讀取pdf文件
Pdf1.FileName := 'C:\LargeFile.pdf';
Pdf1.Active := True;
//清空列表
Memo1.Lines.Clear;
//循環pdf頁面
for I := 1 to Pdf1.PageCount do
begin
Pdf1.PageNumber := I;
Memo1.Lines.Add(IntToStr(I) + '------------------');
//提取當前頁面文本
Memo1.Lines.Add(Pdf1.Text);
end;
finally
Pdf1.Active := False;
end;
end;
提取圖片
在窗體上放置TPdf組件Pdf1
procedure TForm1.Button8Click(Sender: TObject);
var
I, J: Integer;
Bitmap: TBitmap;
begin
try
//讀取pdf文件
Pdf1.FileName := 'C:\LargeFile.pdf';
Pdf1.Active := True;
//循環pdf頁面
for I := 1 to Pdf1.PageCount do
begin
Pdf1.PageNumber := I;
//循環當前頁面圖片
for J := 0 to Pdf1.BitmapCount - 1 do
begin
//提取圖片並保存
Bitmap := Pdf1.Bitmap[J];
try
Bitmap.SaveToFile('C:\bmp_' + IntToStr(I) + '_' + IntToStr(J) + '.bmp');
finally
Bitmap.Free;
end;
end;
end;
finally
Pdf1.Active := False;
end;
end;
提取文檔信息
在窗體上放置TPdf組件Pdf1 和 TMemo組件Memo1
procedure TForm1.Button9Click(Sender: TObject);
begin
try
//讀取pdf文件
Pdf1.FileName := 'C:\LargeFile.pdf';
Pdf1.Active := True;
//讀取文檔信息
Memo1.Lines.Add('標題 ' + Pdf1.Title);
Memo1.Lines.Add('主題 ' + Pdf1.Subject);
Memo1.Lines.Add('作者 ' + Pdf1.Author);
Memo1.Lines.Add('關鍵字 ' + Pdf1.Keywords);
Memo1.Lines.Add('生成器 ' + Pdf1.Creator);
Memo1.Lines.Add('創建工具 ' + Pdf1.Producer);
Memo1.Lines.Add('上次修改時間 ' + Pdf1.ModifiedDate);
Memo1.Lines.Add('創建時間 ' + Pdf1.CreationDate);
finally
Pdf1.Active := False;
end;
end;