我看到了一些使用CMYK的例子,但似乎没有正常工作:
color = colors.Color(0.00, 0.25, 0.25, 0.01)
我尝试了很多颜色,但只有一种看起来工作正常(灰色):
color = colors.Color(0.01, 0.00, 0.04, 0.20)
我的代码:
from reportlab.lib import colors
from reportlab.lib.pagesizes import A4, inch, landscape
from reportlab.lib.enums import TA_CENTER
from reportlab.lib.units import mm
from reportlab.lib.styles import getSampleStyleSheet, ParagraphStyle
from reportlab.platypus import SimpleDocTemplate, Table, LongTable, TableStyle, Paragraph, KeepTogether
import cgi
response = HttpResponse(content_type='application/pdf')
response['Content-Disposition'] = 'attachment; filename=export.pdf'
data = [['ID', 'Title', 'Type', 'Priority', 'Status', 'Description', 'Comments']]
# getting the list
product_id = request.GET.get('product', '')
status = request.GET.get('status', '')
filter_id = request.GET.get('filter', '')
sort = request.GET.get('sort', '-created')
author = LdapUser.objects.get(uid=str(request.user))
issue_list = _get_issue_list(product_id, status, filter_id, author, sort)
row = 1
color_style = []
for issue in issue_list:
comments = ''
for comment in issue.comments:
comments += comment
data.append([str(issue.id), issue.title, issue.type, issue.priority, issue.status, issue.description, cgi.escape(comments)])
color = colors.Color(0, 0, 0, 0)
if issue.status == 'New':
#color = colors.Color(0.00, 0.25, 0.25, 0.01)
color = colors.red
elif issue.status == 'Unconfirmed':
#color = colors.Color(0.14, 0.14, 0.00, 0.09)
color = colors.purple
elif issue.status == 'Confirmed':
#color = colors.Color(0.00, 0.04, 0.42, 0.00)
color = colors.yellow
elif issue.status == 'Triaged':
#color = colors.Color(0.00, 0.20, 0.48, 0.00)
color = colors.orange
elif issue.status == 'Reopened':
#color = colors.Color(0.24, 0.13, 0.00, 0.00)
color = colors.lightblue
elif issue.status == 'Resolved':
#color = colors.Color(0.14, 0.00, 0.28, 0.04)
color = colors.palegreen
elif issue.status == 'Invalid':
color = colors.Color(0.01, 0.00, 0.04, 0.20)
#table_style.add('BACKGROUND', (0,row), (-1,row), color)
color_style.append(('BACKGROUND', (0,row), (-1,row), color))
row +=1
答案 0 :(得分:1)
默认情况下,colors.Color
使用RGBA类型的颜色。
这是对此的验证:
>>> toColor('rgba( 255,0,0,0.5)') == Color(1,0,0,0.5)
True
>>> toColor('cmyk(1,0,0,0 )') == CMYKColor(1,0,0,0)
True
因此,您需要使用colors.CMYKColor