筱悠哉 發表於 2022-2-10 12:13:00

delphi llPDFLib 常用功能

<h1 id="llpdflib--常用功能">llPDFLib常用功能</h1>
<h2 id="属性和方法">属性和方法</h2>
<h3 id="tpdfdocumentcreate">TPDFDocument.Create</h3>
<pre><code class="language-delphi">constructor Create(AOwner: TComponent); override;
</code></pre>
<p>创建并初始化 TPDFDocument 的一个实例。</p>
<p><strong>参数</strong></p>
<p><em>AOwner</em> 建立组件与其所有者的关系。</p>
<h3 id="tpdfdocumentbegindoc">TPDFDocument.BeginDoc</h3>
<pre><code class="language-delphi">procedure BeginDoc;
</code></pre>
<p>开始一个新的PDF文档。在创建的文档中添加第一页。</p>
<h3 id="tpdfdocumentenddoc">TPDFDocument.EndDoc</h3>
<pre><code class="language-delphi">procedure EndDoc;
</code></pre>
<p>结束PDF文档的创建工作。将所有未保存的数据重置到输出流。</p>
<h3 id="tpdfdocumentnewpage">TPDFDocument.NewPage</h3>
<pre><code class="language-delphi">procedure NewPage;
</code></pre>
<p>在PDF文档中添加新页面,并将 <code>Canvas</code> 传输到此页面。</p>
<h3 id="tpdfdocumentfilename">TPDFDocument.FileName</h3>
<pre><code class="language-delphi">property FileName: string;
</code></pre>
<p>创建的PDF文档的名称。</p>
<blockquote>
<p>如果指定了<code>OutputStream</code>,该值将被忽略。</p>
</blockquote>
<h3 id="tpdfdocumentautolaunch">TPDFDocument.AutoLaunch</h3>
<pre><code class="language-delphi">property AutoLaunch: Boolean;
</code></pre>
<p>指定在默认PDF查看器中创建后是否打开生成的PDF文件。</p>
<h3 id="tpdfdocumentcanvas">TPDFDocument.Canvas</h3>
<pre><code class="language-delphi">property Canvas: TCanvas;
</code></pre>
<p>标准<code>TCanvas</code>,可以作为标准HDC操作。</p>
<h3 id="tpdfdocumentcurrentpage">TPDFDocument.CurrentPage</h3>
<pre><code class="language-delphi">property CurrentPage: TPDFPage;
</code></pre>
<p>文档中的当前页,可以用绘图操作。</p>
<h3 id="tpdfdocumentdocumentinfo">TPDFDocument.DocumentInfo</h3>
<pre><code class="language-delphi">property DocumentInfo: TPDFDocInfo;
</code></pre>
<p>属性定义有关PDF文档的信息。</p>
<h3 id="tpdfdocinfoauthor">TPDFDocInfo.Author</h3>
<pre><code class="language-delphi">property Author: string;
</code></pre>
<p>指定生成文档中的作者。</p>
<h3 id="tpdfdocinfocreator">TPDFDocInfo.Creator</h3>
<pre><code class="language-delphi">property Creator: string;
</code></pre>
<p>指定生成文档中的生成器。</p>
<h3 id="tpdfdocinfokeywords">TPDFDocInfo.Keywords</h3>
<pre><code class="language-delphi">property Keywords: string;
</code></pre>
<p>指定生成文档中的关键字。</p>
<h3 id="tpdfdocinfosubject">TPDFDocInfo.Subject</h3>
<pre><code class="language-delphi">property Subject: string;
</code></pre>
<p>指定生成文档的主题。</p>
<h3 id="tpdfdocinfotitle">TPDFDocInfo.Title</h3>
<pre><code class="language-delphi">property Title: string;
</code></pre>
<p>指定生成文档的标题。</p>
<h3 id="tpdfpagesize">TPDFPage.Size</h3>
<pre><code class="language-delphi">property Size: TPDFPageSize;
</code></pre>
<p>页面大小。</p>
<h3 id="tpdfcanvasheight">TPDFCanvas.Height</h3>
<pre><code class="language-delphi">property Height: Integer;
</code></pre>
<p><code>Canvas</code> 的高度。</p>
<h3 id="tpdfcanvaswidth">TPDFCanvas.Width</h3>
<pre><code class="language-delphi">property Width: Integer;
</code></pre>
<p><code>Canvas</code> 的宽度。</p>
<h3 id="tpdfpagesize-1">TPDFPageSize</h3>
<p>确定页面的大小。</p>
<p><strong>unit</strong></p>
<p>llPDFTypes</p>
<pre><code class="language-delphi">TPDFPageSize = (
psLetter,
psA4,
psA3,
psLegal,
psB5,
psC5,
ps8x11,
psB4,
psA5,
psFolio,
psExecutive,
psEnvB4,
psEnvB5,
psEnvC6,
psEnvDL,
psEnvMonarch,
psEnv9,
psEnv10,
psEnv11
);
</code></pre>
<ul>
<li><em>psLetter</em>216 x 279 mm/8.5 x 11 英寸</li>
<li><em>psA4</em>210 x 297 mm/8.3 x 11.7 英寸</li>
<li><em>psA3</em>297 x 420 mm/11.7 x 16.5 英寸</li>
<li><em>psLegal</em>216 x 356 mm/8.5 x 14 英寸</li>
<li><em>psB5</em>176 x 250 mm/6.9 x 9.8 英寸</li>
<li><em>psC5</em>162 x 229 mm/6.4 x 9.0 英寸</li>
<li><em>ps8x11</em>8 x 11 英寸</li>
<li><em>psB4</em>250 x 353 mm/9.8 x 13.9 英寸</li>
<li><em>psA5</em>148 x 210 mm/5.8 x 8.3 英寸</li>
<li><em>psFolio</em>210 x 330 mm/8.27 x 13 英寸</li>
<li><em>psExecutive</em>184 x 267 mm/7.25 x 10.5 英寸</li>
<li><em>psEnvB4</em>250 x 353 mm/9.8 x 13.9 英寸</li>
<li><em>psEnvB5</em>176 x 250 mm/6.9 x 9.8 英寸</li>
<li><em>psEnvC6</em>114 x 162 mm/4.5 x 6.4 英寸</li>
<li><em>psEnvDL</em>110 x 220 mm/4.4 x 8.8 英寸</li>
<li><em>psEnvMonarch</em>190.5 x 98.4 mm/7.5 x 3.875 英寸</li>
<li><em>psEnv9</em>225.4 x 98.4 mm/8.875 x 3.875 英寸</li>
<li><em>psEnv10</em>241.3 x 104.8 mm/9.5 x 4.125 英寸</li>
<li><em>psEnv11</em>263.5 x 114.3 mm/10.375 x 4.5 英寸</li>
</ul>
<h2 id="例子">例子</h2>
<h3 id="创建文档">创建文档</h3>
<pre><code class="language-delphi">uses llPDFDocument;

procedure TForm1.Button1Click(Sender: TObject);
var
Pdf: TPDFDocument;
begin
Pdf := TPDFDocument.Create(nil);
try
    //设置生成PDF文件后打开该文件
    Pdf.AutoLaunch := True;
    //设置生成的文件名
    Pdf.FileName := 'C:\Users\Administrator\Desktop\ceshi.pdf';
    //开始创建新PDF文档,并添加第一页
    Pdf.BeginDoc;
    //结束PDF文档的创建
    Pdf.EndDoc;
finally
    Pdf.Free;
end;
end;
</code></pre>
<h3 id="操作canvas">操作Canvas</h3>
<pre><code class="language-delphi">uses llPDFDocument;

procedure TForm1.Button2Click(Sender: TObject);
var
Pdf: TPDFDocument;
begin
Pdf := TPDFDocument.Create(nil);
try
    //创建PDF文档
    Pdf.AutoLaunch := True;
    Pdf.FileName := 'C:\Users\Administrator\Desktop\ceshi.pdf';
    Pdf.BeginDoc;
    //通过Canvas输出内容
    with Pdf.Canvas do
    begin
      Pen.Color := clRed;
      Pen.Width := 2;
      Brush.Color := clInfoBk;
      Rectangle(100, 100, 400, 200);
      Font.Name := '宋体';
      Font.Size := 20;
      TextOut(200, 120, '测试内容');
      Pen.Color := clYellow;
      Pen.Width := 5;
      MoveTo(100, 250);
      LineTo(400, 250);
    end;
    //添加新页面,Canvas指向新增页面
    Pdf.NewPage;
    with Pdf.Canvas do
    begin
      Font.Name := '宋体';
      Font.Size := 20;
      TextOut(200, 120, '新增页面');
    end;
    Pdf.EndDoc;
finally
    Pdf.Free;
end;
end;
</code></pre>
<h3 id="添加页面">添加页面</h3>
<pre><code class="language-delphi">uses llPDFDocument, llPDFTypes;

procedure TForm1.Button3Click(Sender: TObject);
var
Pdf: TPDFDocument;
begin
Pdf := TPDFDocument.Create(nil);
try
    //创建PDF文档
    Pdf.AutoLaunch := True;
    Pdf.FileName := 'C:\Users\Administrator\Desktop\ceshi.pdf';
    //开始创建新PDF文档,添加第一页
    Pdf.BeginDoc;
    //设置页面纸张
    Pdf.CurrentPage.Size := psA4;
    //添加新页面,当前页指向新增页面
    Pdf.NewPage;
    //设置页面自定义纸张
    Pdf.CurrentPage.Width := 300;
    Pdf.CurrentPage.Height := 400;
    //结束PDF文档的创建。
    Pdf.EndDoc;
finally
    Pdf.Free;
end;
end;
</code></pre>
<h3 id="添加文档信息">添加文档信息</h3>
<pre><code class="language-delphi">uses llPDFDocument{$IFNDEF UNICODE}, llPDFMisc{$ENDIF};

procedure TForm1.Button4Click(Sender: TObject);
var
Pdf: TPDFDocument;
begin
Pdf := TPDFDocument.Create(nil);
try
    //创建PDF文档
    Pdf.AutoLaunch := True;
    Pdf.FileName := 'C:\Users\Administrator\Desktop\ceshi.pdf';
    //设置文档的信息
    with Pdf.DocumentInfo do
    begin
      {$IFDEF UNICODE}
      Title := '文档标题';
      Subject := '文档主题';
      Author := '文档作者';
      Creator := '文档生成器';
      Keywords := '文档关键字';
      {$ELSE}
      Title := UnicodeChar('文档标题', GB2312_CHARSET);
      Subject := UnicodeChar('文档主题', GB2312_CHARSET);
      Author := UnicodeChar('文档作者', GB2312_CHARSET);
      Creator := UnicodeChar('文档生成器', GB2312_CHARSET);
      Keywords := UnicodeChar('文档关键字', GB2312_CHARSET);
      {$ENDIF}
    end;
    Pdf.BeginDoc;
    Pdf.EndDoc;
finally
    Pdf.Free;
end;
end;
</code></pre><br><br>
来源:https://www.cnblogs.com/txgh/p/15878537.html
頁: [1]
查看完整版本: delphi llPDFLib 常用功能