我需要使用Python为现有PDF添加一些额外的文本,这是最好的方法,我需要安装哪些额外的模块.
注意:理想情况下,我希望能够在Windows和Linux上运行它,但只有推动Linux才能实现.
我想将matplotlib图表直接嵌入到由ReportLab生成的PDF中 - 即不首先保存为PNG,然后将PNG嵌入到PDF中(我想我会得到更好的输出质量).
有谁知道是否有一个matplotlib可流动的ReportLab?
谢谢
我将matplotlib中的一些图表保存为pdf格式,因为它似乎提供了更好的质量.如何使用ReportLab将PDF图像包含到PDF文档中?便捷方法Image(filepath)不适用于此格式.
谢谢.
我正在使用reportlab在django视图中编写pdf,它们非常简单,标题,内容和页脚.
我正在使用非常适合的SimpleDocTemplate,在内容中绘制表格,页脚和标题是drwan使用:
build([data], onFirstPage=drawPageFrame, onLaterPages=drawPageFrame).
Run Code Online (Sandbox Code Playgroud)
我的问题是,如何使用Canvas.drawImage(...)绘制图像?我需要一个"浮动"图像...位于我想要的文本上,而使用SimpleDocTemplate我没有Canvas对象来执行此操作.
搜索我发现了这个:
鸭嘴兽布局的东西使用flowables.当包装,拆分或绘制时,包装工通常将属性canv设置到每个flowable上,即围绕wrap,split和draw方法.在这些方法中,您可以使用self的canv属性访问画布.
怎么用这个?
嗯,更多要测试的东西:
flowables.Macro
flowables.CallerMacro
Run Code Online (Sandbox Code Playgroud)
# -*- coding: utf-8 -*-
from reportlab.lib.pagesizes import A4, landscape, portrait
from reportlab.lib.styles import getSampleStyleSheet
from reportlab.platypus import Table, Flowable, SimpleDocTemplate, Paragraph, Spacer, Image
from reportlab.lib import randomtext
from reportlab import platypus
import os,random
styles = getSampleStyleSheet()
path = os.path.realpath(os.path.dirname(__file__))
def drawPageFrame(canvas, doc):
canvas.saveState()
canvas.drawImage(path+"/ujiPDF.jpg",50,50,57,57)
canvas.restoreState()
doc = SimpleDocTemplate("salida.pdf",pagesize=A4)
elementos = []
com = 'canvas.drawImage("'+path+'/ujiPDF.jpg",100,100,57,57)'
print com
elementos.append(platypus.flowables.Macro('canvas.saveState()'))
print platypus.flowables.Macro(com)
elementos.append(platypus.flowables.Macro(com))
elementos.append(platypus.flowables.Macro('canvas.restoreState()'))
para = Paragraph(randomtext.randomText(randomtext.PYTHON,20), styles["Normal"])
elementos.append(para)
doc.build(elementos,onFirstPage=drawPageFrame, … 我使用PdfPagesfrom matplotlib,可以遍历每个图形对象,并将每个对象另存为同一PDF中的单独页面:
from matplotlib.backends.backend_pdf import PdfPages
pp = PdfPages('output.pdf')
for fig in figs:
pp.savefig(fig)
pp.close()
Run Code Online (Sandbox Code Playgroud)
这很好。但是,是否可以为PDF中的每一页添加页码?
谢谢。