Advertisement
Guest User

Untitled

a guest
Nov 7th, 2015
45
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 2.48 KB | None | 0 0
  1. # -*- coding: utf-8 -*-
  2. import os
  3. import sys
  4. import reportlab
  5. from reportlab.pdfgen import canvas
  6. from reportlab.platypus import Paragraph
  7. from reportlab.lib.styles import getSampleStyleSheet
  8. from reportlab.lib.units import mm
  9. from reportlab.pdfbase.ttfonts import TTFont
  10. from reportlab.lib.fonts import addMapping
  11. import copy
  12.  
  13. text="""Brake Piston Readjusting Set
  14. * For readjusting (pushing or turning) brake pistons on floating caliper systems with or without locking device for hand brakes.
  15. * Thrust bearing avoids damaging of the dust boot.
  16. * With additional outside hexagon s 13 mm for flexible application of operating tools, e.g. reversible ratchets.
  17. * Universal application - suitable for all common vehicle types.
  18.  
  19. <table>
  20. <tr><td></td><td>d(mm)</td><td>PINS d<sub>1</sub>(mm)</td></tr>
  21. <tr><td>#7600-1</td><td></td><td>Basic device</td></tr>
  22. <tr><td>#7600-2</td><td>30</td><td>5</td><td>Adapter with 4 pins HONDA/SAAB</td></tr>
  23. <tr><td>#7600-3</td><td>30</td><td>6</td><td>Adapter VW-AUDI, inside hexagon 12 mm</td></tr>
  24. <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>
  25. <tr><td>#7600-5</td><td>35</td><td>5</td><td>Adapter with 2 pins AUDI 80 B4</td></tr>
  26. <tr><td>#7600-6</td><td>55</td><td>5</td><td>Adapter with 2 pins VW-AUDI</td></tr>
  27. </table>"""
  28.  
  29. def findFont(fontFile):
  30.     for path in ["/usr/share/fonts/truetype/droid", "/usr/local/lib/X11/fonts/Droid/"]:
  31.         fpath=os.path.join(path, fontFile)
  32.         if os.path.exists(fpath):
  33.             return fpath
  34.     else:
  35.         print "Cannot find DroidSansFallbackFull.ttf"
  36.         sys.exit(1)
  37.  
  38. nf = findFont("DroidSansFallbackFull.ttf")
  39. bf = findFont("DroidSans-Bold.ttf")
  40. reportlab.pdfbase.pdfmetrics.registerFont(TTFont("droid", nf))
  41. reportlab.pdfbase.pdfmetrics.registerFont(TTFont("droid-bold", bf))
  42. addMapping('droid', 0, 0, 'droid')    #normal
  43. addMapping('droid', 1, 0, 'droid-bold')    #bold
  44.  
  45. padding = 3*mm
  46.  
  47. styles=getSampleStyleSheet()
  48.  
  49. descStyle = copy.copy(styles["Normal"])
  50. descStyle.autoLeading = 'max'
  51. descStyle.fontName = 'droid'
  52. descStyle.fontSize = 10
  53. descStyle.leading = descStyle.fontSize*1.2
  54.  
  55. width = 100*mm
  56. height = 180*mm
  57. rect = (5*mm, 5*mm, width, height)
  58.  
  59. c=canvas.Canvas("table.pdf")
  60. c.rect(rect[0], -rect[1]+297*mm-rect[3], rect[2], rect[3])
  61.  
  62. p = Paragraph(text.replace("\n", "<br />"), descStyle)
  63. p.wrap(width-padding*2, height-padding*2)
  64. p.drawOn(c, rect[0]+padding, -rect[1]+297*mm-p.height-padding)
  65.  
  66. c.showPage()
  67.  
  68. c.save()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement