delphi llPDFLib 文档设置
<h1 id="llpdflib--文档设置">llPDFLib文档设置</h1><h2 id="属性和方法">属性和方法</h2>
<h3 id="tpdfdocumentoutputstream">TPDFDocument.OutputStream</h3>
<pre><code class="language-delphi">property OutputStream: TStream;
</code></pre>
<p>设置了此属性,则生成文档的输出在流中,而不是在文件中。</p>
<h3 id="tpdfdocumentonepass">TPDFDocument.OnePass</h3>
<pre><code class="language-delphi">property OnePass: Boolean;
</code></pre>
<p>直接创建文档。</p>
<blockquote>
<p>创建大型文档时建议使用此属性。当创建下一个页面时,画布的内容将被直接写入输出流。与此相关的是无法更改 <code>CurrentPageIndex</code>。</p>
<p>如果指定了<code>OutputStream</code>,该值将被忽略。</p>
</blockquote>
<h3 id="tpdfdocumentcompression">TPDFDocument.Compression</h3>
<pre><code class="language-delphi">property Compression: TCompressionType;
</code></pre>
<p>指定是否对PDF文档中画布的内容使用压缩。</p>
<h3 id="tpdfdocumentnonembeddedfonts">TPDFDocument.NonEmbeddedFonts</h3>
<pre><code class="language-delphi">property NonEmbeddedFonts: TStringList;
</code></pre>
<p>设置不被嵌入到文档中的TTF字体列表。</p>
<h3 id="tpdfdocumentprinting">TPDFDocument.Printing</h3>
<pre><code class="language-delphi">property Printing: Boolean;
</code></pre>
<p>判断组件是否正在创建新文档。</p>
<h3 id="tpdfdocumentabort">TPDFDocument.Abort</h3>
<pre><code class="language-delphi">procedure Abort;
</code></pre>
<p>停止创建PDF文档。发送到文件的所有数据都将丢失。</p>
<h3 id="tcompressiontype">TCompressionType</h3>
<p>指定页面内容压缩。</p>
<p><strong>unit</strong></p>
<p>llPDFTypes</p>
<pre><code class="language-delphi">TCompressionType = (
ctNone,
ctFlate
);
</code></pre>
<ul>
<li>
<p><em>ctNone</em>不压缩</p>
</li>
<li>
<p><em>ctFlate</em>使用平面压缩进行压缩</p>
</li>
</ul>
<h2 id="例子">例子</h2>
<h3 id="输出到流">输出到流</h3>
<pre><code class="language-delphi">uses llPDFDocument;
procedure TForm1.Button12Click(Sender: TObject);
var
Pdf: TPDFDocument;
Stream: TMemoryStream;
begin
Pdf := TPDFDocument.Create(nil);
Stream := TMemoryStream.Create;
try
//设置文档输出流
Pdf.OutputStream := Stream;
Pdf.BeginDoc;
Pdf.EndDoc;
//将流中的内容输出到文件
Stream.SaveToFile('C:\Users\Administrator\Desktop\ceshi.pdf');
finally
Stream.Free;
Pdf.Free;
end;
end;
</code></pre>
<h3 id="设置不嵌入字体">设置不嵌入字体</h3>
<pre><code class="language-delphi">procedure TForm1.Button13Click(Sender: TObject);
var
Pdf: TPDFDocument;
begin
Pdf := TPDFDocument.Create(nil);
try
//创建PDF文档
Pdf.AutoLaunch := True;
Pdf.FileName := 'C:\Users\Administrator\Desktop\ceshi.pdf';
//设置不嵌入文档的字体(只能设置TTF字体,可以减小文档的大小)
Pdf.NonEmbeddedFonts.Add('Tahoma');
Pdf.NonEmbeddedFonts.Add('Arial');
Pdf.BeginDoc;
with Pdf.Canvas do
begin
Font.Name := 'Tahoma';
Font.Size := 20;
TextOut(100, 100, 'Tahoma');
Font.Name := 'Arial';
Font.Size := 20;
TextOut(100, 150, 'Arial');
end;
Pdf.EndDoc;
finally
Pdf.Free;
end;
end;
</code></pre>
<h3 id="停止创建文档">停止创建文档</h3>
<pre><code class="language-delphi">procedure TForm1.Button14Click(Sender: TObject);
var
Pdf: TPDFDocument;
I: Integer;
begin
Pdf := TPDFDocument.Create(nil);
try
//创建PDF文档
Pdf.AutoLaunch := True;
Pdf.FileName := 'C:\Users\Administrator\Desktop\ceshi.pdf';
Pdf.BeginDoc;
with Pdf.Canvas do
begin
for I := 0 to 50 do
TextOut(100, 50 + I * 20, IntToStr(I));
end;
//停止创建文档
if Pdf.Printing then Pdf.Abort;
finally
Pdf.Free;
end;
end;
</code></pre>
<h3 id="创建大文件">创建大文件</h3>
<pre><code class="language-delphi">uses llPDFDocument, llPDFTypes;
procedure TForm1.Button15Click(Sender: TObject);
var
Pdf: TPDFDocument;
I, J: Integer;
begin
Pdf := TPDFDocument.Create(nil);
try
//创建PDF文档
Pdf.AutoLaunch := True;
Pdf.FileName := 'C:\Users\Administrator\Desktop\ceshi.pdf';
//直接创建文档,创建大型文档时使用(设置OutputStream后不起作用)
Pdf.OnePass := True;
//压缩内容
Pdf.Compression := ctFlate;
Pdf.BeginDoc;
for I := 1 to 1000 do
begin
if I <> 1 then
Pdf.NewPage;
with Pdf.Canvas do
begin
Font.Name := '宋体';
Font.Size := 11;
for J := 1 to 50 do
TextOut(20, J * 20, IntToStr(I) + '页' + IntToStr(J) + '行 *******************');
end;
end;
Pdf.EndDoc;
finally
Pdf.Free;
end;
end;
</code></pre><br><br>
来源:https://www.cnblogs.com/txgh/p/16058579.html
頁:
[1]