Форум сайта python.su
Здравствуйте подскажите пожалуйста как осуществить перенос строки в формируемой pdf-ке. Код который формирует pdf и в нем в таблицу
from reportlab.pdfbase import pdfmetrics
from cStringIO import StringIO
from reportlab.lib.pagesizes import letter, A4
from reportlab.platypus import SimpleDocTemplate, Paragraph, Spacer, Table, TableStyle
from reportlab.lib.styles import getSampleStyleSheet, ParagraphStyle
from reportlab.lib import colors
from reportlab.lib.units import cm, inch
def print1(request):
response = HttpResponse(mimetype='application/pdf')
response['Content-Disposition'] = 'attachment; filename=3.pdf'
temp = StringIO()
doc = SimpleDocTemplate(temp, pagesize=A4, rightMargin=72, leftMargin=72, topMargin=82, bottomMargin=18)
Catalog = []
styles = getSampleStyleSheet()
styles.add(ParagraphStyle(name='Justify', wordWrap=True))
header = Paragraph("Bnopnya", styles['Normal'])
Catalog.append(header)
style = styles['Normal']
headings = ("dsddfffffffffffffffffffffddddddfffffffffffsd", 'Normal')
t = Table([headings], [5*cm, 2*cm])
t.setStyle(TableStyle(
[('GRID', (0,0), (1,-1), 2, colors.white),
('LINEBELOW', (0,0), (-1,0), 2, colors.white),
('BACKGROUND', (0, 0), (-1, 0), colors.white)]))
Catalog.append(t)
doc.build(Catalog)
response.write(temp.getvalue())
temp.close()
return response
Офлайн
Проблему решил, извиняюсь за задержку, был в отпуске. Может кому поможет, вот код
from reportlab.pdfbase import pdfmetrics
from cStringIO import StringIO
from reportlab.lib.pagesizes import letter, A4
from reportlab.platypus import SimpleDocTemplate, Paragraph, Spacer, Table, TableStyle
from reportlab.lib.styles import getSampleStyleSheet, ParagraphStyle
from reportlab.lib import colors
from reportlab.lib.units import cm, inch
def print1(request):
response = HttpResponse(mimetype='application/pdf')
response['Content-Disposition'] = 'attachment; filename=3.pdf'
temp = StringIO()
doc = SimpleDocTemplate(temp, pagesize=A4, rightMargin=72, leftMargin=72, topMargin=82, bottomMargin=18)
Catalog = []
styles = getSampleStyleSheet()
style = styles['Normal']
styles.add(ParagraphStyle(name='Justify', wordWrap=True, fontSize=12))
header = Paragraph(u'%s' % '''As fffddddfffff dddddddddd dffffffffffffff df ddddddfdkjfkdjfkjdkfjkdjfdfkjkdf''', styles['Justify'])
Catalog.append(header)
row1 = [['dsddfffffffdghghh'],
[header]]
t = Table(row1, 1*[7*cm], 2*[4*cm])
t.setStyle(TableStyle(
[('GRID', (0,0), (1,-1), 1, colors.black),
('LINEBELOW', (0,0), (-1,0), 1, colors.white),
('BACKGROUND', (0, 0), (-1, 0), colors.pink)]))
Catalog.append(t)
doc.build(Catalog)
response.write(temp.getvalue())
temp.close()
return response
Офлайн