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

  • SEARCH
  • Home
  • 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 671021
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T00:19:40+00:00 2026-05-14T00:19:40+00:00

I’m using XPreformatted to print some preformated text and I have an issue with

  • 0

I’m using XPreformatted to print some preformated text and I have an
issue with the line breaks.

The line breaks are correctly translated but additionally I get a
"question mark" at the end of each line.

This is my output:

first line?
second line?
some more text

I’m using django with mysql and the database field is a simple varchar field.

I checked it in the database and everything what is between the "e"
and the "s" in "first linE Second line" is a new line character.

With new line character I mean what is entered in the database when I press "enter" 😉

Thus for me it seems strange that on the one hand the new line is
correctly interpreted as a new line and additionally there is a wrong question mark.

  • 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-14T00:19:41+00:00Added an answer on May 14, 2026 at 12:19 am

    ok I know now how to circumvent this behavior. I just remove the character which is before the \n . Its the byte character 13. Thus I created a gready repair algorithm to remove this character and my pdf generating world is fine again 😉

    def repair_string_for_xpreformatted_use(value):
        #remove element before \n
        #it is an empty element interpreted from XPreformatted as a question mark
        #i guess this element is coming from the mysql db. test it with postgres db!
        #this is definitely a greedy repair algorithm
    
        lb_index = value.find('\n')
        start_index = 0
        end_index = len(value)
        value_rep = ""
        while lb_index != -1:
            lb_index = value.find('\n', 1)
            byte_list = toBytes(value[lb_index-1])
            if byte_list[0] == 13:
                #13 is the strange byte character which should not be there. remove it.. bye bye number 13
                value_rep += value[start_index:lb_index-1]
            else:
                #do not remove the character. we do not want to strip some user information ;-)
                value_rep += value[start_index:lb_index]
    
            value = value[lb_index:end_index]
            if lb_index == (end_index -1) or lb_index == end_index:
                lb_index = -1
            end_index = len(value)
        return value_rep
    

    How to use it:

    from reportlab.platypus import XPreformatted
    footerstyle = ParagraphStyle(name='footerstyle', leading=6, spaceBefore=0, spaceAfter=0, textColor=gray2, fontName='Calibri', fontSize=5, alignment=TA_RIGHT)
    footer_text_rep = repair_string_for_xpreformatted_use(footer_text)
    footer_text_pre = XPreformatted(smart_str(footer_text_rep), footerstyle)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have just tried to save a simple *.rtf file with some websites and
For some reason, after submitting a string like this Jack’s Spindle from a text
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I have a French site that I want to parse, but am running into
This could be a duplicate question, but I have no idea what search terms
I have a text area in my form which accepts all possible characters from
I have thousands of HTML files to process using Groovy/Java and I need to
I have a reasonable size flat file database of text documents mostly saved in
I have a bunch of posts stored in text files formatted in yaml/textile (from
I have a .ini file as follows: [playlist] numberofentries=2 File1=http://87.230.82.17:80 Title1=(#1 - 365/1400) Example

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.