What is the way to add watermark text in a docx file using python?

六月ゝ 毕业季﹏ 提交于 2020-04-30 06:57:25

问题


I'm manipulating a docx file using python-docx module which doesn't seem to have watermark support. What can be the possible way to add some watermark text in a docx file using python?

Edit: I've created a blank document with a watermark text= 'Tariq'. This includes a 'header1.xml' file in the zipped version of the docx file.

    <?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<w:hdr mc:Ignorable="w14 wp14" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:r="http://schemas.openxmlformats.org/officeDocument/2006/relationships" xmlns:v="urn:schemas-microsoft-com:vml" xmlns:w="http://schemas.openxmlformats.org/wordprocessingml/2006/main" xmlns:w10="urn:schemas-microsoft-com:office:word" xmlns:w14="http://schemas.microsoft.com/office/word/2010/wordml" xmlns:wp="http://schemas.openxmlformats.org/drawingml/2006/wordprocessingDrawing" xmlns:wp14="http://schemas.microsoft.com/office/word/2010/wordprocessingDrawing" xmlns:wpg="http://schemas.microsoft.com/office/word/2010/wordprocessingGroup" xmlns:wps="http://schemas.microsoft.com/office/word/2010/wordprocessingShape">
    <w:p>
        <w:pPr>
            <w:pStyle w:val="Header"/>
            <w:rPr/>
        </w:pPr>
        <w:r>
            <w:rPr/>
            <w:pict>
                <v:shapetype adj="10800" coordsize="21600,21600" id="shapetype_136" o:spt="136" path="m@9,l@10,em@11,21600l@12,21600e">
                    <v:stroke joinstyle="miter"/>
                    <v:formulas>
                        <v:f eqn="val #0"/>
                        <v:f eqn="sum @0 0 10800"/>
                        <v:f eqn="sum @0 0 0"/>
                        <v:f eqn="sum width 0 @0"/>
                        <v:f eqn="prod @2 2 1"/>
                        <v:f eqn="prod @3 2 1"/>
                        <v:f eqn="if @1 @5 @4"/>
                        <v:f eqn="sum 0 @6 0"/>
                        <v:f eqn="sum width 0 @6"/>
                        <v:f eqn="if @1 0 @8"/>
                        <v:f eqn="if @1 @7 width"/>
                        <v:f eqn="if @1 @8 0"/>
                        <v:f eqn="if @1 width @7"/>
                    </v:formulas>
                    <v:handles>
                        <v:h position="@0,21600"/>
                    </v:handles>
                </v:shapetype>
                <v:shape fillcolor="silver" id="PowerPlusWaterMarkObject" o:spid="shape_0" stroked="f" style="position:absolute;margin-left:-0.05pt;margin-top:203.3pt;width:498.5pt;height:257.65pt;rotation:315;mso-position-horizontal:center;mso-position-horizontal-relative:margin;mso-position-vertical:center;mso-position-vertical-relative:margin" type="shapetype_136">
                    <v:path textpathok="t"/>
                    <v:textpath fitshape="t" on="t" string="Tariq" style="font-family:&quot;Liberation Sans&quot;;font-size:1pt" trim="t"/>
                    <w10:wrap type="none"/>
                    <v:fill color2="#3f3f3f" o:detectmouseclick="t" opacity="0.5" type="solid"/>
                    <v:stroke color="#3465a4" endcap="flat" joinstyle="round"/>
                </v:shape>
            </w:pict>
        </w:r>
        <w:bookmarkStart w:id="0" w:name="__UnoMark__0_101710128"/>
        <w:bookmarkStart w:id="1" w:name="__UnoMark__0_101710128"/>
        <w:bookmarkEnd w:id="1"/>
    </w:p>
</w:hdr>

来源:https://stackoverflow.com/questions/56074727/what-is-the-way-to-add-watermark-text-in-a-docx-file-using-python

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!