Debenu Quick PDF Library(PDF编程开发工具)提供一套全方位的 PDF API 函数,帮助您快速简便地处理 PDF 文件。从文档属性的基本操做到建立您本身的 PDF 查看器和 PDF 编辑器,这款软件知足您的全部需求。Quick PDF Library是一款供 PDF 开发人员使用的 SDK,功能强大、无需版税,其中包括超过500个函数,可用于 Delphi、C、C#、C++、ASP、VB六、VB.NET、VBScript、PHP、PowerBASIC 等,使用 ActiveX、DLL、LIB 或 Delphi 版本的库php
官方帮助文档:https://www.debenu.com/docs/pdf_library_reference/FunctionGroups.phphtml
能够参考(提取文本和图像并插入新PDF):http://quickpdf.org/forum/extract-text-and-images-and-insert-into-new-pdf_topic1308.html算法
安装: 编程
首先到官网下载该库,官网地址为:http://www.debenu.com/。本文所使用的版本为11.11,下载后获得一个exe文件:foxit_quick_pdf_library_en.exe。双击exe文件便可安装控件库,安装过程当中会要求输入安装目录,选择合适的目录完成安装。app
文件GettingStarted.pdf
介绍了在使用该控件库以前须要作的一些准备工做。首先以管理员身份运行命令提示符并切换到安装目录下,而后输入如下命令完成控件的注册。(我这里安装了两个版本因此有1131的版本)编辑器
接着把DebenuPDFLibraryDLL1111.dll、DebenuPDFLibraryDLL1111.pas 添加到Delphi项目中函数
程序记得uses DebenuPDFLibraryDLL1111工具
unit Unit1; interface uses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs, SynPdf, StdCtrls, DebenuPDFLibraryDLL1111; type TForm1 = class(TForm) btn1: TButton; edt1: TEdit; edt2: TEdit; lbl1: TLabel; procedure btn1Click(Sender: TObject); procedure FormCreate(Sender: TObject); private { Private declarations } public { Public declarations } end; var Form1: TForm1; implementation {$R *.dfm} // 读取pdf文本内容以及图片 function ReadPdf(const fileName, saveImagePath: string; var text: string; var imageFiles: string): string; var rPdf: TDebenuPDFLibraryDLL1111; imageCount, i, j, num, keyStatus, FH, PR: Integer; begin Result := ''; num := 0; if Trim(fileName) = '' then begin Result := 'Path cannot be empty'; Exit; end; if (Trim(saveImagePath) <> '') and (not DirectoryExists(saveImagePath)) then begin ForceDirectories(saveImagePath); // 建立目录 end; rPdf := TDebenuPDFLibraryDLL1111.Create('DebenuPDFLibraryDLL1111.dll'); // 库 keyStatus := rPdf.UnlockKey('**********'); // 密钥 秘钥能够购买或者找我要 if keyStatus <> 1 then begin Result := 'The library cannot be loaded or unlocked fails'; Exit; end; try rPdf.LoadFromFile(Trim(fileName), ''); // 以直接访问模式打开文件并存储文件句柄 FH := rPdf.DAOpenFile(fileName, ''); for i := 1 to rPdf.DAGetPageCount(FH) do begin rPdf.SelectPage(i); // 选区页 text := text + rPdf.GetPageText(8); // 获取文本 8:更准确的文本提取算法 if Trim(saveImagePath) <> '' then begin imageCount := rPdf.GetPageImageList(0); // 获取图片 for j := 1 to rPdf.GetImageListCount(imageCount) do // 遍历当前页中的全部图片 begin rPdf.SaveImageListItemDataToFile(imageCount, j, 0, saveImagePath + '\' + IntToStr(num) + '.png'); imageFiles := imageFiles + saveImagePath + '\' + IntToStr(num) + '.png ; '; inc(num); end; end; end; finally rPdf.Free; end; end; // 写pdf function WritePdf(const fileName, text: string): string; var wPdf: TDebenuPDFLibraryDLL1111; num, wStatus: Integer; begin Result := ''; if Trim(fileName) = '' then begin Result := 'Path cannot be empty'; Exit; end; try wPdf := TDebenuPDFLibraryDLL1111.Create('DebenuPDFLibraryDLL1111.dll'); // 库 try wStatus := wPdf.UnlockKey('*************'); // 密钥 if wStatus = 1 then begin num := wPdf.AddTrueTypeSubsettedFont('FangSong', text, 0); wPdf.SelectFont(num); wPdf.DrawWrappedText(50, 750, 500, text); wPdf.SaveToFile(fileName); end else begin Result := 'The library cannot be loaded or unlocked fails'; end; finally wPdf.Free; end; except on e: Exception do Result := e.Message; end; end; procedure TForm1.btn1Click(Sender: TObject); var text, imageFiles: string; begin text := ''; imageFiles := ''; // showmessage(WritePdf(edt1.Text,edt2.Text)); ShowMessage(ReadPdf(edt1.text, edt2.text, text, imageFiles)); lbl1.Caption := text; ShowMessage(text); ShowMessage(imageFiles); end; procedure TForm1.FormCreate(Sender: TObject); begin //readAndWritePDf(); end; end.
运行:开发工具
提取的:ui
本来pdf: