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

PDF export not working on specific pages in Arabic & Farsi #1498

Open
Tracked by #1533
timobrembeck opened this issue May 25, 2022 · 8 comments
Open
Tracked by #1533

PDF export not working on specific pages in Arabic & Farsi #1498

timobrembeck opened this issue May 25, 2022 · 8 comments
Labels
🐛 bug Something isn't working ⛔ blocked Blocked by external dependency 😱 effort: high Big change, which requires >12h 🆘 prio: urgent Needs to be resolved now(?)
Milestone

Comments

@timobrembeck
Copy link
Member

timobrembeck commented May 25, 2022

Describe the Bug

Steps to Reproduce

https://admin.integreat-app.de/marburg-biedenkopf/fa/wp-json/ig-mpdf/v1/pdf/

Expected Behavior

The PDF should be shown

Actual Behavior

An internal server error occurs
(AttributeError: 'ParaLines' object has no attribute 'lineBreak')

Additional Information

Update: Fixed upstream (see xhtml2pdf/xhtml2pdf#643), so wait until a new release is triggered and update xhtml2pdf to fix the issue.

Also, when updating, we can also remove this workaround:

# Get fixed version of default pdf styling (see https://github.com/digitalfabrik/integreat-cms/issues/1537)
fixed_css = DEFAULT_CSS.replace("background-color: transparent;", "", 1)

Traceback
  self.handle_flowable(flowables)
File "/opt/integreat-cms/.venv/lib/python3.9/site-packages/reportlab/platypus/doctemplate.py", line 928, in handle_flowable
  if frame.add(f, canv, trySplit=self.allowSplitting):
File "/opt/integreat-cms/.venv/lib/python3.9/site-packages/reportlab/platypus/frames.py", line 212, in _add
  flowable.drawOn(canv, self._x + self._leftExtraIndent, y, _sW=aW-w)
File "/opt/integreat-cms/.venv/lib/python3.9/site-packages/reportlab/platypus/flowables.py", line 112, in drawOn
  self._drawOn(canvas)
File "/opt/integreat-cms/.venv/lib/python3.9/site-packages/reportlab/platypus/flowables.py", line 93, in _drawOn
  self.draw()#this is the bit you overload
File "/opt/integreat-cms/.venv/lib/python3.9/site-packages/xhtml2pdf/xhtml2pdf_reportlab.py", line 684, in draw
  Paragraph.draw(self)
File "/opt/integreat-cms/.venv/lib/python3.9/site-packages/xhtml2pdf/reportlab_paragraph.py", line 1144, in draw
  self.drawPara(self.debug)
File "/opt/integreat-cms/.venv/lib/python3.9/site-packages/xhtml2pdf/reportlab_paragraph.py", line 1641, in drawPara
  dpl(tx, offset, lines[0], noJustifyLast and nLines == 1)
File "/opt/integreat-cms/.venv/lib/python3.9/site-packages/xhtml2pdf/reportlab_paragraph.py", line 405, in _justifyDrawParaLineX
  if last or not nSpaces or abs(extraSpace) <= 1e-8 or line.lineBreak:
AttributeError: 'ParaLines' object has no attribute 'lineBreak'
@timobrembeck timobrembeck added 🐛 bug Something isn't working ‼️ prio: high Needs to be resolved ASAP. labels May 25, 2022
@timobrembeck timobrembeck added this to the Version 1.2 milestone May 25, 2022
@timobrembeck timobrembeck mentioned this issue Jun 8, 2022
36 tasks
@svenseeberg svenseeberg added the 😱 effort: high Big change, which requires >12h label Jun 9, 2022
@timobrembeck timobrembeck modified the milestones: 22Q2, 22Q3 Jul 18, 2022
@svenseeberg svenseeberg added 🆘 prio: urgent Needs to be resolved now(?) and removed ‼️ prio: high Needs to be resolved ASAP. labels Jul 20, 2022
@timobrembeck
Copy link
Member Author

The error also appears on some Arabic pages:

  File "/opt/integreat-cms/.venv/lib/python3.9/site-packages/django/views/decorators/cache.py", line 44, in _wrapped_view_func
    response = view_func(request, *args, **kwargs)
  File "/opt/integreat-cms/.venv/lib/python3.9/site-packages/integreat_cms/cms/utils/pdf_utils.py", line 115, in generate_pdf
    pisa_status = pisa.CreatePDF(
  File "/opt/integreat-cms/.venv/lib/python3.9/site-packages/xhtml2pdf/document.py", line 155, in pisaDocument
    doc.multiBuild(context.story)
  File "/opt/integreat-cms/.venv/lib/python3.9/site-packages/reportlab/platypus/doctemplate.py", line 1169, in multiBuild
    self.build(tempStory, **buildKwds)
  File "/opt/integreat-cms/.venv/lib/python3.9/site-packages/reportlab/platypus/doctemplate.py", line 1082, in build
    self.handle_flowable(flowables)
  File "/opt/integreat-cms/.venv/lib/python3.9/site-packages/reportlab/platypus/doctemplate.py", line 931, in handle_flowable
    if frame.add(f, canv, trySplit=self.allowSplitting):
  File "/opt/integreat-cms/.venv/lib/python3.9/site-packages/reportlab/platypus/frames.py", line 212, in _add
    flowable.drawOn(canv, self._x + self._leftExtraIndent, y, _sW=aW-w)
  File "/opt/integreat-cms/.venv/lib/python3.9/site-packages/reportlab/platypus/flowables.py", line 112, in drawOn
    self._drawOn(canvas)
  File "/opt/integreat-cms/.venv/lib/python3.9/site-packages/reportlab/platypus/flowables.py", line 93, in _drawOn
    self.draw()#this is the bit you overload
  File "/opt/integreat-cms/.venv/lib/python3.9/site-packages/xhtml2pdf/xhtml2pdf_reportlab.py", line 684, in draw
    Paragraph.draw(self)
  File "/opt/integreat-cms/.venv/lib/python3.9/site-packages/xhtml2pdf/reportlab_paragraph.py", line 1144, in draw
    self.drawPara(self.debug)
  File "/opt/integreat-cms/.venv/lib/python3.9/site-packages/xhtml2pdf/reportlab_paragraph.py", line 1641, in drawPara
    dpl(tx, offset, lines[0], noJustifyLast and nLines == 1)
  File "/opt/integreat-cms/.venv/lib/python3.9/site-packages/xhtml2pdf/reportlab_paragraph.py", line 405, in _justifyDrawParaLineX
    if last or not nSpaces or abs(extraSpace) <= 1e-8 or line.lineBreak:
AttributeError: 'ParaLines' object has no attribute 'lineBreak'

@timobrembeck timobrembeck changed the title PDF export not working on specific pages in farsi PDF export not working on specific pages in Arabic & Farsi Sep 13, 2022
@MizukiTemma MizukiTemma self-assigned this Sep 17, 2022
@MizukiTemma
Copy link
Member

MizukiTemma commented Sep 23, 2022

I've tested some of the not working farsi pages on the current develop branch for PDF export and it works.

The tested pages are the first (عنوان اقامت شهروندان اتحادیه اروپا و کشورهای ثالث) and last (شهروندان اتحادیه اروپا فاقد شغل) under the last parent page with world map icon ( شهروندان اتحادیه اروپا و اتباع کشور های ثالث) under the ID-Card icon (مسائل حقوقی: پناهندگی، اتحادیه اروپا و کشورهای ثالث) in Marburg-Biedenkopf.
These pages cannt be successfully exported as PDF, neither individually nor together with other pages.

Though when I copy & past the contents in the current develop branch and export them as PDF, it works.

page overview
Export as bundle
exported individually

@charludo
Copy link
Contributor

charludo commented Nov 2, 2022

Looks like it's an xhtml2pdf bug. Opened this issue: xhtml2pdf/xhtml2pdf#642 and corresponding PR upstream. I don't think there's anything further we need to do other than wait until the fix makes it into a release.

IDK if this issue should remain open until then?

@timobrembeck
Copy link
Member Author

@charludo Thank you so much!

Hmm, I guess in this case let's leave it open until the problem is fixed for us by updating the library.

@timobrembeck timobrembeck added the ⛔ blocked Blocked by external dependency label Nov 3, 2022
@timobrembeck timobrembeck modified the milestones: 22Q4, 23Q1 Dec 12, 2022
@timobrembeck timobrembeck removed the ⛔ blocked Blocked by external dependency label Jan 31, 2023
@timobrembeck timobrembeck modified the milestones: 23Q1, 23Q2 Mar 23, 2023
@timobrembeck timobrembeck added the ⛔ blocked Blocked by external dependency label Mar 23, 2023
@timobrembeck timobrembeck modified the milestones: 23Q2, 23Q3 Jul 2, 2023
@svenseeberg svenseeberg modified the milestones: 23Q3, 23Q4 Oct 4, 2023
@charludo charludo removed their assignment Oct 12, 2023
@MizukiTemma MizukiTemma modified the milestones: 23Q4, 24Q1 Dec 5, 2023
@osmers
Copy link

osmers commented Feb 27, 2024

Any updates here? What are we waiting for?

@timobrembeck
Copy link
Member Author

@osmers the problem has been fixed in the upstream library xhtml2pdf, but these fixes have introduced a number of even worse bugs (for example page numbering doesn't work anymore and the text lines are reversed on right to left alphabets), so we decided not to update the library until the new bugs have been fixed as well.

@osmers
Copy link

osmers commented Feb 28, 2024

@timobrembeck ah alright, thanks for the explanation - I didn't get that from reading the comments :) hopefully it will be fixed soon!

@BananaEgg
Copy link

I'm facing the same issue, has there been progress?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🐛 bug Something isn't working ⛔ blocked Blocked by external dependency 😱 effort: high Big change, which requires >12h 🆘 prio: urgent Needs to be resolved now(?)
Projects
None yet
Development

Successfully merging a pull request may close this issue.

7 participants