[reportlab-users] Problem with long text in a textField

Robin Becker robin at reportlab.com
Wed May 29 05:12:26 EDT 2024


Hi,

not exactly sure what you are attempting to do.

 From your example I can say that the use of a raw linefeed in an XML attribute will cause a problem. XML attributes 
don't cross lines so far as I know, but googling seems to indicate it might be allowable in some parsers. We are using a 
widely used python parser package called lxml.

I assume you realize that using a textField means that you are using an iteractive form mechanism designed for input. 
Although the various PDF manuals discuss methods for altering borders, colours fonts & other display properties it turns 
out that the actual display of fields is entirely controlled by the reader software. However, it may be possible that 
you also need to set the maxlen attribute in the field. Looking at the document, PDF32000_2008.pdf, I see text field is 
described in 12.7.4.3 (page 442). Perhaps some of the attributes need to be set.

When I run your example after replacing \n with 
 can see inside the PDF that the full text is present in the 
document, but the display value starts like this "/DV (Tacrolimus:\n-....)". into lines. According the manuals that's 
supposed to be the way to represent a linefeed. I will need a while to see how acrobat pro does it.


On 28/05/2024 20:39, Kip Nalley wrote:
> Hello,
> I'm using reportlab with a .prep file to generate a PDF.  The issue is that when I have long text in a textField like below, the text is truncated, and the \n newline characters are not rendered as new lines.  The size of the textField can accommodate the text, it just won't render anything beyond a certain number of characters as a single string. Neither '<br>' nor '<br/>' work to break up the text (I have tried both).  Multiline does nothing as far as I can tell.
> 
> IF I replace \n with 
 the text goes into the box but is truncated after 1000 characters.  But if I pass the value as a variable, the 
 is rendered as text.
> 
> So there are two issues simultaneously: How can I get the text to format properly so the whole text blob is included and rendered with line breaks in the textField?
> 
> 
> <illustration height="20cm" width="20cm">
>                  <textField x="0cm" y="3cm"
>                  name="LLM_summary"
>                  width="20cm" height="15cm"
>                  fontSize="10"
>                  multiline="true"
>                  value="Tacrolimus:\n- Evidence from PharmGKB shows genotype GG is associated with increased risk of remaining on steroids at 1 year after transplantation when treated with prednisone and tacrolimus i and Precursor Cell Lymphoblastic Leukemia-Lymphoma as compared to genotype GG."></textField>
> 
> </illustration>
> 
> 
.........

-- 
Robin Becker



More information about the reportlab-users mailing list