recipe-576832.py 文件源码

python
阅读 27 收藏 0 点赞 0 评论 0

项目:code 作者: ActiveState 项目源码 文件源码
def main():
    import sys
    import urllib2
    from cStringIO import StringIO
    from reportlab.platypus import SimpleDocTemplate, Image, Paragraph, PageBreak
    from reportlab.lib.styles import ParagraphStyle, getSampleStyleSheet

    #This is needed because ReportLab accepts the StringIO as a file-like object,
    #but doesn't accept urllib2.urlopen's return value
    def get_image(url):
        u = urllib2.urlopen(url)
        return StringIO(u.read())

    styles = getSampleStyleSheet()
    styleN = ParagraphStyle(styles['Normal'])

    # build doc

    if len(sys.argv) > 1:
        fn = sys.argv[1]
    else:
        fn = "filename.pdf"
    doc = SimpleDocTemplate(open(fn, "wb"))
    elements = [
        Paragraph("Hello,", styleN),
        Image(get_image("http://www.red-dove.com/images/rdclogo.gif")),
        PageBreak(),
        Paragraph("world!", styleN),
        Image(get_image("http://www.python.org/images/python-logo.gif")),
    ]
    doc.build(elements, canvasmaker=NumberedCanvas)
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号