pythonpdfpdf-generationreportlab

Python reportlab paragraph function only draws a third of the input text to a pdf file


Forgive me if this is a common issue, i could not find an answer.

As the title states, I've got a problem with report lab drawing text to a .pdf file. The input is a big plaintext string, extracted from a json object.

This is the code i use too generate and automaticly open the pdf file. To open the document I use a system call.

def importAsPdf():
        #Open the plain tekst
        document = json.load(urllib2.urlopen(documenturl))
        documentId = document["id"].encode("utf-8")
        text = document["text"].encode("utf-8")
        print(text)

        #Create the pdf file
        doc = SimpleDocTemplate("pdftextfile.pdf")
        parts = []
        #setting page width and height. just used a standard A4 page measurement.
        PAGE_WIDTH, PAGE_HEIGHT = A4
        aW = PAGE_WIDTH - 4*inch  # available width and height 
        aH = PAGE_HEIGHT - 4*inch

        #importing the styles
        style = ParagraphStyle(name='fancy')
        style.fontSize = 12
        style.leading = 18

        #Build the pdf
        p = Paragraph(text, style)
        parts.append(p)
        doc.build(parts)
        print(doc.filename)
            #Open the pdf
        subprocess.call(('gnome-open', "pdftextfile.pdf"))

When it opens the pdf, only about on third of the text is in there and the other 2 thirds are no where to be found. It doesn't throw any exception or anything, it just stops somewhere mid sentence about 1 third of the way there.

Any thoughts?

edit: I've found that it stops at the only "<" in the text. Are these a problem for generating pdf files with reportlab?


Solution

  • I have found that an "<" in the text stops reportlab from completely drawing the text to a pdf document. I removed the "<" with text.replace("<", "")and everything is now fine.

    As to the why, I have no idea.