武装大熊猫 發表於 2022-2-17 14:46:00

delphi llPDFLib 操作PDF

<h1 id="llpdflib--操作pdf">llPDFLib操作PDF</h1>
<h2 id="属性和方法">属性和方法</h2>
<h3 id="tpdfcanvassetactivefont">TPDFCanvas.SetActiveFont</h3>
<pre><code class="language-delphi">procedure SetActiveFont(FontName: AnsiString; FontStyle: TFontStyles; FontSize: Extended; FontCharset: TFontCharset = ANSI_CHARSET); overload;
</code></pre>
<p>设置文本操作的活动truetype字体。llPDFLib模拟 <em>fsUnderLine</em> 和 <em>fsStrikeOut</em> 样式。 如果字体没有 <em>fsBold</em> 或 <em>fsItalic</em> 样式,llPDFLib也会模拟它。</p>
<p><strong>参数</strong></p>
<p><em>FontName</em>truetype字体的名称。</p>
<p><em>FontStyle</em>字体的样式。</p>
<p><em>FontSize</em>字体大小。</p>
<p><em>FontCharset</em>Charset,用于ansi字符串。 <strong>默认值</strong> <em>ANSI_CHARSET</em>。</p>
<h3 id="tpdfcanvastextout">TPDFCanvas.TextOut</h3>
<pre><code class="language-delphi">procedure TextOut(X: Extended; Y: Extended; Orientation: Extended; TextStr: AnsiString); overload;
</code></pre>
<p>文本字符串输出。</p>
<p><strong>参数</strong></p>
<p><em>X</em>文本输出起始点的X坐标。</p>
<p><em>Y</em>文本输出起始点的Y坐标。</p>
<p><em>Orientation</em>文本方向。</p>
<p><em>TextStr</em>要输出的文本字符串。</p>
<h3 id="tpdfcanvassetcolor">TPDFCanvas.SetColor</h3>
<pre><code class="language-delphi">procedure SetColor(Color: TPDFColor);
</code></pre>
<p>设置闭合区域的填充颜色和线条的颜色。</p>
<p><strong>参数</strong></p>
<p><em>Color</em>填充和线条的颜色。</p>
<h3 id="tpdfcanvassetcolorfill">TPDFCanvas.SetColorFill</h3>
<pre><code class="language-delphi">procedure SetColorFill(Color: TPDFColor);
</code></pre>
<p>设置闭合区域的填充颜色。</p>
<p><strong>参数</strong></p>
<p><em>Color</em>填充的颜色。</p>
<h3 id="tpdfcanvassetlinewidth">TPDFCanvas.SetLineWidth</h3>
<pre><code class="language-delphi">procedure SetLineWidth(lw: Extended);
</code></pre>
<p>将当前线宽设置为以点为单位指定的值。</p>
<p><strong>参数</strong></p>
<p><em>lw</em>新线宽 。</p>
<h3 id="tpdfcanvasrectangle">TPDFCanvas.Rectangle</h3>
<pre><code class="language-delphi">procedure Rectangle(X1: Extended; Y1: Extended; X2: Extended; Y2: Extended);
</code></pre>
<p>绘制一个矩形,其中左上角位于( <em>X1</em> , <em>Y1</em> ),右下角位于( <em>X2</em> , <em>Y2</em> )。</p>
<p><strong>参数</strong></p>
<p><em>X1</em>矩形左上角的X坐标。</p>
<p><em>Y1</em>矩形左上角的Y坐标。</p>
<p><em>X2</em>矩形右下角的X坐标。</p>
<p><em>Y2</em>矩形右下角的Y坐标。</p>
<h3 id="tpdfcanvasstroke">TPDFCanvas.Stroke</h3>
<pre><code class="language-delphi">procedure Stroke;
</code></pre>
<p>通过当画笔颜色和当前线宽描边当前路径。</p>
<h3 id="tpdfcanvasfillandstroke">TPDFCanvas.FillAndStroke</h3>
<pre><code class="language-delphi">procedure FillAndStroke;
</code></pre>
<p>首先使用当前填充颜色填充内部,然后使用当前画笔颜色描边路径。PDF的图形状态为填充和描边操作保留了不同的颜色,因此可以使用这些组合操作符。</p>
<h3 id="tpdfcanvasshowimage">TPDFCanvas.ShowImage</h3>
<pre><code class="language-delphi">procedure ShowImage(ImageIndex: Integer; X: Extended; Y: Extended); overload;
</code></pre>
<p>在画布上显示图像。</p>
<p><strong>参数</strong></p>
<p><em>ImageIndex</em>生成的图像中的图像索引。</p>
<p><em>X</em>矩形左上角的X坐标。</p>
<p><em>Y</em>矩形左上角的Y坐标。</p>
<h3 id="tpdfimagesaddimage">TPDFImages.AddImage</h3>
<pre><code class="language-delphi">function AddImage(FileName: TFileName; Compression: TImageCompressionType): Integer; overload;
function AddImage(Image: TGraphic; Compression: TImageCompressionType): Integer; overload;
</code></pre>
<p>根据压缩类型将文件中的图像或<code>TGraphic</code>中的图像添加到生成的文档中。目前支持bmp(<code>TBitmap</code>)和jpeg(<code>TJPegImage</code>)格式。</p>
<p><strong>参数</strong></p>
<p><em>FileName</em>要插入到文档中的图像的文件名。</p>
<p><em>Image</em>要插入到文档中的图像的对象。</p>
<p><em>Compression</em>压缩类型,将图像保存在文档中。</p>
<p><strong>返回值</strong></p>
<p>返回保存在文档图像中的索引。</p>
<blockquote>
<p>由于图像可能会占用很大的尺寸,因此会立即将其写入生成的输出流或文件。</p>
</blockquote>
<h3 id="llpdfcanvascolortopdfcolor">llPDFCanvas.ColorToPDFColor</h3>
<pre><code class="language-delphi">function ColorToPDFColor(Color: TColor): TPDFColor;
</code></pre>
<p>将TColor转换为PDFColor的函数。</p>
<p><strong>参数</strong></p>
<p><em>Color</em>颜色 。</p>
<h3 id="timagecompressiontype">TImageCompressionType</h3>
<p>指定PDF文档中图像的存储类型</p>
<p><strong>unit</strong></p>
<p>llPDFTypes</p>
<pre><code class="language-delphi">TImageCompressionType = (
itcFlate,
itcJpeg,
itcCCITT3,
itcCCITT32d,
itcCCITT4,
itcJBIG2
);
</code></pre>
<ul>
<li><em>itcFlate</em>Flate 压缩(可用于黑白和彩色图像)</li>
<li><em>itcJpeg</em>Jpeg 压缩(可用于黑白和彩色图像)</li>
<li><em>itcCCITT3</em>CCITT3(仅适用于黑白图像)</li>
<li><em>itcCCITT32d</em>CCITT32d(仅适用于黑白图像)</li>
<li><em>itcCCITT4</em>CCITT4(仅适用于黑白图像)</li>
<li><em>itcJBIG2</em>JBIG2(用于扫描页面的黑白图像)</li>
</ul>
<h3 id="tpdfcolor">TPDFColor</h3>
<p>确定绘制图形基元时使用的色彩空间和颜色。</p>
<p><strong>unit</strong></p>
<p>llPDFTypes</p>
<pre><code class="language-delphi">TPDFColor = record
ColorSpace: TPDFColorSpace;
case TPDFColorSpace of
    csCMYK: (Cyan: Extended;
             Magenta: Extended;
             Yellow: Extended;
             Key: Extended;);
    csGray: (Gray: Extended;);
    csRGB: (Red: Extended;
            Green: Extended;
            Blue: Extended;);
end;
</code></pre>
<h2 id="例子">例子</h2>
<h3 id="输出文字">输出文字</h3>
<pre><code class="language-delphi">uses llPDFDocument, llPDFCanvas;

procedure TForm1.Button5Click(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;
    with Pdf.CurrentPage do
    begin
      //设置字体
      SetActiveFont('宋体', , 20, GB2312_CHARSET);
      //设置字体颜色
      SetColor(ColorToPDFColor(clBlue));
      //输出内容
      TextOut(100, 100, 0, '文本内容');
    end;
    Pdf.EndDoc;
finally
    Pdf.Free;
end;
end;
</code></pre>
<h3 id="输出矩形">输出矩形</h3>
<pre><code class="language-delphi">uses llPDFDocument, llPDFCanvas;

procedure TForm1.Button6Click(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;
    with Pdf.CurrentPage do
    begin
      //设置颜色
      SetColor(ColorToPDFColor(clRed));
      SetColorFill(ColorToPDFColor(clYellow));
      //设置宽度
      SetLineWidth(1);
      //画矩形
      Rectangle(100, 100, 250, 175);
      Stroke;
      //填充矩形
      Rectangle(100, 200, 200, 300);
      FillAndStroke;
    end;
    Pdf.EndDoc;
finally
    Pdf.Free;
end;
end;
</code></pre>
<h3 id="插入图片">插入图片</h3>
<pre><code class="language-delphi">uses llPDFDocument, llPDFTypes;

procedure TForm1.Button8Click(Sender: TObject);
var
Pdf: TPDFDocument;
Bmp1, Bmp2: Integer;
begin
Pdf := TPDFDocument.Create(nil);
try
    //创建PDF文档
    Pdf.AutoLaunch := True;
    Pdf.FileName := 'C:\Users\Administrator\Desktop\ceshi.pdf';
    Pdf.BeginDoc;
    Bmp1 := Pdf.Images.AddImage('C:\Users\Administrator\Desktop\bmp0001.bmp', itcJpeg);
    Bmp2 := Pdf.Images.AddImage('C:\Users\Administrator\Desktop\bmp0002.bmp', itcJpeg);
    with Pdf.CurrentPage do
    begin
      ShowImage(Bmp1, 10, 50);
      ShowImage(Bmp2, 10, 200);
    end;
    Pdf.EndDoc;
finally
    Pdf.Free;
end;
end;
</code></pre><br><br>
来源:https://www.cnblogs.com/txgh/p/15904614.html
頁: [1]
查看完整版本: delphi llPDFLib 操作PDF