Forum


Replies: 5   Views: 229
Remove watermark added by phpdocx
Topic closed:
Please note this is an old forum thread. Information in this post may be out-to-date and/or erroneous.
Every phpdocx version includes new features and improvements. Previously unsupported features may have been added to newer releases, or past issues may have been corrected.
We encourage you to download the current phpdocx version and check the Documentation available.

Posted by Bouillou  · 04-09-2024 - 08:48

Hello,

I'm using PHPDocX v15.0

For some of my documents, I add a watermark. The documents contain pages in portrait and landscape format.

Sometimes I want to edit the document and remove the watermark. However, the official method provided by MS through the menu “Design→Watermark→Remove Watermark” doesn't remove it. Instead, I have to click on the header, then select the watermark text and finally remove it. BUT this doesn't remove all the watermarks, only the watermark present on the page. As a result, I have to delete the watermark on each page individually.

Is there any way to make the watermark work with the “Design→Watermark→Remove Watermark” menu?

Best regards

Posted by admin  · 04-09-2024 - 09:49

Hello,

What version of MS Word are you using? We have tested the "Remove Watermark" option available in MS Word with the included samples in the package and the watermark is removed correctly when the scope is the default value (header).

Please note that phpdocx allows adding watermaks in the following scopes:

Header (default) or footer.

Using the footer scope doesn't allow removing watermarks using the "Remove Watermark" option available in MS Word. In this case (footer scope), to remove the watermark, you need to select the header or footer and remove the watermark by selecting it. This doesn't happen if you use the header scope. To use the header scope, please do not set the scope option.
We have tested it with MS Word 2010, MS Word 2013, MS Word 2019 and MS Word 2021 and the behaviour is the same.

Please check the included samples and try again setting header as scope if you are using custom footer scope.

Also note that using MS Word, you many need to remove section watermarks one by one:

https://www.quora.com/How-do-you-remove-a-watermark-in-Word-from-all-pages-at-once

Please note that this is a MS Word requirement/limitation that we can't change. The same happens if the DOCX is created with phpdocx or any DOCX editor.

You can also use the watermarkRemove method to remove watermarks using phpdocx.

Regards.

Posted by Bouillou  · 04-09-2024 - 14:33

Thanks for your tests and reply,

The document has section breaks to toogle between portait and landscape page layout every 2 pages. Could it be the reason why deleting the watermark is only done 2 pages at times ?

Best regards

Posted by admin  · 04-09-2024 - 15:01

Hello,

If we run the following code:

$docx = new CreateDocx();

$docx->addText('Section 1A');
$docx->addBreak(array('type' => 'page'));
$docx->addText('Section 1B');

$docx->addSection('nextPage', 'A4-landscape');
$docx->addText('Section 2A');
$docx->addBreak(array('type' => 'page'));
$docx->addText('Section 2B');

$docx->addSection('nextPage', 'A4');
$docx->addText('Section 3A');
$docx->addBreak(array('type' => 'page'));
$docx->addText('Section 3B');

$docx->createDocx('new_document');

$docxUtilities = new DocxUtilities();
$docxUtilities->watermarkDocx('new_document.docx', 'new_document_watermark.docx', 'text', array('text' => 'phpdocx'));

that adds: two pages, a section break with a landscape layout, two pages, a section break with a portrait  layout, and two pages. A watermark is added to all sections.

If we open the DOCX output with MS Word and choose "Remove Watermark", all watermarks are removed correctly. However, as explained in our previous reply, removing watermarks per section may sometimes be needed.

For further support, we'd need to check the DOCX output and the watermarkDocx options you are using. You can send them to contact[at]phpdocx.com

Regards.

Posted by Bouillou  · 20-09-2024 - 06:53

In fact the problem occurs when several documents are merged together, then a watermarking is added.

In that case, the watermarking is not global to the whole file but to the merged files.

Best regards

Posted by admin  · 20-09-2024 - 09:41

Hello,

mergeDocx generates a single DOCX merging two or more DOCX documents. A watermark can be added to the DOCX output using watermarkDocx (as any other DOCX document). The watermark can be added to the whole document or per section (section option).

For further support about this same question, please send to "contact[at]phpdocx.com" the simplest PHP code that illustrates your case of use and the DOCX output you get. We'll check them. This code must use phpdocx standalone (without external resources such as databases, web services, frameworks...).

Regards.