python reportlab 相对较为可用的正式报表

#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=&

  • 1
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
ReportLab is an open-source Python library used for creating PDF documents. It allows for the creation of complex and dynamic PDF documents with the help of various features such as graphics, images, tables, and charts. ReportLab can be used to create a wide range of PDF documents, including invoices, reports, brochures, and more. ReportLab is built on the PDF format, which is a widely used format for documents that require consistent formatting across different devices and platforms. The library provides a high level of control over the layout and design of the PDF document, allowing developers to create professional-looking documents with ease. Some of the key features of ReportLab include: 1. Text flow - ReportLab allows for the automatic flow of text across multiple pages, making it easy to create long documents. 2. Graphics - The library provides various tools for creating charts, graphs, and other types of visualizations. 3. Templates - ReportLab allows for the creation and use of templates, making it easy to create consistent designs across multiple documents. 4. Encryption - The library supports various encryption methods to ensure the security of the PDF document. ReportLab is widely used in industries such as finance, healthcare, and legal services for creating documents such as invoices, medical reports, and legal documents. It is also used in e-commerce for creating product catalogs and brochures. ReportLab is available under the BSD license and can be installed using pip, the Python package installer. The library is well-documented, with numerous examples and tutorials available online.

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值