2011-05-26 16 views
5

ReportLab的形象是走出上的PDF畫布鏡像用下面的代碼片段:ReportLab的圖像繪製」關於canvas.Canvas

from reportlab.pdfgen import canvas 
from reportlab.platypus import Image 

pdf = canvas.Canvas(filename, bottomup=0) 

logo_image = Image(
    "%s/images/wsp_logo.jpg" % settings.STATIC_ROOT, 
    width=200, 
    height=200) 
logo_image.drawOn(pdf, 100, 100) 

如何擁有它繪製‘正常的’,如一個希望看到它

回答

3

我不能在此刻測試,但它在你的Canvas對象的創建是可能是因爲bottomup = 0默認爲1documentation:。

自底向上參數切換座標系。一些圖形系統(如PDF和PostScript)將頁面左下方的(0,0)放置在其他頁面(如許多圖形用戶界面[GUI]),將origen放在左上角。在自下而上的說法已過時,並且可能會在未來

需要被丟棄,看它是否真的適用於所有的任務,如果沒有的話擺脫它

鑑於該報價的警告,我的猜測是將其設置爲0是問題的根源。

+0

你是對的,這是因爲自下而上設置爲0. – sepulchered 2012-11-10 13:07:43

+2

關於如何解決這個問題,同時保持'bottomtop'設置爲0的任何想法? – Voles 2013-03-13 13:32:17

4

使用canvas.scale函數來翻轉圖像。

canvas.saveState() 
canvas.translate(x, y) 
canvas.scale(1,-1) 
canvas.drawImage(img_path, 0, 0, width=-width, height=-height, mask='auto') 
canvas.restoreState() 
0

用左下角的原點(0,0)繪製圖片。

canvas.saveState() 
canvas.transform(1, 0, 0, -1, 0, H) 
draw_your_picture_code() 
canvas.restoreState() 

H是頁面高度。