使用Image从HTML创建Word文档

时间:2014-03-05 20:38:18

标签: html ms-word vml

我从一些格式化的HTML生成word文档时遇到一些小问题 我一直在使用下面这个链接的代码。 HTML generated Microsoft Word document with header, footer and watermark

我遇到的唯一问题是当我将文档发送到没有本地存储图像的地方时,我会找到图像未找到的图像链接。我希望有人能指出我正确的方向。我很想在python中做些什么来处理这个问题,但遗憾的是由于工作我坚持使用HTML和其他一些东西(我的javascript还不是很好,所以你)。任何帮助表示赞赏。

代码如下。

提前致谢。

    <html xmlns:v="urn:schemas-microsoft-com:vml"
xmlns:o="urn:schemas-microsoft-com:office:office"
xmlns:w="urn:schemas-microsoft-com:office:word"
xmlns:m="http://schemas.microsoft.com/office/2004/12/omml"
xmlns="http://www.w3.org/TR/REC-html40">
<head><meta http-equiv=Content-Type content="text/html; charset=utf-8"><title></title>
<style>
v\:* {behavior:url(#default#VML);}
o\:* {behavior:url(#default#VML);}
w\:* {behavior:url(#default#VML);}
.shape {behavior:url(#default#VML);}
</style>
<style>
body
{
font-family: Arial;
}

th{

    text-align: left;
    text-decoration: underline;
}
.header
{
text-align: center;
}
#title{
font-size: 18px;
font-weight: bold;
}
#subtitle{
font-size: 16px;
font-weight: bold;
text-decoration: underline;
}
#footer{
text-align: right;
font-size: 10px;
}

#conditions{
    width: 100%;
    text-align: justify;
}

.first {
    vertical-align: top;
    width: 40%;
    font-weight: bold;
}

#signing{
    width: 100%;
}

.ownersignature{
    text-align: center;
}

#pageheader{
    position: relative;
    text-align: right;
}
/*#signing td{
    width: 40%;
}*/
#h1{
    text-align: right;
}

@page
{
    mso-page-orientation: Portrait;
    size:21cm 29.7cm;    
    margin:1.8cm 1cm 1cm 1cm;
}
@page Section1 {
    mso-header-margin:.2cm;
    mso-footer-margin:.2in;
    mso-title-page: yes;
    mso-first-header: fh1;
    mso-footer: f1;
    }
div.Section1 { 
    page:Section1;
 }
div#hrdftrtbl
{
    margin:0in 0in 0in 900in;

    width:1px;
    height:1px;
    overflow:hidden;
}
div.MsoHeader{
    text-align: right;
}

p.MsoFooter, li.MsoFooter, div.MsoFooter
{
    margin:0in;
    margin-bottom:.0001pt;
    mso-pagination:widow-orphan;
    tab-stops:center 3.0in right 6.0in;
    font-size:12.0pt;
    float: right;
}
</style>
<xml>
<w:WordDocument>
<w:View>Print</w:View>
<w:Zoom>100</w:Zoom>
<w:DoNotOptimizeForBrowser/>
</w:WordDocument>
</xml>
</head>
<body>

<div id="pageheader">


    <p class=header><span id='title'>Title!</span><br/><br/><span id='subtitle'>subtitle!</span></p>

</div>

<div class=Section1>

<!-- Header section -->


<div id='hrdftrtbl'>
    <div style='mso-element:footer' id=f1><span style='position:relative;#hz-index:-1'> 
        <!-- FOOTER-tags -->
        <div id='footer'><br/><br/>This is my footer</div>


   </span>


        </p>
    </div>

    <div id='hrdftrbl'>
        <div style='mso-element:header' id=fh1 >
            <span style='mso-no-proof:yes'>
                <!--[if gte vml 1]>
                <v:shapetype id="_x0000_t75"
                    coordsize="21600,21600" o:spt="75" o:preferrelative="t" path="m@4@5l@4@11@9@11@9@5xe"
                    filled="f" stroked="f">
                    <v:stroke joinstyle="miter"/>
                    <v:formulas>
                        <v:f eqn="if lineDrawn pixelLineWidth 0"/>
                        <v:f eqn="sum @0 1 0"/>
                        <v:f eqn="sum 0 0 @1"/>
                        <v:f eqn="prod @2 1 2"/>
                        <v:f eqn="prod @3 21600 pixelWidth"/>
                        <v:f eqn="prod @3 21600 pixelHeight"/>
                        <v:f eqn="sum @0 0 1"/>
                        <v:f eqn="prod @6 1 2"/>
                        <v:f eqn="prod @7 21600 pixelWidth"/>
                        <v:f eqn="sum @8 21600 0"/>
                        <v:f eqn="prod @7 21600 pixelHeight"/>
                        <v:f eqn="sum @10 21600 0"/>
                    </v:formulas>
                    <v:path o:extrusionok="f" gradientshapeok="t" o:connecttype="rect"/>
                    <o:lock v:ext="edit" aspectratio="t"/>
                </v:shapetype>
                <v:shape id="_x0000_s1025" type="#_x0000_t75" alt="" style='position:absolute;
                    margin-left:0;margin-top:2pt;width:537pt;height:57pt;z-index:251659264'>
                    <v:imagedata src="/home/user/Documents/image.jpg"/>
                    <w:wrap type="square"/>
                </v:shape>
                <![endif]-->
            </span>
        </div>
    </div>

    <div style='mso-element:header' id=fh1>
        <p class=MsoHeader><span lang=EN-US style='mso-ansi-language:EN-US'>&nbsp;<o:p></o:p></span></p>

        </div>
        <div style='mso-element:footer' id=ff1>
        <p class=MsoFooter><span lang=EN-US style='mso-ansi-language:EN-US'>&nbsp;<o:p></o:p></span></p>
    </div>



</div>

</body>
</html>

0 个答案:

没有答案