#coding=utf-8
#from reportlab.lib import *
from reportlab.platypus import *
from reportlab.lib.styles import *
from reportlab.rl_config import *
from reportlab.lib.units import *
from reportlab.lib.pagesizes import *
from reportlab.pdfbase import *
from reportlab.lib import *
#from reportlab.pdfgen import *
from reportlab.graphics.barcode.code39 import *
'''def gather_pdftext (node, depth, in_line_block=False,replaceEnt=True):
for n in node.children:
print n
#return ''.join([for n in node.children ])
class MyParagraph(Paragraph):
def wrap(self, availWidth, availHeight):
self.width = availWidth
leftIndent = self.style.leftIndent
first_line_width = availWidth - (leftIndent+self.style.firstLineIndent) - self.style.rightIndent
later_widths = availWidth - leftIndent - self.style.rightIndent
try:
self.blPara = self.breakLinesCJK([first_line_width, later_widths])
except:
self.blPara = self.breakLines([first_line_width, later_widths])
self.height = len(self.blPara.lines) * self.style.leading
return (self.width,self.height)'''
#Paragraph.wrap = wrap
def init_header_config():
from reportlab.pdfbase.ttfonts import TTFont
import copy
warnOnMissingFontGlyphs = 0
pdfmetrics.registerFont(TTFont('zhenhei','D:/python_workspace/python_pdf_demo/wqy-zenhei.ttc'))
stylesheet= getSampleStyleSheet()
styles= copy.deepcopy(stylesheet['Normal'])
styles.fontName ='zhenhei'
styles.fontSize = 20
return styles
def init_body_font(stylesheet):
import copy
styles= copy.deepcopy(stylesheet['BodyText'])
styles.fontName ='zhenhei'
styles.fontSize = 10
return styles
#首页定义信息
def firstPage(canvas,doc):
TITLE=u"订单打印明细"
canvas.saveState()
canvas.setFont('zhenhei',16)
canvas.drawCentredString(doc.pagesize[0]/2-30,doc.pagesize[1]-40,TITLE)
canvas.setFont('zhenhei',9)
canvas.drawString((doc.pagesize[0]/2)-20,20,u"首页")
# barcode=code39.Extended39("123456789",barWidth=0.5*mm,barHeight=20*mm)
# barcode.drawOn(canvas,100*mm,100*mm)
canvas.restoreState()
#翻页时每页面定义信息
def laterPages(canvas,doc):
TITLE=u"订单打印明细"
canvas.saveState()
canvas.setFont('zhenhei',16)
canvas.drawCentredString(doc.pagesize[0]/2-30,doc.pagesize[1]-40,TITLE)
canvas.setFont('zhenhei', 9)
canvas.drawString((doc.pagesize[0]/2)-20,20,u"页码:%d" % (doc.page))
canvas.restoreState()
def init_data(table_style):
import MySQLdb
hosts=&
python reportlab 相对较为可用的正式报表
最新推荐文章于 2024-05-22 15:42:31 发布