【问题标题】:reportlab save location报告实验室保存位置
【发布时间】:2013-01-24 13:18:33
【问题描述】:

我正在尝试将 reportlab 生成的 PDF 文件保存到特定位置。可能吗?代码将pdf创建到自己的目录中。

def myFirstPage(canvas, doc):
    canvas.saveState()
    canvas.setFont('Times-Bold',16)
    canvas.drawCentredString(PAGE_WIDTH/2.0, PAGE_HEIGHT-108, Title)
    canvas.setFont('Times-Roman',9)
    canvas.restoreState()

def create_pdf(sometext):
    doc = SimpleDocTemplate("myfile.pdf")
    Story = [Spacer(1,2*inch)]
    style = styles["Normal"]
    bogustext = ("There is something: %s. " % sometext)
    p = Paragraph(bogustext, style)
    Story.append(p)
    Story.append(Spacer(1,0.2*inch))
    doc.build(Story, onFirstPage=myFirstPage)

【问题讨论】:

    标签: python location save reportlab


    【解决方案1】:

    是的,这是可能的。我建议使用os.path.join 来构建路径。示例:

    import os
    
    def create_pdf(sometext):
        outfilename = "myfile.pdf"
        outfiledir = '/somedir'
        outfilepath = os.path.join( outfiledir, outfilename )
        doc = SimpleDocTemplate( outfilepath )
        # ...
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-10-05
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多