相同的html内容,但结果布局不同,同时使用python转换为docx和pdf

时间:2019-03-07 06:57:52

标签: python html pdf docx python-pdfkit

我从原始内容中给出了一段html内容,如下所示:

<style type="text/css">   @page { size: 8.27in 11.69in; margin: 0.2in }        </style>
<table style="border-collapse:collapse;border:none;mso-border-alt:solid windowtext .5pt;" cellspacing="0" cellpadding="0" bordercolor="#2b628d" border="1">
   <tbody>
		<tr style="border-top: 1px solid #2b628d;    border-collapse: collapse; " height="20">
         <td>
            
            <p style="margin-bottom: 0in; font-weight: normal" align="left"><font color="#336699">  <font face="Calibri, sans-serif"><font style="font-size: 8pt" size="1"><u><b>Information:</b></u></font></font></font></p>
            
            <table width="705" cellspacing="0" cellpadding="4">
               
               <tbody>
                  <tr valign="top" height="20">
                     <td style="border-top: 1px solid #ffffff; border-bottom: 1px solid #ffffff; border-left: 1px solid #ffffff; border-right: none; padding-top: 0.01in; padding-bottom: 0.01in; padding-left: 0.04in; padding-right: 0in">
                        <p style="margin-left: -0.02in; font-weight: normal"><font color="#336699"><font face="Calibri, sans-serif"><font style="font-size: 8pt" size="1"><span style="background: #ffffff">First    Name:</span></font></font></font>    </p>
                     </td>
					 <td style="border-top: 1px solid #ffffff; border-bottom: 1px solid #ffffff; border-left: 1px solid #ffffff; border-right: none; padding-top: 0.01in; padding-bottom: 0.01in; padding-left: 0.04in; padding-right: 0in">
                        <p style="margin-left: -0.02in; font-weight: normal"><font color="#336699"><font face="Calibri, sans-serif"><font style="font-size: 8pt" size="1"><span style="background: #ffffff">XXXX</span></font></font></font>    </p>
                     </td>
                     
                     <td style="border-top: 1px solid #ffffff; border-bottom: 1px solid #ffffff; border-left: 1px solid #ffffff; border-right: none; padding-top: 0.01in; padding-bottom: 0.01in; padding-left: 0.04in; padding-right: 0in">
                        <p style="font-weight: normal"><font color="#336699"><font face="Calibri, sans-serif"><font style="font-size: 8pt" size="1"><span style="background: #ffffff">Middle    Name:</span></font></font></font></p>
                     </td>
                     <td style="border-top: 1px solid #ffffff; border-bottom: 1px solid #ffffff; border-left: 1px solid #ffffff; border-right: none; padding-top: 0.01in; padding-bottom: 0.01in; padding-left: 0.04in; padding-right: 0in">
                        <p style="font-weight: normal"><font color="#336699"><font face="Calibri, sans-serif"><font style="font-size: 8pt" size="1"><span style="background: #ffffff">YYYY</span></font></font></font></p>
                     </td>
                     <td style="border-top: 1px solid #ffffff; border-bottom: 1px solid #ffffff; border-left: 1px solid #ffffff; border-right: none; padding-top: 0.01in; padding-bottom: 0.01in; padding-left: 0.04in; padding-right: 0in">
                        <p style="font-weight: normal"><font color="#336699"><font face="Calibri, sans-serif"><font style="font-size: 8pt" size="1"><span style="background: #ffffff">Last    Name:</span></font></font></font>    </p>
                     </td>
                     <td style="border-top: 1px solid #ffffff; border-bottom: 1px solid #ffffff; border-left: 1px solid #ffffff; border-right: none; padding-top: 0.01in; padding-bottom: 0.01in; padding-left: 0.04in; padding-right: 0in">
                        <p style="font-weight: normal"><font color="#336699"><font face="Calibri, sans-serif"><font style="font-size: 8pt" size="1"><span style="background: #ffffff">ZZZZ </span></font></font></font>    </p>
                     </td>
                  </tr>

                  <tr valign="top" height="20">
                     <td style="border-top: none; border-bottom: 1px solid #ffffff; border-left: 1px solid #ffffff; border-right: none; padding-top: 0in; padding-bottom: 0.01in; padding-left: 0.04in; padding-right: 0in">
                        <p style="margin-left: -0.02in; font-weight: normal"><font color="#336699"><font face="Calibri, sans-serif"><font style="font-size: 8pt" size="1"><span style="background: #ffffff">Street    1:</span></font></font></font>    </p>
                     </td>
                     <td style="border-top: none; border-bottom: 1px solid #ffffff; border-left: 1px solid #ffffff; border-right: none; padding-top: 0in; padding-bottom: 0.01in; padding-left: 0.04in; padding-right: 0in">
                        <p style="margin-left: -0.02in; font-weight: normal"><font color="#336699"><font face="Calibri, sans-serif"><font style="font-size: 8pt" size="1"><span style="background: #ffffff">New street</span></font></font></font>    </p>
                     </td>
                     <td style="border-top: none; border-bottom: 1px solid #ffffff; border-left: 1px solid #ffffff; border-right: none; padding-top: 0in; padding-bottom: 0.01in; padding-left: 0.04in; padding-right: 0in">
                        <p style="margin-left: -0.02in; font-weight: normal" align="justify">    <font color="#336699"><font face="Calibri, sans-serif"><font style="font-size: 8pt" size="1"><span style="background: #ffffff">Street    2:</span></font></font></font>    </p>
                     </td>
                     <td style="border-top: none; border-bottom: 1px solid #ffffff; border-left: 1px solid #ffffff; border-right: none; padding-top: 0in; padding-bottom: 0.01in; padding-left: 0.04in; padding-right: 0in">
                        <p style="margin-left: -0.02in; font-weight: normal" align="justify">    <font color="#336699"><font face="Calibri, sans-serif"><font style="font-size: 8pt" size="1"><span style="background: #ffffff">New street 2</span></font></font></font>    </p>
                     </td>
                     <td style="border-top: none; border-bottom: 1px solid #ffffff; border-left: 1px solid #ffffff; border-right: none; padding-top: 0in; padding-bottom: 0.01in; padding-left: 0.04in; padding-right: 0in">
                        <p style="font-weight: normal" align="justify"><font color="#336699"><font face="Calibri, sans-serif"><font style="font-size: 8pt" size="1"><span style="background: #ffffff">Email:</span></font></font></font>    </p>
                     </td>
					 <td style="border-top: none; border-bottom: 1px solid #ffffff; border-left: 1px solid #ffffff; border-right: none; padding-top: 0in; padding-bottom: 0.01in; padding-left: 0.04in; padding-right: 0in">
                        <p style="font-weight: normal" align="justify"><font color="#336699"><font face="Calibri, sans-serif"><font style="font-size: 8pt" size="1"><span style="background: #ffffff">mymail@test.com   </span></font></font></font>    </p>
                     </td>
                     <td><br></td>
                  </tr>

                  <tr valign="top" height="20">
                     <td style="border-top: none; border-bottom: 1px solid #ffffff; border-left: 1px solid #ffffff; border-right: none; padding-top: 0in; padding-bottom: 0.01in; padding-left: 0.04in; padding-right: 0in">
                        <p style="margin-left: -0.02in; font-weight: normal"><font color="#336699"><font face="Calibri, sans-serif"><font style="font-size: 8pt" size="1"><span style="background: #ffffff">City:</span></font></font></font></p>
                     </td>
                     <td style="border-top: none; border-bottom: 1px solid #ffffff; border-left: 1px solid #ffffff; border-right: none; padding-top: 0in; padding-bottom: 0.01in; padding-left: 0.04in; padding-right: 0in">
                        <p style="margin-left: -0.02in; font-weight: normal"><font color="#336699"><font face="Calibri, sans-serif"><font style="font-size: 8pt" size="1"><span style="background: #ffffff">Chennai</span></font></font></font></p>
                     </td>
                     <td style="border-top: none; border-bottom: 1px solid #ffffff; border-left: 1px solid #ffffff; border-right: none; padding-top: 0in; padding-bottom: 0.01in; padding-left: 0.04in; padding-right: 0in">
                        <p style="margin-left: -0.02in; font-weight: normal" align="justify">    <font color="#336699"><font face="Calibri, sans-serif"><font style="font-size: 8pt" size="1"><span style="background: #ffffff">State:</span></font></font></font></p>
                     </td>
                     <td style="border-top: none; border-bottom: 1px solid #ffffff; border-left: 1px solid #ffffff; border-right: none; padding-top: 0in; padding-bottom: 0.01in; padding-left: 0.04in; padding-right: 0in">
                        <p style="margin-left: -0.02in; font-weight: normal" align="justify">    <font color="#336699"><font face="Calibri, sans-serif"><font style="font-size: 8pt" size="1"><span style="background: #ffffff">Tamilnadu</span></font></font></font></p>
                     </td>
                     <td style="border-top: none; border-bottom: 1px solid #ffffff; border-left: 1px solid #ffffff; border-right: none; padding-top: 0in; padding-bottom: 0.01in; padding-left: 0.04in; padding-right: 0in">
                        <p style="font-weight: normal" align="justify"><font color="#336699"><font face="Calibri, sans-serif"><font style="font-size: 8pt" size="1"><span style="background: #ffffff">Zip    Code:</span></font></font></font></p>
                     </td>
                     <td style="border-top: none; border-bottom: 1px solid #ffffff; border-left: 1px solid #ffffff; border-right: none; padding-top: 0in; padding-bottom: 0.01in; padding-left: 0.04in; padding-right: 0in">
                        <p style="font-weight: normal" align="justify"><font color="#336699"><font face="Calibri, sans-serif"><font style="font-size: 8pt" size="1"><span style="background: #ffffff">600001</span></font></font></font></p>
                     </td>
                  </tr>

                  <tr valign="top" height="20">
                     <td style="border-top: none; border-bottom: 1px solid #ffffff; border-left: 1px solid #ffffff; border-right: none; padding-top: 0in; padding-bottom: 0.01in; padding-left: 0.04in; padding-right: 0in">
                        <p style="margin-left: -0.02in; font-weight: normal"><font color="#336699"><font face="Calibri, sans-serif"><font style="font-size: 8pt" size="1"><span style="background: #ffffff">Telephone:</span></font></font></font></p>
                     </td>
                     <td style="border-top: none; border-bottom: 1px solid #ffffff; border-left: 1px solid #ffffff; border-right: none; padding-top: 0in; padding-bottom: 0.01in; padding-left: 0.04in; padding-right: 0in">
                        <p style="margin-left: -0.02in; font-weight: normal"><font color="#336699"><font face="Calibri, sans-serif"><font style="font-size: 8pt" size="1"><span style="background: #ffffff">123123123</span></font></font></font></p>
                     </td>
                     <td style="border-top: none; border-bottom: 1px solid #ffffff; border-left: 1px solid #ffffff; border-right: none; padding-top: 0in; padding-bottom: 0.01in; padding-left: 0.04in; padding-right: 0in">
                        <p style="margin-left: -0.02in; font-weight: normal"><font color="#336699"><font face="Calibri, sans-serif"><font style="font-size: 8pt" size="1"><span style="background: #ffffff">543543345543:</span></font></font></font></p>
                     </td>
                     <td style="border-top: none; border-bottom: 1px solid #ffffff; border-left: 1px solid #ffffff; border-right: none; padding-top: 0in; padding-bottom: 0.01in; padding-left: 0.04in; padding-right: 0in">
                        <p style="margin-left: -0.02in; font-weight: normal"><font color="#336699"><font face="Calibri, sans-serif"><font style="font-size: 8pt" size="1"><span style="background: #ffffff">432432432</span></font></font></font></p>
                     </td>
                     <td style="border-top: none; border-bottom: 1px solid #ffffff; border-left: 1px solid #ffffff; border-right: none; padding-top: 0in; padding-bottom: 0.01in; padding-left: 0.04in; padding-right: 0in">
                        <p style="font-weight: normal"><font color="#336699"><font face="Calibri, sans-serif"><font style="font-size: 8pt" size="1"><span style="background: #ffffff">Source    :</span></font></font></font></p>
                     </td>
                     <td style="border-top: none; border-bottom: 1px solid #ffffff; border-left: 1px solid #ffffff; border-right: none; padding-top: 0in; padding-bottom: 0.01in; padding-left: 0.04in; padding-right: 0in">
                        <p style="font-weight: normal"><font color="#336699"><font face="Calibri, sans-serif"><font style="font-size: 8pt" size="1"><span style="background: #ffffff">News</span></font></font></font></p>
                     </td>
                  </tr>

				  <tr valign="top" height="20">
					 <td style="border-top: none; border-bottom: 1px solid #ffffff; border-left: 1px solid #ffffff; border-right: 1px solid #ffffff; padding-top: 0in; padding-bottom: 0.01in; padding-left: 0.04in; padding-right: 0.04in">
                        <p style="font-weight: normal"><font color="#336699"><font face="Calibri, sans-serif"><font style="font-size: 8pt" size="1"><span style="background: #ffffff">Job    Portals:</span></font></font></font></p>
                     </td>
					 <td style="border-top: none; border-bottom: 1px solid #ffffff; border-left: 1px solid #ffffff; border-right: 1px solid #ffffff; padding-top: 0in; padding-bottom: 0.01in; padding-left: 0.04in; padding-right: 0.04in">
                        <p style="font-weight: normal"><font color="#336699"><font face="Calibri, sans-serif"><font style="font-size: 8pt" size="1"><span style="background: #ffffff">Indeed</span></font></font></font></p>
                     </td>
                     <td style="border-top: 1px solid #ffffff; border-bottom: 1px solid #ffffff; border-left: 1px solid #ffffff; border-right: none; padding-top: 0.01in; padding-bottom: 0.01in; padding-left: 0.04in; padding-right: 0in">
                        <p><font color="#336699"><font face="Calibri, sans-serif"><font style="font-size: 8pt" size="1">Years    of IT Experience:</font></font></font></p>
                     </td>
                     <td style="border-top: 1px solid #ffffff; border-bottom: 1px solid #ffffff; border-left: 1px solid #ffffff; border-right: none; padding-top: 0.01in; padding-bottom: 0.01in; padding-left: 0.04in; padding-right: 0in">
                        <p><font color="#336699"><font face="Calibri, sans-serif"><font style="font-size: 8pt" size="1">2</font></font></font></p>
                     </td>
                     <td style="border-top: 1px solid #ffffff; border-bottom: 1px solid #ffffff; border-left: 1px solid #ffffff; border-right: none; padding-top: 0.01in; padding-bottom: 0.01in; padding-left: 0.04in; padding-right: 0in">
                        <p><font color="#336699"><font face="Calibri, sans-serif"><font style="font-size: 8pt" size="1">Work    Location :</font></font></font></p>
                     </td>
                     <td style="border-top: 1px solid #ffffff; border-bottom: 1px solid #ffffff; border-left: 1px solid #ffffff; border-right: none; padding-top: 0.01in; padding-bottom: 0.01in; padding-left: 0.04in; padding-right: 0in">
                        <p><font color="#336699"><font face="Calibri, sans-serif"><font style="font-size: 8pt" size="1">Newyork</font></font></font></p>
                     </td>
                  </tr>

				  <tr valign="top" height="20">
                     <td style="border-top: 1px solid #ffffff; border-bottom: 1px solid #ffffff; border-left: 1px solid #ffffff; border-right: none; padding-top: 0in; padding-bottom: 0in; padding-left: 0.04in; padding-right: 0in">
                        <p><font color="#336699"><font face="Calibri, sans-serif"><font style="font-size: 8pt" size="1">Validity:</font></font></font>    </p>
                     </td>
					 <td style="border-top: 1px solid #ffffff; border-bottom: 1px solid #ffffff; border-left: 1px solid #ffffff; border-right: none; padding-top: 0in; padding-bottom: 0in; padding-left: 0.04in; padding-right: 0in">
                        <p><font color="#336699"><font face="Calibri, sans-serif"><font style="font-size: 8pt" size="1">2020   </font></font></font>    </p>
                     </td>
                     <td style="border-top: 1px solid #ffffff; border-bottom: 1px solid #ffffff; border-left: 1px solid #ffffff; border-right: none; padding-top: 0in; padding-bottom: 0in; padding-left: 0.04in; padding-right: 0in">
                        <p style="margin-right: -2.23in"><font color="#336699"><font face="Calibri, sans-serif"><font style="font-size: 8pt" size="1">Age: </font></font></font>    </p>
                     </td>
					 <td style="border-top: 1px solid #ffffff; border-bottom: 1px solid #ffffff; border-left: 1px solid #ffffff; border-right: none; padding-top: 0in; padding-bottom: 0in; padding-left: 0.04in; padding-right: 0in">
                        <p style="margin-right: -2.23in"><font color="#336699"><font face="Calibri, sans-serif"><font style="font-size: 8pt" size="1"></font></font></font>    </p>
                     <br></td>
                     <td style="border-top: 1px solid #ffffff; border-bottom: 1px solid #ffffff; border-left: 1px solid #ffffff; border-right: none; padding-top: 0in; padding-bottom: 0in; padding-left: 0.04in; padding-right: 0in">
                        <p><font color="#336699"> <font face="Calibri, sans-serif"><font style="font-size: 8pt" size="1">Country:</font></font></font></p>
                     </td>
                     <td style="border-top: 1px solid #ffffff; border-bottom: 1px solid #ffffff; border-left: 1px solid #ffffff; border-right: none; padding-top: 0in; padding-bottom: 0in; padding-left: 0.04in; padding-right: 0in">
                        <p><font color="#336699"> <font face="Calibri, sans-serif"><font style="font-size: 8pt" size="1"></font></font></font></p>
                     </td>
                  </tr>
               </tbody>
            </table>

            
         </td>
      </tr>
 
   </tbody>
</table>

当我使用python将其使用 pdfkit 转换为 pdf 文件,并使用扩展名为 .docx 的直接html代码将其转换为docx文件时,即时通讯pdf等不同的布局,只有一半的页面内容,而.docx文件却具有完整的页面内容。

为什么尺寸会有所不同,以及如何在两种格式中使用相同的尺寸?

谢谢。

0 个答案:

没有答案