$style = array('width' => 0.5, 'cap' => 'butt', 'join' => 'miter', 'dash' => 0, 'color' => array(255, 0, 0));
$pdf->Line(5, 10, 80, 30, $style);
I uses the above statements to draw a line.
Result view in screen has this line drawn.
However It's not printed on paper.
Any help would be highly appreciated.
I'm sorry folks, it's not TCPDF problem.
I was using Google to print out the PDF generated and having this problem.
If I try Internet Explorer there is no problem.
Related
I'm struggling with some additional margins
$pageLayout = [
$width,
$height,
];
$pdf = new TCPDF('L, 'mm', $pageLayout, TRUE, 'UTF-8', FALSE);
$pdf->setCellPaddings(0,0,0,0);
$textBorder = array('LTRB' => array('width' => 0.001, 'cap' => 'butt', 'join' => 'miter', 'dash' => 0, 'color' => array(0, 0, 0)));
$pdf->Text($paddingLR, $paddingTB,$myText,0,false,true,$textBorder,0,'L',false,'',0,false,'A','C',true);
The border is only for visualisation.
Preview of rendered Text
now i'm surprised about the margins around the text. I'd expect, that the Text starts within the border line. The same for the space above the letters.
Does anyone have a suggestion how to make this work?
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.
Please use the below code for the draw horizontal dotted line in pdf using TCPDF and apply a style to it.
<?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));
I've a PhpSpreadsheet process to export data to XLSX and PDF. I'm using TcPDF as PDF writer. But TcPDF has a problem to convert/translate border style.
Xlsx export
TcPDF export
Any idea to fix this?
I guess you have to use TcPDF's SetLineStyle() (see example 35):
$pdf->SetLineStyle(array('width' => 0.5, 'cap' => 'butt', 'join' => 'miter', 'dash' => 4, 'color' => array(255, 0, 0)));
$text="DUMMY";
$pdf->Cell(0, 0, $text, 1, 1, 'L', 1, 0);
if you want to create complex border styles for individual cells check this
or see example 48 if you use HTML tables.
Alternatively, try SetLineWidth(1.0).
I'm using TCPDF in my php application, but I'm not finding a way to draw a circle with black border and filled with another color;
here my code:
$style_bollino = array('width' => 0.25, 'dash' => 0, 'color' => array(0, 0, 0));
$this->SetAlpha(1);
$this->Circle(35, 100, 4, 0, 360, 'C', $style_bollino, array(210, 0, 0));
I tried also to change 'C' parameter to 'F' or null but I didn't get the result.
I'm not able to figure out what I'm missing
kind regards,
Matt
According to one of their examples, there's a one-liner way to do it, just pass 'DF' to $style parameter:
$this->Circle(35, 100, 4, 0, 360, 'DF', $style_bollino, array(210, 0, 0));
For a list of options for this parameter, check the PHPDoc in TCPDF_STATIC::getPathPaintOperator() function.
This seems like a fairly straightforward requirement but I can't work out how to do it in one line either.
However, it's pretty simple to fill the circle and then draw another stroked circle on top of it.
foreach (array("F", "S") as $fill_style) {
$this->Circle(35, 100, 4, 0, 360, $fill_style, $style_bollino, array(210, 0, 0));
}
I have created a custom header for my PDF created with TCPDF. Now I would like to add a blue line (about 2px width) that goes across the page at the bottom of the header but can't figure out how?
I believe you do it like this:
$style = array('width' => 0.5, 'cap' => 'butt', 'join' => 'miter', 'dash' => 0, 'color' => array(255, 0, 0));
$pdf->Line(5, 10, 80, 30, $style);
Here is the full example
http://www.tcpdf.org/examples/example_012.phps
I found the easiest way to put line
$pdf->writeHTML("<hr>", true, false, false, false, '');
You can also use the page axis:
$pdf->Line(5, $pdf->y, $pdf->w - 5, $pdf->y);
However if you are trying to render a colored <hr> html tag you will need to adjust the TCPDF::DrawColor (this excerpt is from code that adds a graph bar to each row of a data report as per $twidth and $lengthmm):
$htmlbar = '<hr style="width:' . $lengthmm . 'mm;">';
$oldDrawColor = $pdf->DrawColor;
$pdf->setDrawColor(121, 161, 46);
$pdf->MultiCell($twidth,'2',$htmlbar,0,'L',$fill,1,'','',true,0,true,false,4,'T',false);
$pdf->DrawColor = $oldDrawColor;
Drawing a horizontal black line at the current position:
$style = ['width' => 0.2, 'cap' => 'butt', 'join' => 'miter', 'dash' => 0, 'color' => [0, 0, 0]];
$this->pdf->SetLineStyle($style);
$this->pdf->Line(PDF_MARGIN_LEFT, $this->pdf->getY(), $this->pdf->getPageWidth()-PDF_MARGIN_LEFT, $this->pdf->getY());
$this->pdf->Ln();
The point is to get the x value for the second point.
This is how I do it:
$pageWidth = $pdf->getPageWidth(); // Get total page width, without margins
$pageMargins = $pdf->getMargins(); // Get all margins as array
$headerMargin = $pageMargins['header']; // Get the header margin
$px2 = $pageWidth - $headerMargin; // Compute x value for second point of line
$p1x = $this->getX();
$p1y = $this->getY();
$p2x = $px2;
$p2y = $p1y; // Use same y for a straight line
$style = array();
$this->Line($p1x, $p1y, $p2x, $p2y, $style);
Links
TCPDF::getMargins()
http://www.tcpdf.org/doc/code/classTCPDF.html#ae9bd660bf5b5e00eea82f1168cc67b5b
TCPDF::getPageWidth()
http://www.tcpdf.org/doc/code/classTCPDF.html#a510ab21d6a373934bcd3bd4683704b7e
Have fun!
Just add some HTML : )
$html ='<hr>';
$pdf->writeHTML($html, true, false, true, false, '');