Skip to content

Instantly share code, notes, and snippets.

@Guley
Created January 31, 2020 11:12
Show Gist options
  • Save Guley/6f3656770281170f04fd8b03d9ad768b to your computer and use it in GitHub Desktop.
Save Guley/6f3656770281170f04fd8b03d9ad768b to your computer and use it in GitHub Desktop.
Tcpdf add custom text watermark
<?php
require('Pdf.php');
class PDF_Rotate extends Pdf
{
var $angle=0;
function Header()
{
//Put the watermark
$this->SetFont('','B',40);
$this->SetTextColor( 165, 203, 73 );
$this->RotatedText(10,190,'It is under comapny name proprietor. ',45);
}
function Rotate($angle,$x=-1,$y=-1)
{
if($x==-1)
$x=$this->x;
if($y==-1)
$y=$this->y;
if($this->angle!=0)
$this->_out('Q');
$this->angle=$angle;
if($angle!=0)
{
$angle*=M_PI/180;
$c=cos($angle);
$s=sin($angle);
$cx=$x*$this->k;
$cy=($this->h-$y)*$this->k;
$this->_out(sprintf('q %.5F %.5F %.5F %.5F %.2F %.2F cm 1 0 0 1 %.2F %.2F cm',$c,$s,-$s,$c,$cx,$cy,-$cx,-$cy));
}
}
function RotatedText($x, $y, $txt, $angle)
{
//Text rotated around its origin
$this->Rotate($angle,$x,$y);
$this->Text($x,$y,$txt);
$this->Rotate(0);
}
function _endpage()
{
if($this->angle!=0)
{
$this->angle=0;
$this->_out('Q');
}
parent::_endpage();
}
}
$pdf= new PDF_Rotate();
?>
@wuminmin
Copy link

where is 'Pdf.php ?

@Guley
Copy link
Author

Guley commented Dec 20, 2022

@wuminmin You need to add the TcPDF library to your project and you will see the file there.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment