이 스택 질문을 수정했습니다 : Applying watermarks on pdf files when users try to download the files 그러나 오류가 발생했습니다. 수정 방법에 대한 설명이 있지만 정교하지는 못했습니다. 내가 페이지 이상이 모두 한 페이지에 병합되어있는 PDF 파일을로드 할 때FPDI/FPDF : 워터 마크 및 여러 페이지 인쇄
require_once('fpdf/fpdf.php');
require_once('fpdi/fpdi.php');
class WaterMark
{
public $pdf, $file, $newFile,
$wmText = "STACKOVERFLOW";
/** $file and $newFile have to include the full path. */
public function __construct($file, $newFile)
{
$this->pdf = new FPDI();
$this->file = $file;
$this->newFile = $newFile;
}
/** $file and $newFile have to include the full path. */
public static function applyAndSpit($file, $newFile)
{
$wm = new WaterMark($file, $newFile);
if($wm->isWaterMarked())
return $wm->spitWaterMarked();
else{
$wm->doWaterMark();
return $wm->spitWaterMarked();
}
}
/** @todo Make the text nicer and add to all pages */
public function doWaterMark()
{
$currentFile = $this->file;
$newFile = $this->newFile;
$this->pdf->addPage();
$pagecount = $this->pdf->setSourceFile($currentFile);
for($i = 1; $i <= $pagecount; $i++){
$tplidx = $this->pdf->importPage($i);
$this->pdf->useTemplate($tplidx, 10, 10, 100);
// now write some text above the imported page
$this->pdf->SetFont('Arial', 'I', 40);
$this->pdf->SetTextColor(255,0,0);
$this->pdf->SetXY(25, 135);
$this->_rotate(55);
$this->pdf->Write(0, $this->wmText);
}
$this->pdf->Output($newFile, 'F');
}
public function isWaterMarked()
{
return (file_exists($this->newFile));
}
public function spitWaterMarked()
{
return readfile($this->newFile);
}
protected function _rotate($angle,$x=-1,$y=-1) {
if($x==-1)
$x=$this->pdf->x;
if($y==-1)
$y=$this->pdf->y;
if($this->pdf->angle!=0)
$this->pdf->_out('Q');
$this->pdf->angle=$angle;
if($angle!=0){
$angle*=M_PI/180;
$c=cos($angle);
$s=sin($angle);
$cx=$x*$this->pdf->k;
$cy=($this->pdf->h-$y)*$this->pdf->k;
$this->pdf->_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));
}
}
}
header('Content-type: application/pdf');
//header('Content-Disposition: attachment; filename="downloaded.pdf"');
WaterMark::applyAndSpit('C:\xampp\htdocs\tst\test0.pdf','C:\xampp\htdocs\tst\output0.pdf');
: 여기
는 코드입니다. 이 게시물에 이미지를 첨부했습니다.감사합니다.
@vascowhite이 문제를 해결하는 방법에 대한 아이디어가 있습니까? –
사실,하지만 삽입되는 것을 확인하여 시작할 것입니다. 전체 페이지가 회전 된 것처럼 보입니다. 죄송하지만 fpdf에 대한 많은 경험이 없습니다. 나는 그것을 사용했지만 매우 기본적인 것들을 위해서만 사용했다. 내가 나중에 그것을 가지고 놀 기회가 있다면 오늘 내가 찾을 수있는 것을 볼 것입니다. 행운을 빕니다. – vascowhite
본 적이 있니? http://www.setasign.de/products/pdf-php-solutions/setapdf-stamper/ – vascowhite