Search code examples
phpfpdfwatermark

How set watermark behind text in fpdf


is there who can help me, i had a problem with the watermark in fpdf

Here is my code:

$width_header = array(10,45,25,60,20,15,15);
$set_align    = array('L','L','L','L','R','L','R');
$table_head   = array('No.','Kelompok','Kode Brg','Nama Barang','QTY','','Cek list');
$page_copy    = 0;
$fpdf->SetFont('Arial','B',11);

$lebar = $fpdf->w;

$fpdf->line($fpdf->GetX(), $fpdf->GetY(), $fpdf->GetX()+$lebar-18, $fpdf->GetY());
$fpdf->Ln(2);
$fpdf->SetWidths($width_header);
$fpdf->SetAligns($set_align);
$fpdf->SetFont('Arial','B',9);
for($i=1;$i<=1;$i++) {
    $fpdf->Row_Header($table_head);
}
$fpdf->line($fpdf->GetX(), $fpdf->GetY(), $fpdf->GetX()+$lebar-18, $fpdf->GetY());

$no        = 1;
$sub_total = 0;
$sql2 = $this->adm_entry_penjualan_model->getDataCetakDetil(" WHERE a.hps<>'*' AND a.no_bukti='$no_bukti_tmp' AND a.tgl='$tgl_tmp' ORDER BY b.acct_no, b.kode_sub");

$fpdf->SetFont('Arial','',10);

foreach ($sql2->result_array() as $key_no => $row2) {
        //Put the watermark
        $fpdf->SetFont('Arial','B',50);
        $fpdf->SetTextColor(255,222,233);
        $fpdf->RotatedText(90,90,'COPY',45);
        $fpdf->SetFont('Arial','',10);
        $fpdf->SetTextColor(0,0,0);
        $fpdf->SetFont('Arial','',10);
    $fpdf->Row(
        array($no++,
        $row2['acct_name'],
        $row2['kode_sub'],
        $row2['nama_sub'],
        $row2['qty'].' ',
        $row2['satuan'],
        '...'
    ));

    $fpdf->line($fpdf->GetX(), $fpdf->GetY(), $fpdf->GetX()+$lebar-18, $fpdf->GetY());

}

I want a result like this image:

image 1

but it looks like this image:

image 2

what should I change in order to get the results I want

sorry for my bad english


Solution

  • Put your watermark code in the Header() function as shown in this example. That way the watermark will be set on AddPage(), i.e. before the actual content is output, making the watermark appear in the "background".