Watermarking on PDF files using PHP
I'd check out this PHP Class on Github by binarystash. It seems to do what you are asking for.
https://github.com/binarystash/PDFWatermarker
Hopefully this helps.
Add background watermark to pdf files via PHP for existing .pdf files?
Yes you can with FPDF and this add-on http://www.fpdf.de/downloads/addons/9/
How do I add a watermark to a PDF using PHP and without removing dynamic content?
Here's the solution I've came up with:
Editing a pdf with php a cost effective manner isn't viable. If you're working with a single pdf, use an online service to convert it into an HTML file (there are many), then use php to edit in a watermark for that file document. Once that's done, use a service like Prince HTML to convert that HTML file back into a newly watermarked pdf to download.
Applying watermarks on pdf files when users try to download the files
Although there are several very good PDF libs for PHP, if I were writing such a program I'd just shell out to run pdftk but you' still need to generate your watermark.
$tempfile=tempnam();
system("pdftk input_file.pdf background watermark.pdf output $tempfile dont_ask", $errcode);
if (!$errcode && $ih=fopen($tempfile, 'r')) {
header('Content-Type: application/pdf');
fpassthru($ih);
fclose($ih);
} else {
print "Whoops";
}
unlink($tempfile);
Unable to add watermark image in existing PDF
I have created a library which define all header() , footer() function. I have made changes in the library file.I have remove all watermark generation code from library and call it where the actual PDF is generation function and my error was solved
// initiate PDF library
$pdf = new Digilib();
$pdf->setDate($date);
$pdf->name = ucfirst($name);
$url_curl = $distination_folder . $Filename;
$fileContent = file_get_contents($url_curl, false, stream_context_create(array('ssl' => array('verify_peer' => false, 'verify_peer_name' => false))));
$pageCount = $pdf->setSourceFile(StreamReader::createByString($fileContent));
for ($pageNo = 1; $pageNo <= $pageCount; $pageNo++) {
$templateId = $pdf->importPage($pageNo);
$size = $pdf->getTemplateSize($templateid);
$pdf->AddPage('P', array($size['width'], $size['height']));
$pdf->useTemplate($templateId);
$pdf->Image($logopath, 10, 10, 15, '', 'PNG', '', 'T', false, 300, '', false, false, 0, false, false, false);
$pdf->SetFont('freeserif', 'b', 15);
$pdf->Cell(0, 2, $CustomHeaderText, 0, false, 'C', 0, '', 0, false, 'T', 'C');
$pdf->SetFont('freeserif', 'b', 9);
$pdf->Cell(0, 2, '' . $pdf->getAliasNumPage() . '/' . $pdf->getAliasNbPages(), 0, false, 'C', 0, '', 0, false, 'T', 'M');
$ImageW = 105; //WaterMark Size
$ImageH = 80;
$pdf->setPage($pageNo); //WaterMark Page
$myPageWidth = $pdf->getPageWidth();
$myPageHeight = $pdf->getPageHeight();
$myX = ($myPageWidth / 2) - 50; //WaterMark Positioning
$myY = ($myPageHeight / 2) - 40;
$pdf->SetAlpha(0.35);
$pdf->Image($watermarkpath, $myX, $myY, $ImageW, $ImageH, '', '', 'C', true, 300);
$pdf->SetAlpha(1);
$pdf->SetFooterMargin(0);
}
Related Topics
Laravel Eloquent Compare Date from Datetime Field
MySQL Innodb Engine in Laravel
Post Arrays Not Showing Unchecked Checkboxes
What Does a PHP Function Return by Default
PHP Jquery Ajax Call Throws Net::Err_Empty_Response
How to Get PHP, Symlinks and _File_ to Work Together Nicely
Simulate File Structure with PHP
Remove Non English Characters PHP
Convert a String to a Double - Is This Possible
How to Remove Values from Two Arrays That Have the Same Key and Value
How to Clear PHP's Gettext Cache Without Restart Apache Nor Change Domain
How to Call a Static Method from a Class If All I Have Is a String of the Class Name
MySQL Table Does Not Exist Error, But It Does Exist
Create Nested List from Multidimensional Array