How can draw dotted line in pdf using php and TCPDF?

Viewed 1929

I need to draw a horizontal dotted line in pdf using TCPDF. I tried:

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

I used the dash parameter. When I set it to 1 it draws short dashes, but I need dots. I did not find an explanation of the style parameters or any manual on the internet.

2 Answers

Please use the below code for the draw horizontal dotted line in pdf using TCPDF and apply a style to it.

enter image description here

<?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');

I hope this helps!

You can have dots, if you want to.

Just set the cap to round in the style properties:

$style = array('width' => 0.5, 'cap => 'round', 'dash' => '2,2,2,2', 'phase' => 0, 'color' => array(255, 0, 0));
Related