Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>The description text went up as you wrap it in a styles["Normal"] You can try to wrap your text in a styles["BodyText"] This will allow your text to align themselves according to the width of the cell you specify. You could also include formatting which is similar to HTML text formatting.</p> <p>Then use TableStyle to format the content in the table, for example, color text, center paragraph, span rows/columns and so on.</p> <p>I edited the code above to a working version (example):</p> <pre><code>from reportlab.pdfgen import canvas from reportlab.lib.pagesizes import A4, cm from reportlab.lib.styles import getSampleStyleSheet from reportlab.platypus import Paragraph, Table, TableStyle from reportlab.lib.enums import TA_JUSTIFY, TA_LEFT, TA_CENTER from reportlab.lib import colors width, height = A4 styles = getSampleStyleSheet() styleN = styles["BodyText"] styleN.alignment = TA_LEFT styleBH = styles["Normal"] styleBH.alignment = TA_CENTER def coord(x, y, unit=1): x, y = x * unit, height - y * unit return x, y # Headers hdescrpcion = Paragraph('''&lt;b&gt;descrpcion&lt;/b&gt;''', styleBH) hpartida = Paragraph('''&lt;b&gt;partida&lt;/b&gt;''', styleBH) hcandidad = Paragraph('''&lt;b&gt;candidad&lt;/b&gt;''', styleBH) hprecio_unitario = Paragraph('''&lt;b&gt;precio_unitario&lt;/b&gt;''', styleBH) hprecio_total = Paragraph('''&lt;b&gt;precio_total&lt;/b&gt;''', styleBH) # Texts descrpcion = Paragraph('long paragraph', styleN) partida = Paragraph('1', styleN) candidad = Paragraph('120', styleN) precio_unitario = Paragraph('$52.00', styleN) precio_total = Paragraph('$6240.00', styleN) data= [[hdescrpcion, hcandidad,hcandidad, hprecio_unitario, hprecio_total], [partida, candidad, descrpcion, precio_unitario, precio_total]] table = Table(data, colWidths=[2.05 * cm, 2.7 * cm, 5 * cm, 3* cm, 3 * cm]) table.setStyle(TableStyle([ ('INNERGRID', (0,0), (-1,-1), 0.25, colors.black), ('BOX', (0,0), (-1,-1), 0.25, colors.black), ])) c = canvas.Canvas("a.pdf", pagesize=A4) table.wrapOn(c, width, height) table.drawOn(c, *coord(1.8, 9.6, cm)) c.save() </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload