Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # -*- coding: utf-8 -*-
- import os
- import sys
- import reportlab
- from reportlab.pdfgen import canvas
- from reportlab.platypus import Paragraph
- from reportlab.lib.styles import getSampleStyleSheet
- from reportlab.lib.units import mm
- from reportlab.pdfbase.ttfonts import TTFont
- from reportlab.lib.fonts import addMapping
- import copy
- text="""Brake Piston Readjusting Set
- * For readjusting (pushing or turning) brake pistons on floating caliper systems with or without locking device for hand brakes.
- * Thrust bearing avoids damaging of the dust boot.
- * With additional outside hexagon s 13 mm for flexible application of operating tools, e.g. reversible ratchets.
- * Universal application - suitable for all common vehicle types.
- <table>
- <tr><td></td><td>d(mm)</td><td>PINS d<sub>1</sub>(mm)</td></tr>
- <tr><td>#7600-1</td><td></td><td>Basic device</td></tr>
- <tr><td>#7600-2</td><td>30</td><td>5</td><td>Adapter with 4 pins HONDA/SAAB</td></tr>
- <tr><td>#7600-3</td><td>30</td><td>6</td><td>Adapter VW-AUDI, inside hexagon 12 mm</td></tr>
- <tr><td>#7600-4</td><td>32</td><td>6</td><td>Adapter with 2 points FORD Focus, SMART for four OPEL Zafira, Astra, Astra G, Corsa GSI</td></tr>
- <tr><td>#7600-5</td><td>35</td><td>5</td><td>Adapter with 2 pins AUDI 80 B4</td></tr>
- <tr><td>#7600-6</td><td>55</td><td>5</td><td>Adapter with 2 pins VW-AUDI</td></tr>
- </table>"""
- def findFont(fontFile):
- for path in ["/usr/share/fonts/truetype/droid", "/usr/local/lib/X11/fonts/Droid/"]:
- fpath=os.path.join(path, fontFile)
- if os.path.exists(fpath):
- return fpath
- else:
- print "Cannot find DroidSansFallbackFull.ttf"
- sys.exit(1)
- nf = findFont("DroidSansFallbackFull.ttf")
- bf = findFont("DroidSans-Bold.ttf")
- reportlab.pdfbase.pdfmetrics.registerFont(TTFont("droid", nf))
- reportlab.pdfbase.pdfmetrics.registerFont(TTFont("droid-bold", bf))
- addMapping('droid', 0, 0, 'droid') #normal
- addMapping('droid', 1, 0, 'droid-bold') #bold
- padding = 3*mm
- styles=getSampleStyleSheet()
- descStyle = copy.copy(styles["Normal"])
- descStyle.autoLeading = 'max'
- descStyle.fontName = 'droid'
- descStyle.fontSize = 10
- descStyle.leading = descStyle.fontSize*1.2
- width = 100*mm
- height = 180*mm
- rect = (5*mm, 5*mm, width, height)
- c=canvas.Canvas("table.pdf")
- c.rect(rect[0], -rect[1]+297*mm-rect[3], rect[2], rect[3])
- p = Paragraph(text.replace("\n", "<br />"), descStyle)
- p.wrap(width-padding*2, height-padding*2)
- p.drawOn(c, rect[0]+padding, -rect[1]+297*mm-p.height-padding)
- c.showPage()
- c.save()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement