Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Space between words when using wordWrap='CJK' and alignment=TA_JUSTIFY #11

Open
dn070017 opened this issue Nov 29, 2019 · 0 comments
Open

Comments

@dn070017
Copy link

When using Asian characters with English/numbers, I expected the spaces will be added between the Asian characters and English/numbers for TA_JUSTIFY alignment (so the line alignment perfectly at the right side of the text). But instead, the spaces are added at the end of the line.

Expected:
image

Result:
image

Code:

from io import BytesIO
from reportlab.pdfgen import canvas
from reportlab.pdfbase import pdfmetrics, ttfonts
from reportlab.lib.units import cm
from reportlab.lib.enums import TA_JUSTIFY, TA_LEFT, TA_CENTER
from reportlab.lib.styles import getSampleStyleSheet, ParagraphStyle
from reportlab.platypus import Paragraph, Frame, Table, TableStyle, Image

pdfmetrics.registerFont(ttfonts.TTFont('Noto-Light', './NotoSansCJKtc_ttf/NotoSansCJKtc-Light.ttf'))

styles = getSampleStyleSheet()
styles.add(ParagraphStyle(name='Content', fontName='Noto-Light', leading=19, alignment = TA_JUSTIFY, wordWrap = 'CJK', fontSize=13))

packet = BytesIO()
pdf_canvas = canvas.Canvas(packet, pagesize=(23.6 * cm, 32.3 * cm))

string = "測試測試測試測試測試測試測試測試測試測試123測試測試測試測試測試測試測試測試測試測試"

f = Frame(12 * cm, 9 * cm, 8.35 * cm, 2.7 * cm, showBoundary=1, leftPadding=0, rightPadding=0, topPadding=0, bottomPadding=0)
story = [Paragraph(string, styles['Content'])]
f.addFromList(story, pdf_canvas)
pdf_canvas.showPage()
pdf_canvas.save()

Version: 3.5.26

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant