标签: reportlab

11
推荐指数
2
解决办法
3102
查看次数

添加在ReportLab中使用的字体

我正在尝试在python ReportLab中添加一个字体,以便我可以将它用于函数.该函数使用canvas.Canvas在PDF中绘制一堆文本,没什么复杂的,但我需要为布局问题添加固定宽度的字体.

当我尝试使用我能找到的小信息来注册字体时,这似乎有效.但是当我试图从我的Canvas对象中调用.addFont('fontname')时,我一直在努力

"PDFDocument实例没有属性'addFont'"

该功能是否未实施?如何访问除.getAvailableFonts中列出的10个左右的默认字体以外的字体?谢谢.

我正在尝试制作的一些示例代码:

from reportlab.pdfgen import canvas
c = canvas.Canvas('label.pdf')
c.addFont('TestFont') #This throws the error listed above, regardless of what argument I use (whether it refers to a font or not).
c.drawString(1,1,'test data here')
c.showPage()
c.save()
Run Code Online (Sandbox Code Playgroud)

要注册字体,我试过了

from reportlab.lib.fonts import addMapping
from reportlab.pdfbase import pdfmetrics

pdfmetrics.registerFont(TTFont('TestFont', 'ghettomarquee.ttf'))
addMapping('TestFont', 0, 0, 'TestFont')
Run Code Online (Sandbox Code Playgroud)

其中'ghettomarquee.ttf'只是一个随意的字体.

python fonts reportlab

11
推荐指数
1
解决办法
6176
查看次数

使用ReportLab(Python)的PDF文档中的PDF图像

我将matplotlib中的一些图表保存为pdf格式,因为它似乎提供了更好的质量.如何使用ReportLab将PDF图像包含到PDF文档中?便捷方法Image(filepath)不适用于此格式.

谢谢.

python pdf image reportlab

11
推荐指数
1
解决办法
4645
查看次数

我们可以使用reportlab创建交互式PDF表单吗?

我们可以使用reportlab创建交互式PDF表单吗?也就是说,一种从读取器获取数据并将其保存到数据库中的表单.

python pdf django reportlab

11
推荐指数
1
解决办法
2693
查看次数

如何在reportlab中对对象进行分组,以便它们在新页面中保持在一起

我正在使用reportlab生成一些pdf文件.我有一个重复的部分.它包含一个标题和一个表:

            Story.append(Paragraph(header_string, styleH))
            Story.append(table) 
Run Code Online (Sandbox Code Playgroud)

如何将段落与表格分组(在乳胶中我会将它们放入相同的环境中),以便在页面制动的情况下,段落和表格保持在一起?目前,段落有时会浮动在一页的末尾,表格从下一页开始.

python reportlab

11
推荐指数
3
解决办法
4258
查看次数

呈现从SimpleDocTemplate构建的ReportLab pdf

我有一个django应用程序,目前使用用户可以下载的画布生成pdfs.我创建一个StringIO缓冲区,做一些东西,然后发送调用response.write.

# Set up response
response = HttpResponse(mimetype='application/pdf')
response['Content-Disposition'] = 'attachment; filename=menu-%s.pdf' % str(menu_id)
# buffer
buff = StringIO()

# Create the pdf object
p = canvas.Canvas(buff)

# Add some elements... then

p.showPage()
p.save()

# Get the pdf from the buffer and return the response
pdf = buff.getvalue()
buff.close()
response.write(pdf)
Run Code Online (Sandbox Code Playgroud)

我现在想用platypus和SimpleDocTemplate构建我的pdf并编写了这个

# Set up response
response = HttpResponse(mimetype='application/pdf')
pdf_name = "menu-%s.pdf" % str(menu_id)
response['Content-Disposition'] = 'attachment; filename=%s' % pdf_name

menu_pdf = SimpleDocTemplate(pdf_name, rightMargin=72,
                            leftMargin=72, topMargin=72, bottomMargin=18)

# container for pdf …
Run Code Online (Sandbox Code Playgroud)

pdf django reportlab

11
推荐指数
2
解决办法
7930
查看次数

使用Python中的Reportlab的图像宽高比

我想在一个框架内插入一个图像.我发现了两种方法:

  1. drawImage(self,image,x,y,width = None,height = None,mask = None,preserveAspectRatio = False,anchor ='c')
  2. 图像(文件名,宽度=无,高度=无)

我的问题是:如何在保留其宽高比的同时在帧中添加图像?

from reportlab.lib.units import cm
from reportlab.pdfgen.canvas import Canvas
from reportlab.platypus import Frame, Image

c = Canvas('mydoc.pdf')
frame = Frame(1*cm, 1*cm, 19*cm, 10*cm, showBoundary=1)

"""
If I have a rectangular image, I will get a square image (aspect ration 
will change to 8x8 cm). The advantage here is that I use coordinates relative
to the frame.
"""
story = []
story.append(Image('myimage.png', width=8*cm, height=8*cm))
frame.addFromList(story, c)

"""
Aspect ration …
Run Code Online (Sandbox Code Playgroud)

python pdf image reportlab

11
推荐指数
2
解决办法
2万
查看次数

如何在reportlab,python中创建具有不同页面大小的PDF文档

是否可以在reportlab中创建具有不同页面大小的PDF文档?

我想创建一个文档,其中第一页的大小与其他页面的大小不同.有人可以帮忙吗?

python pdf reportlab

11
推荐指数
1
解决办法
8690
查看次数

使用reportlab生成的pdf提供选项卡标题

这个问题很简单,但我找不到任何数据.当我使用reportlab生成pdf,将httpresponse作为文件传递时,配置为显示文件的浏览器会正确显示pdf.但是,选项卡的标题仍为"(匿名)127.0.0.1/whatnot",这对用户来说有点难看.

由于大多数网站能够以某种方式显示适当的标题,我认为这是可行的...是否有某种标题参数,我可以传递给PDF?或者响应的一些标题?这是我的代码:

def render_pdf_report(self, context, file_name):
    response = HttpResponse(content_type='application/pdf')
    response['Content-Disposition'] = 'filename="{}"'.format(file_name)

    document = BaseDocTemplate(response, **self.get_create_document_kwargs())
    #  pdf generation code
    document.build(story)
    return response
Run Code Online (Sandbox Code Playgroud)

python django pdf-generation reportlab httpresponse

11
推荐指数
3
解决办法
4247
查看次数

安装:Reportlab:"ImportError:没有名为reportlab.lib的模块"

我安装了reportlab,via

pip install reportlab
Run Code Online (Sandbox Code Playgroud)

(也尝试通过

easy_install reportlab
Run Code Online (Sandbox Code Playgroud)

)

..但是我得到了上面的错误.之前还有其他RL导入 - 它是它所反对的.lib.我曾经让RL工作得很好,但是IT重新构建了我的计算机,我正在尝试重建它.脚本工作正常,但我认为RL安装有点时髦.

Reportlab:3.3.0

python installation pip reportlab

11
推荐指数
1
解决办法
2万
查看次数