PyAr / pyafipws

Interfases, tools and apps for Argentina's gov't. webservices (soap, com/dll simil-ocx, pdf, dbf, xml, json, etc.) #python
https://github.com/PyAr/pyafipws/wiki/PyAr-PSF-GSoC-2019-Final-Summary
GNU Lesser General Public License v3.0
2 stars 15 forks source link

Upgrade FPDF to version 2 and fix backward incompatibilities #111

Open reingart opened 1 year ago

reingart commented 1 year ago

To bump fpdf library some changes are needed as new version is backward incompatible

pip unistall fpdf
pip install fpdf2

Errors python pyfepdf.py --prueba

Encodign in UTF-8
Prueba!
/home/devel/pa/.venv/lib/python3.10/site-packages/fpdf/fpdf.py:1887: UserWarning: Substituting font arial by core font helvetica
  warnings.warn(
/home/devel/pa/pyfepdf.py:1650: DeprecationWarning: "dest" is deprecated, unused and will soon be removed
  return self.template.render(archivo, dest)
Traceback (most recent call last):
  File "/home/devel/pa/pyfepdf.py", line 2105, in <module>
    main()
  File "/home/devel/pa/pyfepdf.py", line 2098, in main
    fepdf.GenerarPDF(archivo=salida)
  File "/home/devel/pa/pyafipws/utils.py", line 240, in capturar_errores_wrapper
    return func(self, *args, **kwargs)
  File "/home/devel/pa/pyfepdf.py", line 1650, in GenerarPDF
    return self.template.render(archivo, dest)
  File "/home/devel/pa/.venv/lib/python3.10/site-packages/fpdf/template.py", line 686, in render
    super().render()
  File "/home/devel/pa/.venv/lib/python3.10/site-packages/fpdf/template.py", line 575, in render
    self.handlers[handler_name](**ele)
  File "/home/devel/pa/.venv/lib/python3.10/site-packages/fpdf/template.py", line 354, in _text
    pdf.cell(w=width, h=height, txt=text, border=0, align=align, fill=fill)
  File "/home/devel/pa/.venv/lib/python3.10/site-packages/fpdf/fpdf.py", line 220, in wrapper
    return fn(self, *args, **kwargs)
  File "/home/devel/pa/.venv/lib/python3.10/site-packages/fpdf/fpdf.py", line 2728, in cell
    align = Align.coerce(align)
  File "/home/devel/pa/.venv/lib/python3.10/site-packages/fpdf/enums.py", line 142, in coerce
    return super(cls, cls).coerce(value)
  File "/home/devel/pa/.venv/lib/python3.10/site-packages/fpdf/enums.py", line 55, in coerce
    raise ValueError(f"{value} is not a valid {cls.__name__}")
ValueError: I is not a valid Align

Proper Unit Test should be written comparing current PDF with the one generated by the new library

Lucas-C commented 1 year ago

Hi, fpdf2 maintainer here 😊

Thank you for making this compatibility test and sharing the results.

Regarding this ValueError: I is not a valid Align, I don't understand how this can be a valid value for align... I don't see it documented anywhere, or even appearing in the code of https://github.com/reingart/pyfpdf. I think it must fall in the else case there: https://github.com/reingart/pyfpdf/blob/master/fpdf/fpdf.py#L760

If you have an explanation for the meaning of this value of align='I', we could consider adding backward-compatible support for it in fpdf2. But right now it seems more relevant to fix https://github.com/PyAr/pyafipws code to get rid of this strange value of align='I' 😅

gmischler commented 1 year ago

Late to the party, but anyway...

align="I" is obviously a client-side bug, and was probably meant to read align="J". On the library side, silently ignoring an invalid parameter value - as the legacy version does - should also be considered a bug. Fix both bugs, (and any similar ones that may come up), and the transition should proceed rather smoothly.

For your convenience: A List of API differences between PyFPDF and fpdf2