Clippit icon indicating copy to clipboard operation
Clippit copied to clipboard

Add text in word Watermark in DocumentAssembler

Open luizfbicalho opened this issue 1 year ago • 7 comments

Did anyone suceeded in addng a watermark to the template, with a tranformation and make it work?

Mine was like this

image

luizfbicalho avatar Apr 06 '23 21:04 luizfbicalho

You may start from posting here code sample that you have used.

sergey-tihon avatar Apr 08 '23 11:04 sergey-tihon

DocumentWaterMark.docx DocumentWaterMark_Transformed.docx

I Uploaded the files and this is the xml

<Data>
	<Name>Abelardo Barbosa</Name>
	<Address>Rua Montes Passados, 1550</Address>
	<Phone>(11)9999-9999</Phone>
	<Email>[email protected]</Email>
	<WaterMark>TEXTO QUE PRECISO PARA COLOCAR DE FUNDO NO DOCUMENTO</WaterMark>
</Data>

This is the template image

image image

and this is the result image

image

As you can see the Assembled document still have the <#<Content Select="./WaterMark"/>#> on the watermark.

Is that possible?

luizfbicalho avatar Apr 11 '23 12:04 luizfbicalho

What code/class do you use (and how)?

sergey-tihon avatar Apr 11 '23 17:04 sergey-tihon

This is the code, just a simple AssembleDocument @sergey-tihon

var wmlDoc = new WmlDocument("template.docx", template);
var element = XElement.Parse(orig);
bool templateError;
var wmlAssembledDoc = DocumentAssembler.AssembleDocument(wmlDoc, element, out templateError);
return wmlAssembledDoc.DocumentByteArray;

luizfbicalho avatar Apr 11 '23 18:04 luizfbicalho

I believe that watermarks are not supported yet. If you decide to implement this, you need to take a look inside your template, find markup for the watermark and then extend content transformation to the property handle transformation - https://github.com/sergey-tihon/Clippit/blob/master/OpenXmlPowerTools/Word/DocumentAssembler.cs#L1152

sergey-tihon avatar Apr 21 '23 12:04 sergey-tihon

The watermark is inside a shape, the xml is this

<v:textpath style="font-family:&quot;Calibri&quot;;font-size:1pt" string="&lt;#&lt;Content Select=&quot;./WaterMark&quot;/&gt;#&gt;" xmlns:v="urn:schemas-microsoft-com:vml" />

I would work fine if it were a subnode but as an string it's too unsafe to change, do you have any other idea?

luizfbicalho avatar Apr 23 '23 23:04 luizfbicalho

I see no other options rather than special case for string attribute of v:textpath

sergey-tihon avatar Apr 24 '23 14:04 sergey-tihon