Related
I wanted to show data with custom position. the currency is align left and the number align right.
So i'm trying to make a cell that looks like 1 cell but it's made of 2 cell .
Here is part of my code
$pdf->Cell(5, 10, ' $ ', 'L', 0, 'L');
$pdf->Cell(45, 10, $r_purchases_t['purchase_total'], 'R', 0, 'R');
It's result is this :
|$ 10,000.00|
Problem : It has no bottom border,how can i make custom cell border just left and bottom side ?
If possible, i want some code like $pdf->Cell(5, 10, ' $ ', 'L'||'B', 0, 'L');
SOLVED,
Apparently you can just combine border using , in border parameter.
So to add left and bottom border of the cell just using this code
$pdf->Cell(5, 10, ' $ ', 'L,B', 0, 'L');
$pdf->Cell(45, 10, ' $ '. $r_purchases_t['purchase_total'], 'L', 0, 'L');
Try This and adjust width of cell accordin to need.
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've have three cells and i'am trying to align the text to Left, Center and Right.
function Footer()
{
$this->SetY( -15 );
$this->SetFont( 'Arial', '', 10 );
$this->Cell(0,10,'Left text',0,0,'L');
$this->Cell(0,10,'Center text:',0,0,'C');
$this->Cell( 0, 10, 'Right text', 0, 0, 'R' );
}
When I ouput my PDF file, center text get automatically aligned right.
This is how it looks:
Can somebody tell me what I'm doing wrong here and how I can fix this issue?
The new position after a Cell call will be set to the right of each cell if you set the ln-parameter of the Cell method to 0. You have to reset the x-coordinate before the last 2 Cell calls:
class Pdf extends FPDF {
...
function Footer()
{
$this->SetY( -15 );
$this->SetFont( 'Arial', '', 10 );
$this->Cell(0,10,'Left text',0,0,'L');
$this->SetX($this->lMargin);
$this->Cell(0,10,'Center text:',0,0,'C');
$this->SetX($this->lMargin);
$this->Cell( 0, 10, 'Right text', 0, 0, 'R' );
}
}
Though Jan Slabon's answer was really good I still had issues with the center not being exactly centered on my page, maybe we have different versions of the library and that's what accounts for the slight differences, for instance he uses lMargin and on some versions that's not available. Anyway, the way it worked for me is this:
$pdf = new tFPDF\PDF();
//it helps out to add margin to the document first
$pdf->setMargins(23, 44, 11.7);
$pdf->AddPage();
//this was a special font I used
$pdf->AddFont('FuturaMed','','AIGFutura-Medium.ttf',true);
$pdf->SetFont('FuturaMed','',16);
$nombre = "NAME OF PERSON";
$apellido = "LASTNAME OF PERSON";
$pos = 10;
//adding XY as well helped me, for some reaons without it again it wasn't entirely centered
$pdf->SetXY(0, 10);
//with SetX I use numbers instead of lMargin, and I also use half of the size I added as margin for the page when I did SetMargins
$pdf->SetX(11.5);
$pdf->Cell(0,$pos,$nombre,0,0,'C');
$pdf->SetX(11.5);
//$pdf->SetFont('FuturaMed','',12);
$pos = $pos + 10;
$pdf->Cell(0,$pos,$apellido,0,0,'C');
$pdf->Output('example.pdf', 'F');
Seems that there is a parameter for this, so ('R' for right-aligning, 'C' for centering):
$pdf->Cell(0, 10, "Some text", 0, true, 'R');
will right align text.
Also, notice that the first parameter ('width') is zero, so cell has 100% width.
I'm using TCPDF to create barcode labels. The code works great until I tried to scale the price text to make it taller (more visible). Now the bottom row of labels are spilling components onto later pages, including components that are not scaled. It appears the ordinate value of the text along the bottom row of labels is off the bottom of the page and that is causing the problem, but I thought that setting the (x,y) value when calling procedures like MultiCell absolutely set the (x,y) value?. Does anyone know how to fix this? Can I force a large art board? Can I move the object after it has been scaled? Can I somehow recover from the off-page ordinate calculation?
The issue is in the create_label function, below. The second MultiCell line is the scaled entry. The specific effect on the bottom row of labels is that the description and price are correctly on the first label, but the barcode is forced to a second page. The description and price of the second label are on the second page, but the barcode is forced to a third. Etc.
function create_label($posx, $posy, $upc, $price, $desc){
global $START_X, $START_Y, $INC_X, $INC_Y, $style, $pdf;
$pdf->SetFont('helvetica', '', 15);
$pdf->MultiCell(1.00, 0.575, $desc, 0, 'L', false, 1, $START_X+($posx*$INC_X), $START_Y+($posy*$INC_Y), true, 1, false, true, 0.575, 'M', true);
$pdf->SetFont('', 'B', '24');
$pdf->StartTransform();
$pdf->ScaleY('200',1.00,0.7+($posy*$INC_Y)); break;
$pdf->MultiCell(1.00, 0.575, $price, 0, 'R', false, 1, $START_X+($posx*$INC_X)+1.00, $START_Y+($posy*$INC_Y), true, 1, false, true, 0.575, 'M', true);
$pdf->StopTransform();
$pdf->write1DBarcode($upc, 'UPCA', $START_X+($posx*$INC_X), $START_Y+($posy*$INC_Y)+0.3125+0.2625, 2.0, .3, '', $style, 'N');
}
$pdf = new TCPDF('P', 'in', 'LETTER', true, 'UTF-8', false);
$pdf->SetMargins(0.1875, 0.5, 0.1875);
$pdf->SetHeaderMargin(0);
$pdf->SetFooterMargin(0);
$pdf->SetAutoPageBreak(TRUE, 0.5);
$pdf->setImageScale(PDF_IMAGE_SCALE_RATIO);
if (#file_exists(dirname(__FILE__).'/lang/eng.php')) {
require_once(dirname(__FILE__).'/lang/eng.php');
$pdf->setLanguageArray($l);
}
$pdf->AddPage();
$START_X = 0.85;
$START_Y = 0.38;
$INC_X = 2.375;
$INC_Y = 0.9375;
// label width = 2.25
// label height = 0.875
// Label gutter = 1/8 x 1/16
$upc_list = array( /*Array of UPC numbers*/ );
for($row = 0; $row <= 10; $row++){
for ($col = 0; $col <= 2; $col++){
unset($upc);
if(strlen($upc) > 0 && strlen($upc) < 13 && is_numeric($upc)) {
unset($item);
$item = get_item_from_database($upc); // Creates data array
create_label($col, $row, $upc, $item['price'], trim($item['description']));
}
}
}
$pdf->Output('test_pdf.pdf', 'I');
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');