Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fail to generate table from csv-table #1239

Open
FlorentP42 opened this issue Oct 11, 2024 · 2 comments
Open

Fail to generate table from csv-table #1239

FlorentP42 opened this issue Oct 11, 2024 · 2 comments
Labels
bug Triaged as a bug

Comments

@FlorentP42
Copy link

FlorentP42 commented Oct 11, 2024

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?

@lornajane
Copy link
Contributor

Thanks for the bug report, I hadn't seen this problem before and I guess we don't have a test for it either. Please keep us posted if you have any more information!

@lornajane lornajane added the bug Triaged as a bug label Oct 15, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Triaged as a bug
Projects
None yet
Development

No branches or pull requests

3 participants
@lornajane @FlorentP42 and others