Menu

Background color

Help
Jordy
2012-03-12
2019-06-15
  • Jordy

    Jordy - 2012-03-12

    Instead of a white page/background I need a green page/background.
    How to set a full page background color?
    Thanks!

     
  • Nicola Asuni

    Nicola Asuni - 2012-03-12

    Check the example n. 51 and use a rect() function instead of image.

     
  • Jordy

    Jordy - 2012-03-13

    Thanks for the quick and perfect response!

    Here is my working code which can be used for people with the same request.

    // Extra header voor background color
    class MYPDF extends TCPDF {
        //Page header
        public function Header() {
            // Background color      
            $this->Rect(0,0,210,297,'F','',$fill_color = array(255, 170, 96));
        }
    }
    
    // create new PDF document
    $pdf = new MYPDF(PDF_PAGE_ORIENTATION, PDF_UNIT, PDF_PAGE_FORMAT, true, 'UTF-8', false);
    
     
  • Jordy

    Jordy - 2012-03-13

    nicolaasuni, After printing example n. 51 there is still a white margin
    visible around the background image. Do you know how to remove does margins?

     
  • Nicola Asuni

    Nicola Asuni - 2012-03-13

    The white margings are probably imposed by your printer.
    Check also if you are scaling the PDF on the printer dialog.

     
  • sognox

    sognox - 2013-07-25

    but... header disappear

    I would like a pdf with a background color, a header and a footer ... possible?

     

    Last edit: sognox 2013-07-25
  • md. noman

    md. noman - 2019-06-15

    Why can't I set heading background color & set text wrapping? Please help me. This is my code below:

    setPrintHeader(false); $pdf->setPrintFooter(false); $pdf->SetAutoPageBreak(false); $conn = mysqli_connect('localhost','root','',''); // if (!$conn) // { // die('Could not connect: ' . mysqli_error()); // } //mysqli_select_db('nrb_database', $conn); // mysqli_query("SET NAMES utf8"); $query= mysqli_query($conn, "SELECT * FROM "); $pdf->SetMargins(10, 20, 15); $pdf->AddPage(); $pdf->setImageScale(1.53); $pdf->Image('img/agrani_bank.gif',60,0); $pdf->SetFont('FreeSerif', 'B', 10); $pdf->SetFillColor(136, 136, 136); $pdf->Cell(193,8,"Remittance Receiver`s Information",1,1,'C'); $pdf->Ln(); $pdf->SetFont('FreeSerif', 'B', 6); $pdf->SetFillColor(255, 255, 255); $pdf->Cell(8, $row_height, 'Sl N0', 1, 0, 'C', 1); $pdf->Cell(15, $row_height, 'Mobile', 1, 0, 'C', 1); $pdf->Cell(20, $row_height, 'Receiver Name', 1, 0, 'C', 1); $pdf->Cell(20, $row_height, 'Receiver Father Name', 1, 0, 'C', 1); $pdf->Cell(20, $row_height, 'Permanent Address', 1, 0, 'C', 1); $pdf->Cell(15, $row_height, 'Bank Account', 1, 0, 'C', 1); $pdf->Cell(20, $row_height, 'Remitter Name', 1, 0, 'C', 1); $pdf->Cell(20, $row_height, 'Father Name of Rmitter', 1, 0, 'C', 1); $pdf->Cell(15, $row_height, 'Country', 1, 0, 'C', 1); $pdf->Cell(20, $row_height, 'Relation', 1, 0, 'C', 1); $pdf->Cell(20, $row_height, 'NID', 1, 1, 'C', 1); $i = 0; $max = 30; $row_height = 5; $backup_sl_no = ""; while($row = mysqli_fetch_array($query)) { $sl_no = $row['sl_no']; $mobile_no = $row['mobile_no']; $receiver = $row['receiver']; $father_name = $row['father_name']; $permanent_address = $row['permanent_address']; $bank_ac = $row['bank_ac']; $remitter = $row['remitter']; $father_name_remitter = $row['father_name_remitter']; $origin = $row['origin']; $relation = $row['relation']; $image = $row['image']; /*if ($backup_sl_no != $sl_no) { $pdf->AddPage(); $pdf->SetFont('FreeSerif', 'B', 6); $pdf->SetFillColor(255, 255, 255); $pdf->Cell(193,$row_height, $sl_no, 1, 1, 'C', 1); } else { $pdf->AddPage(); $pdf->SetFont('FreeSerif', 'B', 6); $pdf->SetFillColor(255, 255, 255); } */ if ($i > $max) { $pdf->AddPage(); $pdf->SetFont('FreeSerif', 'B', 6); $pdf->SetFillColor(255, 255, 255); $pdf->Cell(8, $row_height, 'Sl No', 1, 0, 'C', 1); $pdf->Cell(15, $row_height, 'Mobile', 1, 0, 'C', 1); $pdf->Cell(20, $row_height, 'Receiver Name', 1, 0, 'C', 1); $pdf->Cell(20, $row_height, 'Receiver Father Name', 1, 0, 'C', 1); $pdf->Cell(20, $row_height, 'Permanent Address', 1, 0, 'C', 1); $pdf->Cell(15, $row_height, 'Bank Account', 1, 0, 'C', 1); $pdf->Cell(20, $row_height, 'Remitter Name', 1, 0, 'C', 1); $pdf->Cell(20, $row_height, 'Father Name of Rmitter', 1, 0, 'C', 1); $pdf->Cell(15, $row_height, 'Country', 1, 0, 'C', 1); $pdf->Cell(20, $row_height, 'Relation', 1, 0, 'C', 1); $pdf->Cell(20, $row_height, 'NID', 1, 1, 'C', 1); $i = 0; } if (!empty($sl_no)) { $pdf->SetFont('FreeSerif', '', 6); $pdf->Cell(8, $row_height, $sl_no, 1, 0, 'C', 1); $pdf->Cell(15, $row_height, $mobile_no, 1, 0, 'C', 1); $pdf->Cell(20, $row_height, $receiver, 1, 0, 'C', 1); $pdf->Cell(20, $row_height, $father_name, 1, 0, 'C', 1); $pdf->Cell(20, $row_height, $permanent_address, 1, 0, 'C', 1); $pdf->Cell(15, $row_height, $bank_ac, 1, 0, 'C', 1); $pdf->Cell(20, $row_height, $remitter, 1, 0, 'C', 1); $pdf->Cell(20, $row_height, $father_name_remitter, 1, 0, 'C', 1); $pdf->Cell(15, $row_height, $origin, 1, 0, 'C', 1); $pdf->Cell(20, $row_height, $relation, 1, 0, 'C', 1); $pdf->Cell(20, $row_height, $image, 1, 1, 'C', 1); } $backup_sl_no != $sl_no; $i++; } mysqli_close($conn); ob_end_clean(); $pdf->Output('mypdf.pdf', 'I'); ?>
     

Log in to post a comment.

MongoDB Logo MongoDB