I am trying to create a header in TCPDF, however it always have a border underneath of it. Is there a way I can remove the bottom border?
This works for some versions:
// Call before the addPage() method
$pdf->SetPrintHeader(false);
$pdf->SetPrintFooter(false);
If you don't want to subclass or change the tcpdf source just call the setHeaderData method and specify white line color.
$pdf->setHeaderData('',0,'','',array(0,0,0), array(255,255,255) );
Problem solved by extends the TCPDF class and modify the header and footer.
class MYPDF extends TCPDF {
public function Header()
{
$image_file = K_PATH_IMAGES.'pdf-header.jpg';
$this->Image($image_file, 160, 10, 40, '', 'JPG', '', 'T', false, 20, '', false, false, 0, false, false, false);
$this->SetFont('helvetica', 'B', 10);
}
public function Footer()
{
$this->SetY(-15);
$this->SetFont('helvetica', 'I', 8);
}
}
tcpdf.php:
// print an ending header line
$this->SetLineStyle(array('width' => 0.25 / $this->k, 'cap' => 'butt', 'join' => 'miter', 'dash' => 0, 'color' => array(255, 255, 255)));
If the other solutions posted in this thread does not work, I solved in this way:
TL;DR
In Footer() function in Tcpdf class (tcpdf.php):
Replace this lines:
$this->Cell(0, 0, $pagenumtxt, 'T', 0, 'L'); // line 3527 in version 6.3.1
$this->Cell(0, 0, $this->getAliasRightShift().$pagenumtxt, 'T', 0, 'R'); // line 3530 in version 6.3.1
With this lines
$this->Cell(0, 0, $pagenumtxt, 0, 0, 'L');
$this->Cell(0, 0, $this->getAliasRightShift().$pagenumtxt, 0, 0, 'R');
Alternative way 1
Comment this lines in Footer() function in Tcpdf class (tcpdf.php):
In my file (version 6.3.1) they were placed at line 3524
//Print page number
if ($this->getRTL()) {
$this->SetX($this->original_rMargin);
$this->Cell(0, 0, $pagenumtxt, 'T', 0, 'L');
} else {
$this->SetX($this->original_lMargin);
$this->Cell(0, 0, $this->getAliasRightShift().$pagenumtxt, 'T', 0, 'R');
}
This will disable the render of the page number in the footer but at least it removes the unwanted line.
Alternative way 2
If these methods does not work, search in the tcpdf.php file for this string:
$this->SetLineStyle(array
You should find 3 occurrences, replace the 'color' property of the array with the value [0,0,0] (or the rgb color of your background), this should cause the line to turn white (or the color you set).
I used this method to troubleshoot where the problem was by putting custom weird color and seeing which one was being rendered.
Explanation
The line is rendered because in the lines
$this->Cell(0, 0, $pagenumtxt, 'T', 0, 'L');
$this->Cell(0, 0, $this->getAliasRightShift().$pagenumtxt, 'T', 0, 'R');
The border property is set to 'T' (top border). You can disable the border by set the border property to 0 (see docs here, $border param).
If that doesn't work you can entirely disable the render of the page number (and thus the border), or you can set the border to a custom color that matches you actual background.
Comment this line in Header() function of tcpdf Class :
$this->Cell(($this->w - $this->original_lMargin - $this->original_rMargin), 0, '', 'T', 0, 'C');
Related
I am using TCPDF , I am trying to add custom footer with different styles like right side Customer Name: color should be blue and left side Approved By: color should be green, and bottom of the page displaying page numbers.
I have tried this in pdf page
$html_content = "<table><tr><td>Customer Name:</td><td style='color:blue;'>Suneel</td><td>Approved By:</td><td style='color:green;'>Srinu</td></tr></table></hr>"
$tcpdf->xfootertext($html_content);
It's Working, but it's not accept the styles
In TCPDF class
function Footer()
{
$year = date('Y');
$footertext = sprintf($this->xfootertext, $year);
$this->writeHTMLCell(0, 0, '', '', $footertext, 0, 0, false,true, "L", true);
$this->SetY(8);
// Set font
$this->SetFont('helvetica', 'I', 8);
// Page number
$this->Cell(0, 27, 'Page '.$this->getAliasNumPage().'/'.$this->getAliasNbPages(), 0, false, 'C', 0, '', 0, false, 'T', 'M');
}
Finally I found answer, Footer has accepted the all styles which we will parse the dynamic content with different colors.
Here is the solutions
$this->writeHTML($footertext, false, true, false, true);
Instead of
$this->writeHTMLCell(0, 0, '', '', $footertext, 0, 0, false,true, "L", true);
I have changed writeHTML instead of writeHTMLCell it accept the footer colors as well.
I am working on generating content for an invoice but i need to have all my 'divs' in alignment - header, body, and footer. Currently i have the header and body in alignment but the footer's margins dont seem to align plus i have two cells - one left aligned and the other right aligned. However they don't align plus their margins are off.
public function Footer()
{
$this->SetY(-15);
$this->SetFont(PDF_FONT_NAME_MAIN, ' ', 8);
$this->SetFooterMargin(15);
//Get time
$date = date('m/d/Y');
$time = date('H:i:s A');
$this->Cell(0, 0, 'Date: '.date("Y-m-d")." - Time: ".$time , 0, false, 'L');
// Page number
$this->Cell(0, 0, 'Page '.$this->getAliasNumPage().'/'.$this->getAliasNbPages(), 0, false, 'R', 0, '', 0, true, 'T', 'M');
}
Any suggestions?
Within the footer function, call this
$this->SetRightMargin(N); // Where N is the value of the margin spacing you like to achieve
Hope this helps
How to send cell() to the back because it currently show to pdf based on order in the code. This is the example.
$pdf->SetXY(10, 20);
$pdf->SetFillColor(240);
$pdf->Cell(10, 10, '', 0, 1, 'L', true); // Show up 1st: Cell 1
$pdf->SetXY(10, 20);
$pdf-> SetFillColor(100);
$pdf->Cell(10, 10, '', 0, 1, 'L', true); // Show up 2nd: Cell 2
So, how can I set which Cell will come first/send to the back without follow the order?
I have to make invoices with TCPDF. I have a logo on top of the pdf and the title of the company has to come right next to it.
Now i'm doing this:
$pdf->Image(__DIR__.'/../../../assets/img/logo.png', 15, 10, 10, 0);
$pdf->Cell(110, 0, 'Company', 0, 0, 'L', 0, '', 3);
But "Company" is on top of the logo now. Is there a way to add padding left on that cell?
Try using:
$pdf->Image(__DIR__.'/../../../assets/img/logo.png', 15, 10, 10, 0, null, null,'T');
documentation
Hy
I'm trying to convert an image (both png or jpeg) to pdf and then adding crop marks using tcpdf (no limitation on the library, it just seemed the best to me, no problems in changing if would solve the problem).
the best case for me is: I have an input image, I give it to some function of tcpdf, that converts it into a pdf, add the bookmarks in the angles (top-left, top-right, bottom-left, bottom-right) and save the pdf without nowing anything about the sizes of the image...
I tried looking around but coudn't find anything without passing the size of the images to tcpdf, this is what I came up with:
$pagelayout = array('706', '606'); // or array($height, $width)
$pdf = new TCPDF('', 'pt', $pagelayout, true, 'UTF-8', false);
// set document information
$pdf->SetAuthor('JOIN SRL');
// add a page
$pdf->AddPage();
$pdf->Image($input, 0, 0, '', '', 'JPG', 'http://www.tcpdf.org', '', true, 300, '', false, false, 1, false, false, false);
$pdf->Image($input);
$pdf->cropMark('', '', 10, 10, 'TL');
$pdf->cropMark('', '', 10, 10, 'TR');
$pdf->cropMark('', '', 10, 10, 'BL');
$pdf->cropMark('', '', 10, 10, 'BR');
$pdf->Output($output, 'F');
as you can see I had to pass the image size to tcpdf, but this is just a test, I would like to get rid of this informations in this peace of code...
And this dosn't work either because the pdf page comes otu bigger than the image, and hte crop marks don't get show( I think this is quite obvious, I tried not giving coordinates hoping that they would automatically set in the angles of the page, but no luck) .
Does someone have any ideas?
thank's
EDIT
I managed to solve nearly everything. could be fine like this( the code follows) but I wanted to know if there is a way to do the same thing without knowing the image size.
$pdf->setMargins(0, 0, 0);
$pdf->SetAutoPageBreak(false, 0);
$pdf->AddPage();
$pdf->Image($input);
$width = $pdf->getPageWidth();
$height = $pdf->getPageHeight();
$pdf->cropMark(5, 5, 5, 5, 'TL', array(255, 0, 0));
$pdf->cropMark($width - 5, 5, 5, 5, 'TR', array(255, 0, 0));
$pdf->cropMark(5, $height - 5, 5, 5, 'BL', array(255, 0, 0));
$pdf->cropMark($width - 5, $height - 5, 5, 5, 'BR', array(255, 0, 0));
$pdf->Output($output, 'F');
thank's