Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 1024079
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T11:43:33+00:00 2026-05-16T11:43:33+00:00

I have been working with some complex PDF outputs with reportlab. These are generally

  • 0

I have been working with some complex PDF outputs with reportlab. These are generally fine but there are some cases still where I get LayoutErrors – these are usually because Flowables are too big at some point.

It’s proving o be pretty hard to debug these as I don’t often have more information than something like this;

Flowable <Table@0x104C32290 4 rows x 6 cols> with cell(0,0) containing
'<Paragraph at 0x104df2ea8>Authors'(789.0 x 1176) too large on page 5 in frame 'normal'(801.543307087 x 526.582677165*) of template 'Later'

It’s really not that helpful. What I would ideally like to know is the best debugging and testing strategies for this kinda thing.

  • Is there a way I can view a broken PDF? i.e. rendered with the layout errors so I can see whats going on more easily.
  • Is there a way I can add a hook to reportlab to better handle these errors? Rather than just failing the whole PDF?
  • Any other suggestions about generally improving, testing and handling problems like these.

I don’t have a particular example so its more general advice, the exception above I have resolved but its kinda through trial and error (read; guessing and seeing what happens).

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-16T11:43:34+00:00Added an answer on May 16, 2026 at 11:43 am

    We had a problem when using Reportlab to format some content that was originally html and sometimes the html was too complex. The solution (and I take no credit here, this was from the guys at Reportlab) was to catch the error when it occurred and output it directly into the PDF.

    That means you get to see the cause of the problem in the right context. You could expand on this to output details of the exception, but in our case since our problem was converting html to rml we just had to display our input:

    Tthe preppy template contains this:

    {{script}}
    #This section contains python functions used within the rml.
    #we can import any helper code we need within the template,
    #to save passing in hundreds of helper functions at the top
    from rml_helpers import blocks
    {{endscript}}
    

    and then later bits of template like:

        {{if equip.specification}}
     <condPageBreak height="1in"/> 
            <para style="h2">Item specification</para>
            {{blocks(equip.specification)}}
        {{endif}}
    

    In rml_helpers.py we have:

    from xml.sax.saxutils import escape
    from rlextra.radxml.html_cleaner import cleanBlocks
    from rlextra.radxml.xhtml2rml import xhtml2rml
    
    def q(stuff):
        """Quoting function which works with unicode strings.
    
        The data from Zope is Unicode objects.  We need to explicitly
        convert to UTF8; then escape any ampersands.  So
           u"Black & Decker drill"
        becomes
           "Black &amp; Decker drill"
        and any special characters (Euro, curly quote etc) end up
        suitable for XML.  For completeness we'll accept 'None'
        objects as well and output an empty string.
    
        """
        if stuff is None:
            return ''
        elif isinstance(stuff,unicode):
            stuff = escape(stuff.encode('utf8'))
        else:
            stuff = escape(str(stuff))
        return stuff.replace('"','&#34;').replace("'", '&#39;')
    
    def blocks(txt):
        try:
            txt2 = cleanBlocks(txt)
            rml = xhtml2rml(txt2)
            return rml
        except:
            return '<para style="big_warning">Could not process markup</para><para style="normal">%s</para>' % q(txt)
    

    So anything which is too complex for xhtml2rml to handle throws an exception and is replaced in the output by a big warning ‘Could not process markup’ followed by the markup that caused the error, escaped so it appears as literal.

    Then all we have to do is to remember to search the output PDF for the error message and fix up the input accordingly.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have been working with Struts for some time, but for a project I
I have been working on some legacy C++ code that uses variable length structures
I'm not a Notes programmer, however, for my sins, have been working on some
On a recent project I have been working on in C#/ASP.NET I have some
I have some really complicated legacy code I've been working on that crashes when
I have been working with relational databases for sometime, but it only recently occurred
I have been working to build a complex data structure which would return a
I have been working on quite a complex accordion/form recently and have a select
I have been working on developing some RESTful Services in Django to be used
I have been working on a web services related project for about the last

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.