edcolon wrote: ↑Tue Oct 09, 2018 11:27 am
Hi,
how do I put an image as a watermark in an output document?
Processmaker recomends to use TCPDF instead of HTML2PDF. With the latter it works however with TCPDF does not.
Thanks in advance.
@Ed
I know this might be old but here's what I did to add a Watermark in TCPDF.
1. Open the file
Code: Select allworkflow/engine/classes/model/OutputDocument.php
2. Locate the function
Code: Select allpublic function generateTcpdf($sUID, $aFields, $sPath, $sFilename, $sContent, $sLandscape = false, $aProperties = array())
and scroll down until you find this portion
Code: Select all $pdf->AddPage();
// set text shadow effect
//$pdf->setTextShadow(array('enabled'=>true, 'depth_w'=>0.2, 'depth_h'=>0.2, 'color'=>array(196,196,196), 'opacity'=>1, 'blend_mode'=>'Normal'));
// Print text using writeHTMLCell()
// $pdf->writeHTMLCell($w=0, $h=0, $x='', $y='', $html, $border=0, $ln=1, $fill=0, $reseth=true, $align='', $autopadding=true);
if (mb_detect_encoding($sContent) == 'UTF-8') {
$sContent = mb_convert_encoding($sContent, 'HTML-ENTITIES', 'UTF-8');
}
$doc = new DOMDocument('1.0', 'UTF-8');
if ($sContent != '') {
$doc->loadHtml($sContent);
}
$pdf->writeHTML($doc->saveXML(), false, false, false, false, '');
// ---------------------------------------------------------
// Close and output PDF document
// This method has several options, check the source code documentation for more information.
//$pdf->Output('example_00.pdf', 'I');
//$pdf->Output('/home/hector/processmaker/example_00.pdf', 'D');
switch ($sOutput) {
case 0:
// Vrew browser
$pdf->Output($sPath . $sFilename . '.pdf', 'I');
break;
case 1:
// Donwnload
$pdf->Output($sPath . $sFilename . '.pdf', 'D');
break;
case 2:
// Save file
$pdf->Output($sPath . $sFilename . '.pdf', 'F');
break;
}
3. Add this code before
$pdf->writeHTML($doc->saveXML(), false, false, false, false, '');
Code: Select all // -- set new background
// get the current page break margin
$bMargin = $pdf->getBreakMargin();
// get current auto-page-break mode
$auto_page_break = $pdf->getAutoPageBreak();
// disable auto-page-break
$pdf->SetAutoPageBreak(false, 0);
// set background image
$img_file ='location/of/the.watermark/image.png';
//$pdf->Image($img_file, top,left, width,height, '', '', '', false, 300, '', false, false, 0);
$pdf->Image($img_file, 15, 50, 180, 180, '', '', '', false, 300, '', false, false, 0);
// restore auto-page-break status
$pdf->SetAutoPageBreak($auto_page_break, $bMargin);
// set the starting point for the page content
$pdf->setPageMark();
Adjust accordingly the top, left, width and height.
Thanks,
hnxDavid