我试图在PDF上放置一个水印,它在单个页面上工作得很好,但是当内容是多个页面时,它将水标记放在第一页上,只有.how才能在每个页面中放置这个水印。是否可以在FPDF.Any帮助中插入图像而不是文本,这将是非常可观的。
class PDF_Rotate extends FPDF
{
var $angle=0;
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 _endpage()
{
if($this->angle!=0)
{
$this->angle=0;
$this->_out('Q');
}
parent::_endpage();
}
}
class mypdf extends PDF_Rotate{
function Header1()
{
/* Put the watermark */
$this->SetFont('Arial','B',50);
$this->SetTextColor(225,225,225);
$this->RotatedText(35,190,'I U A C',45);
//$this->RotatedText(135,190,'I U A C',45);
$this->RotatedText(235,190,'I U A C',45);
$this->RotatedText(95,160,'GEOCHRONOLOGY',45);
$this->RotatedText(65,70,'I U A C',45);
//$this->RotatedText(135,60,'I U A C',45);
$this->RotatedText(235,70,'I U A C',45);
}
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 Footer()
{
// Position at 1.5 cm from bottom
$this->SetY(179);
// Arial italic 8
$this->SetFont('Arial','I',8);
// Text color in gray
$this->SetTextColor(128);
// Page number
$this->Cell(0,10,'Page '.$this->PageNo(),0,0,'C');
$pdf = new mypdf();
$pdf->AliasNbPages();
$pdf->AddPage('L','A4',0);
$pdf->Header1();
$pdf->headerTable();
$pdf->viewTable();
$pdf->footer();
$pdf->output();发布于 2019-11-26 13:48:36
关于Shubham Baranwal和Dave告诉你的..。您应该将标头方法添加到"PDF_Rotate“类中,并且在该方法中添加水印。
据我所见,您有一个名为Header1的方法,只需将其重命名为Header即可。
另外,对于插入图像,它应该是相同的进程,只需在标头方法中添加一个图像,它就会被复制。
https://stackoverflow.com/questions/59043875
复制相似问题