Prerequisites:
Install xhtml2pdf https://pypi.python.org/pypi/xhtml2pdf/
Download Font:; give a address: http://www.jb51.net/fonts/8481.html
File to be converted: 1.htm
CopyCode The Code is as follows: <meta charset = "utf8"/>
<Style type = 'text/CSS '>
@ Font-face {
Font-family: "code2000 ";
SRC: URL ("code2000.ttf ")
}
HTML {
Font-family: code2000;
}
</Style>
<HTML>
<Body> <Table>
<Tr>
<TD> text </TD>
<TD> 123 </TD>
</Tr>
<Tr>
<TD> image </TD>
<TD> </TD>
</Tr>
</Table> </body>
Html_to_assist.pyProgram
Copy code The Code is as follows: #-*-coding: UTF-8 -*-
Import Sx. pisa3 as Pisa
Data = open('1.htm'). Read ()
Result = file('test10000', 'wb ')
PDF = Pisa. createpdf (data, result)
Result. Close ()
Pisa.startviewer('test ')
Note: xhtml2pdf cannot recognize Chinese characters. You must use CSS to embed the code2000 font in the HTML file. It seems that you can only use code2000 for unknown reasons.