zoukankan      html  css  js  c++  java
  • delphi PDFium 提取文档内容

    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 提取数量。

    返回值

    提取的字符串

    StartIndexCount 参数确定要提取的字符。

    例子

    提取文本

    在窗体上放置TPdf组件Pdf1TMemo组件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组件Pdf1TMemo组件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;
    
  • 相关阅读:
    CCPC 2020 长春站 部分简略题解
    atcoder arc106 D Powers
    循环节与拓展欧拉定理(广义欧拉降幂)
    最长公共上升子序列 题解
    namomo fish round1 A~C题解
    Codeforces Round #666 (Div. 2) A~E题解
    Educational Codeforces Round 93 Div2 A~E题解
    Codeforces Round #578 Div2 1200 A~E题解
    UVA11997 K Smallest Sums 题解
    LCA模板
  • 原文地址:https://www.cnblogs.com/txgh/p/15778548.html
Copyright © 2011-2022 走看看