python - Reportlab 'LayoutError' handling and debugging -


I am working with reportlab with some complex PDF outputs. These are usually okay but in some cases where I am receiving LayoutErrors - these are usually because the flowables are very large at some point

It proves o very hard to debug I often do not have these as can be. More info than anything like this;

  Flowwell & lt; Table @ 0x104C32290 4 rows x 6 columns & gt; With cell (0,0) containing '; Paragraph on 0x104df2ea8 & gt; & Lt Author '(789.0 x 1176) is too big on page 5 in' Normal 'frame (801.54, 33,07,087 x 526.582677165 *) in template' later ' 

This is not really useful. Would I want to know that the best debugging and testing strategy for such things?

  • Is there any way to see broken PDFs? That is, layout is provided with errors, so I can see what is happening more easily.
  • In a way, can I add a hook to the report to handle these errors better? Instead of failing in the entire PDF?
  • Generally improvements, tests and any other suggestions about these issues such as handling.

I do not have any special examples, more general advice, I have solved the exceptions above but test and error (read; guess and see what happens) . Text ">

We have a problem that was originally a problem while using the RepublicBab to format HTML and sometimes HTML was very complex. Solution (and I do not take any credit here, report this report Had to catch the error, and it had to output directly to the PDF.

This means that you get to see the cause of the problem in the right context. We can expand on this for the details, but in our case because our problem was changing from HTL to RML, we only had to display our input:

TPPPP template includes:

  {{script}} # This section contains the Python functions used within rml # We save any assistive code we need within the template, passing in hundreds of helpful tasks at the top #to rml_helpers Block from You can import {{endcript}}  

and then later bits like Template:

  {{equip.specification}} & lt; CondPageBreak height = "1in" /> & Lt; Paragraph style = "h2" & gt; Item specification & lt; / Paragraph & gt; {{Block (equip.specification)}} {{endif}}  

In rml_helpers.py we have:

  import from xml.sax.saxutils rlextra .radxml.xhtml2rml import xhtml2rml def q (stuff) from rlextra.radxml.html_cleaner import cleanBlocks escape: "" "Function which works with Unicode strings while encoding data from Zope Unicode objects we need to explicitly change UTF8 So, avoid any ampersands, so you can say "Black & amp; Decker Drill "gets" Black & amp; Decker drill "and any particular character (Euro, curly quotation, etc.) For the perfect end to XML, we will accept 'None' as well and empty string objects in production." "Stuff: if there is no one: return '' elif eashens (stuff, unicode): accessories = escape (stuff. ('Utf 8')): accessories = escape (strings) Reform Stuff. '', 'And' # 34; '). ('', '' '' '' '' '' 'Def blocks (txt): try: txt2 = cleanBlocks (txt) rml = xhtml2rml (txt2) Returns: Excluding rml: Returns & lt; paragraph style = "big_warning" & Gt; Process Markup & lt; / para & gt; & lt; paragraph style = "normal" & gt;% s & lt; / paragraph & gt;% Q (txt)  

Whatever code to handle, it is very complicated for xhtml2rml , throws an exception and is replaced by output by large warning 'can not process markup', after which the error is due to the mother If the blueprint was to come out, it really appeared.

Then we should remember to find out the output PDF for error message and to fix the input accordingly.

< / Html>

Comments