sergey-tihon / Clippit

Fresh PowerTools for OpenXml
https://sergey-tihon.github.io/Clippit/
MIT License
50 stars 19 forks source link

Add text in word Watermark in DocumentAssembler #62

Open luizfbicalho opened 1 year ago

luizfbicalho commented 1 year ago

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

Mine was like this

image
sergey-tihon commented 1 year ago

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

luizfbicalho commented 1 year ago

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>aberlardo@tvz.com.br</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 <##> on the watermark.

Is that possible?

sergey-tihon commented 1 year ago

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

luizfbicalho commented 1 year ago

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;
sergey-tihon commented 1 year ago

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

luizfbicalho commented 1 year ago

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?

sergey-tihon commented 1 year ago

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