首页 > 解决方案 > 如何使用 php 和 TCPDF 在 pdf 中绘制虚线?

问题描述

我需要使用 TCPDF 在 pdf 中绘制水平虚线。我试过了:

$style = array('width' => 0.1, 'cap' => 'butt', 'join' => 'miter', 'dash' => 1, 'color' => array(0, 0, 0));
$pdf->Line(5, 50, 100, 50, $style);

我使用了破折号参数。当我将它设置为 1 时,它会绘制短划线,但我需要点。我没有在互联网上找到关于样式参数的解释或任何手册。

标签: phptcpdf

解决方案


请使用以下代码在 pdf 中绘制水平虚线TCPDF并对其应用样式。

在此处输入图像描述

<?php

require_once('tcpdf.php');

// create new PDF document
$pdf = new TCPDF(PDF_PAGE_ORIENTATION, PDF_UNIT, PDF_PAGE_FORMAT, true, 'UTF-8', false);

// disable header and footer
$pdf->setPrintHeader(false);
$pdf->setPrintFooter(false);

// set font
$pdf->SetFont('helvetica', '', 10);

// add a page
$pdf->AddPage();

//set 'width' => 0.1, 'dash' => '1,1,1,1' as per your requirement
$style = array('width' => 0.5, 'dash' => '2,2,2,2', 'phase' => 0, 'color' => array(255, 0, 0));

// Line
$pdf->Text(5, 4, 'Line examples');
$pdf->Line(5, 20, 200, 20, $style);

//Close and output PDF document
$pdf->Output('line_example.pdf', 'I');

我希望这有帮助!


推荐阅读