It seems that it is possible without big problems...
For PDF, you have the library PDF Watermarker. Example of her use:
<?php
require_once('pdfwatermarker/pdfwatermarker.php');
require_once('pdfwatermarker/pdfwatermark.php');
//Specify path to image. The image must have a 96 DPI resolution.
$watermark = new PDFWatermark('C:\myimage.png');
//Set the position
$watermark->setPosition('bottomleft');
//Place watermark behind original PDF content. Default behavior places it over the content.
$watermark->setAsBackground();
//Specify the path to the existing pdf, the path to the new pdf file, and the watermark object
$watermarker = new PDFWatermarker('C:\test.pdf','C:\output.pdf',$watermark);
//Set page range. Use 1-based index.
$watermarker->setPageRange(1,5);
//Save the new PDF to its specified location
$watermarker->savePdf();
?>
For Word, I found it on Github using the library you mentioned, Phpword. Except you didn’t open any files to edit, I don’t know if that would be hard:
<?php
require_once '../PHPWord.php';
// New Word Document
$PHPWord = new PHPWord();
// New portrait section
$section = $PHPWord->createSection();
// Create header
$header = $section->createHeader();
// Add a watermark to the header
$header->addWatermark('_earth.jpg', array('marginTop'=>200, 'marginLeft'=>55));
$section->addText('The header reference to the current section includes a watermark image.');
// Save File
$objWriter = PHPWord_IOFactory::createWriter($PHPWord, 'Word2007');
$objWriter->save('Watermark.docx');
?>
Sources:
Show us the header you already have so we can help you better.
– Mariana Bayonetta
hello, the header was an example, what I need is to put a message in the document, I have the document saved . doc or . pdf, now I need to add the watermark, I saw some things about Phpword, however I only found to generate the document and not how to add in the existing document.
– Luan Amado