reportlab无法将实际打印页中的上边距设置为零

2024-09-30 05:30:21 发布

您现在位置:Python中文网/ 问答频道 /正文

我使用ReportLab3.0生成付款表单,其中每个项目的位置都是严格定义的。即使我将topMargin设置为0,reportlab仍然存在强制topMargin的问题。我可以调整下边距,但上边距(或我不能打印的区域)大约是12毫米,如果在代码中设置为零。如果我把上边距设为负数,文本就会开始消失。我想知道,我错过了什么。我本可以张贴的图像,但被张贴了几个帖子,我不能这样做。我在使用SimpleDocTemplate时遇到了这个问题,仅仅使用canvas或从BaseDocTemplate生成文档。我最近尝试更正上页边距:

from reportlab.lib.pagesizes import A4
from reportlab.platypus import BaseDocTemplate,PageTemplate, Frame
doc = BaseDocTemplate("pdf_file",showBoundary=1,leftMargin=0, rightMargin=0, topMargin=0, bottomMargin=0, pagesize=A4)
frameT = Frame(self.doc.leftMargin, self.doc.bottomMargin, self.doc.width, self.doc.height,    topPadding=0, id='normal')
time = Paragraph('16:37',self.styles["normal"])
doc.build([time]) 

这件事变得有趣,因为我可以将底部边距设置为零并打印到边框,但在顶部有不可打印的区域,这确实会带来麻烦

更新: 在对几个打印机进行测试后,我注意到打印机驱动程序会根据自己的标准强制执行页边距。例如,对于HP deskjet,顶部有很大的利润空间。使用播放比例设置,可以调整一些边距,但不太好。在


Tags: fromimportself区域doctimeframea4
1条回答
网友
1楼 · 发布于 2024-09-30 05:30:21

也许是打印驱动程序…我有一份报告,我把我的上页边距从0.4英寸改为0.0英寸,它正好排在最上面。在

from reportlab.platypus import SimpleDocTemplate, Paragraph, Spacer, Table, TableStyle, Preformatted, XPreformatted
from reportlab.rl_config import defaultPageSize
from reportlab.lib.units import inch

PAGE_HEIGHT = defaultPageSize[1]; PAGE_WIDTH = defaultPageSize[0]
BottomMargin = 0.4 * inch
TopMargin = 0.4 * inch
LeftMargin = .1 * inch  
RightMargin = .1 * inch
ContentBottomMargin = TopMargin + 0.25 * inch
ContentTopMargin = BottomMargin + 0.35 * inch
ContentLeftMargin = LeftMargin 
ContentRightMargin = RightMargin 

正如你所看到的,这些是我的常规默认值,但是我改变了TopMargin=0.0*inch,它起作用了。在

也许这就是我导入defaultPageSize[1]作为页面高度和您导入A4页面大小的区别?在

相关问题 更多 >

    热门问题