2014-11-05 79 views
0

我正在使用reportlab 3.0生成付款表單,其中每個項目的位置都嚴格定義。即使設置了topMargin = 0,我仍然在使用reportlab製作強制性topMargin時遇到問題。如果將代碼設置爲零,則可調整底部邊距,但頂部邊距(或無法打印的區域)大約爲12毫米。如果我將頂部邊距設置爲負值,文本開始消失。我想知道,我錯過了什麼。我會張貼圖片,但被張貼幾個帖子,我無法做到這一點。我在使用SimpleDocTemplate時遇到了這個問題,只是使用畫布或從BaseDocTemplate製作文檔。我的最新嘗試,以使上邊距正確:reportlab - 無法在物理打印頁面中將頂部邊距設置爲零

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]) 

事情變得有趣,因爲我能下邊距設置爲零,並打印到邊境,但在頂部有是真正造成不可打印區域麻煩

更新: 有幾臺打印機的測試之後,我注意到根據自身條件的打印機驅動力的利潤。例如,對於惠普Deskjet來說,它的利潤率很高。通過播放比例設置,可以調整一些邊緣,但不太好。

回答

0

也許是打印驅動程序...我有一個報告,我將我的TopMargin從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 *英寸,它的工作。

也許這是我爲PAGE_HEIGHT導入defaultPageSize [1]和爲頁面大小導入A4之間的區別?

+0

我一直在測試這個,因爲我有這個想法,而且似乎您對打印機驅動程序的假設是正確的。從Mac驅動程序打印PDF格式的HP噴墨打印結果有一個很大的上限,而從Windows 7打印結果的預期餘量。 – user2576168 2014-11-26 15:56:37