在Delphi中使用Quick PDF Library Lite

简介

Debenu Quick PDF Library 是一个功能强大的PDF操作库,可以中添加处理PDF文件的功能,如创建,渲染,打印,密码安全,合并,分割和操作PDF文件。它包含超过900个函数,支持C,C++,C#,Delphi,Objective-C,Python,PHP,Visual Basic,VB.NET,ASP,PowerBASIC,Pascal和其它语言,包括了ActiveX,DLL,LIB,Delphi和Dylib等版本。 Debenu Quick PDF Library Lite 是其免费精简版,可在应用程序中免费使用和发布,限制如下。

License definition

The full end user license agreement for Debenu Quick PDF Library Lite can be read [online here]>>( http://www.quickpdflibrary.com/products/quickpdf/license.php ), but to give you a rough idea of how you can and can't use Debenu Quick PDF Library Lite, here's a few key points:

Free. You can use Debenu Quick PDF Library Lite in your applications without needing to pay a licensing fee or any royalty fees for distribution. No reselling. You are not allowed to resell Debenu Quick PDF Library or your license key, but you can embed the software in your application, or distribute it with your system. Compiled applications only. You are not permitted to create your own PDF software libraries using Debenu Quick PDF Library.
精简版可使用的函数可以参考安装目录中的 Debenu Quick PDF Library 11.14 Reference Guide.pdf 中Lite Edition Functions列表

下载和安装

首先到官网下载该库,官网地址为: https://www.debenu.com/blog/category/quick-pdf-library-lite 。找不到可以从下面这个地址下 http://www.quickpdflibrary.com/free/lite.php
下载所需版本的安装文件 http://www.debenu.com/downloads/installers/debenu_quick_pdf_library_lite_en.exe?_ga=2.99056022.909023250.1680680730-1863846514.1680680730
下载后得到一个exe文件:debenu_quick_pdf_library_lite_en.exe。双击exe文件即可安装控件库,安装完成后打开刚才所选择的目录,可以看到以下目录与文件(跟下载的版本有关系)。

[Import]
[Samples]
Debenu Quick PDF Library 11.14 Reference Guide.pdf
DebenuPDFLibrary64Lite1114.dll
DebenuPDFLibrary64Lite1114.tlb
DebenuPDFLibraryLite1114.dll
DebenuPDFLibraryLite1114.tlb
GettingStarted.pdf
license.pdf
readme.txt
reasons_to_upgrade.pdf
uninstall.exe

包含32位和64位两个DLL。
使用前先注册需要使用的DLL:
已以管理员身份运行CMD,输入regsvr32 DebenuPDFLibraryLite1114.dll(使用实际下载和使用的DLL名称)注册。
运行Delphi,Component → Import Componet → Import a Type Library → next → 选择 Debenu Quick PDF Library → next → 填写所需信息(默认值不改也可以) → Create unit即可 ,生成名称形如:ebenuPDFLibraryLite1114_TLB.pas
新建项目,在project点右键 → Add 添加刚生成的单元。

Hello world

unit Unit1;
interface
  Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics,
  Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Vcl.StdCtrls,System.Win.ComObj,
  DebenuPDFLibraryLite1114_TLB;
  TForm1 = class(TForm)
    btn1: TButton;
    btn2: TButton;
    procedure btn1Click(Sender: TObject);
    procedure btn2Click(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  Form1: TForm1;
implementation
{$R *.dfm}
procedure TForm1.btn1Click(Sender: TObject);
  pdf: PDFLibrary;
  pid: Integer;
  mm: Double;
begin
 // 创建mm单位,72dot/inch
  mm:= 72/25.4;
  pdf:= CoPDFLibrary.Create as PDFLibrary;
  pid:= pdf.NewDocument;
  pdf.DrawText(10*mm,10*mm,'test');
  pdf.DrawQRCode(20*mm,50*mm,30*mm,'qrcode sample测试',0,0);
  pdf.SaveToFile('d:\1.pdf');
  pdf:= nil;
procedure TForm1.btn2Click(Sender: TObject);
  pdf: PDFLibrary;
  pid: Integer;
  mm: Double;
  path: string;
  picname:string;
begin
  path:= ExtractFilePath(Application.ExeName);
  mm:= 72/25.4;
  pdf:= CoPDFLibrary.Create as PDFLibrary;
  pdf.LoadFromFile('d:\1.pdf','');
  pdf.DrawText(50*mm,100*mm,'read and write pdf');
  picname:= path+'1.bmp';
  ShowMessage(picname);
// 正常模式载入图片
  pid:= pdf.AddImageFromFile(path+'1.bmp',0);
  pdf.DrawImage(20*mm,50*mm,30*mm,10*mm);
// 载入图片包含Alpha通道,可包含透明度,透明背景
  pid:= pdf.AddImageFromFile(path+'2.png',2);
  pdf.DrawImage(40*mm,30*mm,30*mm,10*mm);
  pdf.SaveToFile('d:\1.pdf');
  pdf:=nil;
// 下面这个是在网上找到的方法
// https://www.thoughtco.com/delphi-developers-quick-pdf-library-lite-3972284
// 这个不需要Delphi Import Component,导入tlb库,只需要Regsvr32注册DLL,可以直接用,不过没有动态提示,不如上面方法使用方便
// 需Use ComObj
procedure TForm1.btn3Click(Sender: TObject);
  QP: Variant;
begin
  QP:= CreateOleObject('DebenuPDFLibraryLite1114.PDFLibrary');
  QP.DrawText(100,100,'hello world!');
  QP.SaveToFile('d:\2.pdf') ;
  QP:= Unassigned;