Problem Creating NewLines in PDF
Hello I am generating a PDF in web2py but its ignoring my line breaks. randname = random.randrange(1, 10001) styles = getSampleStyleSheet() title = My Title doc = SimpleDocTemplate(primer.pdf) story = [] story.append(Paragraph(strftime(%a, %d %b %Y %H:%M:%S, gmtime()),styles[Heading2])) para = ParagraphStyle(name=output, fontName='Helvetica', fontSize=12) story.append(Paragraph(str(result_list), para)) doc.build(story) response.headers['Content-Type']='application/pdf' response.headers['Content-Disposition'] = 'attachment;filename='+str(randname)+'-.pdf' return response.stream(open(primer.pdf, 'rb')) result_list is a generated list. The pdf ignores line breaks and outputs it as a list so [' '] are included also. Any idea how I can create line breaks and get rid of the [' '] *cheers -- http://mail.python.org/mailman/listinfo/python-list
Re: Problem Creating NewLines in PDF
Andrew Evans wrote: Hello I am generating a PDF in web2py but its ignoring my line breaks. randname = random.randrange(1, 10001) styles = getSampleStyleSheet() title = My Title doc = SimpleDocTemplate(primer.pdf) story = [] story.append(Paragraph(strftime(%a, %d %b %Y %H:%M:%S, gmtime()),styles[Heading2])) para = ParagraphStyle(name=output, fontName='Helvetica', fontSize=12) story.append(Paragraph(str(result_list), para)) str(result_list) is converting the list into a string. Did you mean to do that? doc.build(story) response.headers['Content-Type']='application/pdf' response.headers['Content-Disposition'] = 'attachment;filename='+str(randname)+'-.pdf' return response.stream(open(primer.pdf, 'rb')) result_list is a generated list. The pdf ignores line breaks and outputs it as a list so [' '] are included also. Any idea how I can create line breaks and get rid of the [' '] -- http://mail.python.org/mailman/listinfo/python-list
Re: Problem Creating NewLines in PDF
Hello yes This line doesn't seem to want to accept a list for some strange reason story.append(Paragraph(str(result_list), para)) *cheers -- http://mail.python.org/mailman/listinfo/python-list
Re: Problem Creating NewLines in PDF
Andrew Evans wrote: Hello yes This line doesn't seem to want to accept a list for some strange reason story.append(Paragraph(str(result_list), para)) From the documentation it appears that you need to pass a string. You're just passing the result of str(result_list), which isn't giving you what you want: result_list = ['hello', 'world'] print str(result_list) ['hello', 'world'] But what do you want? Do you just want to concatenate the entries into a single string (assuming they're all strings)? print .join(result_list) helloworld Or with some kind of separator between them? print .join(result_list) hello world -- http://mail.python.org/mailman/listinfo/python-list
Re: Problem Creating NewLines in PDF
Hello ty for the fast replies This is the string I am using for the PDF I was able to create new lines using the HTML br tag which is what I wanted a method to create new lines search_str=Position: (%d) - Keyword: (%s) - Domain (%s) br /br / % (idx+1, target_keyword, session.target_domain) result_list.append(search_str) however it maintains these characters in the text of the generated PDF [' ', ' '] with the string in between those I just want to be able to out put the string with no extra characters I assume these characters are there because its a list .. From the documentation it appears that you need to pass a string. You're just passing the result of str(result_list), which isn't giving you what you want: -- http://mail.python.org/mailman/listinfo/python-list
Re: Problem Creating NewLines in PDF
Andrew Evans wrote: Hello ty for the fast replies This is the string I am using for the PDF I was able to create new lines using the HTML br tag which is what I wanted a method to create new lines search_str=Position: (%d) - Keyword: (%s) - Domain (%s) br /br / % (idx+1, target_keyword, session.target_domain) result_list.append(search_str) however it maintains these characters in the text of the generated PDF [' ', ' '] with the string in between those I just want to be able to out put the string with no extra characters I assume these characters are there because its a list As I said, if you just want to join a list of strings into one string, then use .join(result_list): story.append(Paragraph(.join(result_list), para)) -- http://mail.python.org/mailman/listinfo/python-list