Skip to content

Fail to generate table from csv-table #1239

Description

@FlorentP42

Description of problem

When attempting to produce a pdf using the following Python code :

from rst2pdf.createpdf import RstToPdf

file_rst="input.rst"
file_style="style.json"
pdf_file_path="output.pdf"
# Generate pdf
with open(file_rst) as inrst:
    RstToPdf( breaklevel=0, breakside=0,
                stylesheets=[file_style]
            ).createPdf(
                text=inrst.read(),
                output=pdf_file_path
            )

with input.rst

.. csv-table::
  :delim: §
  :class: longtable
  :header: "Header1", "Header2", "Header3"
  :widths: 46, 46, 8

   Some text here (some precision - some other info) §  § :style_ok:`Success`
   Some text here (some precision - some other info) §  § :style_ok:`Success`
   Some text here (some precision - some other info) §  § :style_ok:`Success`
   Some text here (some precision - some other info) §  § :style_ok:`Success`
   Some text here (some precision - some other info) §  § :style_ok:`Success`

and style.json

{
  "pageSetup" : {
    "firstTemplate": "coverPage",
    "frames": [
        ["0%", "0%", "100%", "100%"]
      ],
    "showHeader" : false,
    "showFooter" : false
  },
  "pageTemplates" : {
    "coverPage": {
        "frames": [
            ["0%", "0%", "100%", "100%"]
          ],
        "showHeader" : false,
        "showFooter" : false
    }
  },  
  "styles" : [
    ["titre", {
      "fontSize": 30,
      "alignment": "center",
      "spaceBefore": 10,
      "spaceAfter": 15
    }],
    ["projet", {
      "fontSize": 20,
      "alignment": "center",
      "spaceBefore": 10,
      "spaceAfter": 5
    }],
    ["field-list", {
      "colWidths": ["5cm", null] 
    }],
    ["base", {
      "bulletText": "",      
      "fontSize": 8,
      "spaceBefore": 5,
      "spaceAfter": 5
    }],
    ["list-itttem", {
      "bulletText": "\u2751"
    }],
    ["bullet-item", {
      "bulletText": "\u2751"
    }],
    ["bullet-list-item", {
      "bulletText": "\u2751"
    }],
    [ "table-heading", {
        "valign": "MIDDLE"
    }],
    ["non-couvert", {
      "textColor": "red"
    }],
    ["style-ko", {
      "textColor": "red"
    }],
    ["style-sk", {
      "textColor": "orange"
    }],
    ["style-ok", {
      "textColor": "green"
    }]
  ]
}

What is the expected output? What do you see instead?

This was working with no error and producing a table as expected in the pdf with the following environment :

  • Python 3.6.8
  • rst2pdf 0.99
  • reportlab 3.6.8
  • OS: Red Hat Enterprise Linux release 8.6 (Ootpa)

With the environment described below, it no longer generates a table and raises the following error :

path/to/input.rst:1: (ERROR/3) Error with CSV data in "csv-table" directive:
'§' expected after '"'

.. csv-table::
  :delim: §
  :class: longtable
  :header: "Header1", "Header2", "Header3"
  :widths: 46, 46, 8

   Some text here (some precision - some other info) §  § :style_ok:`Success`
   Some text here (some precision - some other info) §  § :style_ok:`Success`
   Some text here (some precision - some other info) §  § :style_ok:`Success`
   Some text here (some precision - some other info) §  § :style_ok:`Success`
   Some text here (some precision - some other info) §  § :style_ok:`Success`

🖥 Versions

  • Python 3.11.10
  • rst2pdf 0.102
  • reportlab 4.2.5

Which operating system are you using?

OS: Alpine Linux v3.18

Additional information

After downgrading rst2pdf back to 0.99 while keeping all of the other versions in the final environment, it seems that the problem is still present, so we are going to investigate further possible causes.

It appears that the error is related to the separator used for the header values: if you replace it with the custom delimiter defined, then it starts printing the table correctly :

.. csv-table::
  :delim: §
  :class: longtable
  :header: "Header1"§ "Header2"§ "Header3"
  :widths: 46, 46, 8

   Some text here (some precision - some other info) §  § :style_ok:`Success`
   Some text here (some precision - some other info) §  § :style_ok:`Success`
   Some text here (some precision - some other info) §  § :style_ok:`Success`
   Some text here (some precision - some other info) §  § :style_ok:`Success`
   Some text here (some precision - some other info) §  § :style_ok:`Success`

Why is it the case and when did it change from accepting regular coma separators regardless of the custom delimiter?

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugTriaged as a bug

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions