Advertisement
toodahlou

drawImage ReportLab Help

Jun 10th, 2025
29
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.31 KB | Help | 0 0
  1. from reportlab.lib.pagesizes import (ELEVENSEVENTEEN,
  2.                                      landscape)
  3. from reportlab.pdfgen import canvas
  4. from reportlab.lib.units import inch
  5. from reportlab.lib.utils import ImageReader
  6.  
  7. DWGSize = landscape(ELEVENSEVENTEEN)
  8. dwg = canvas.Canvas(filename='TestDWG.pdf',
  9.                     pagesize=DWGSize)
  10. width, height = DWGSize  # for ref later
  11.  
  12. Margin = 0.3125*inch
  13. DblMargin = Margin*2
  14.  
  15. dwg.rect(x=Margin,  # Title block outside border
  16.          y=Margin,
  17.          width=width-DblMargin,
  18.          height=height-DblMargin,
  19.          fill=0)
  20. dwg.line(x1=Margin,  # line below logo in title block
  21.          y1=3.875*inch,
  22.          x2=1.5*inch,
  23.          y2=3.875*inch)
  24. dwg.line(x1=Margin,  # line above logo in title block
  25.          y1=6.875*inch,
  26.          x2=1.5*inch,
  27.          y2=6.875*inch)
  28. dwg.line(x1=1.5*inch,  # line seperating title block from rest of drawing
  29.          y1=Margin,
  30.          x2=1.5*inch,
  31.          y2=height-Margin)
  32.  
  33. LOGO_PATH = 'C:/Users/libbyl/PythonProjects/DrawingWithReportLab/Bergkamp register R logo RGB black.jpeg'
  34. BlkLogo = ImageReader(LOGO_PATH)
  35.  
  36. dwg.rotate(90)
  37. dwg.drawImage(BlkLogo,  # put logo in middle box of title block
  38.               x=0.3125*inch,
  39.               y=3.875*inch,
  40.               mask='auto')
  41.  
  42. dwg.showPage()
  43. dwg.save()
  44.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement