def test0(self): "A basic document drawing some strings" # if they do not have the Japanese font files, go away quietly from reportlab.pdfbase.cidfonts import UnicodeCIDFont, findCMapFile pdfmetrics.registerFont(UnicodeCIDFont('STSong-Light')) c = Canvas(outputfile('test_multibyte_chs.pdf')) c.setFont('Helvetica', 30) c.drawString(100,700, 'Simplified Chinese Font Support') c.setFont('Helvetica', 10) c.drawString(100,680, 'Short sample: "China - Zhang Ziyi" (famous actress)') # the two typefaces hBoxText('\u4e2d\u56fd - \u7ae0\u5b50\u6021', c, 100, 660, 'STSong-Light', ) c.setFont('Helvetica',10) c.drawCentredString(297, 36, 'Page %d' % c.getPageNumber()) c.showPage() ## # full kuten chart in EUC ## c.setFont('Helvetica', 18) ## c.drawString(72,750, 'Characters available in GB 2312-80, EUC encoding') ## y = 600 ## enc = 'GB_EUC_H' ## for row in range(1, 95): ## KutenRowCodeChart(row, 'STSong-Light',enc).drawOn(c, 72, y) ## y = y - 125 ## if y < 50: ## c.setFont('Helvetica',10) ## c.drawCentredString(297, 36, 'Page %d' % c.getPageNumber()) ## c.showPage() ## y = 700 ## c.save() if VERBOSE: print('saved '+outputfile('test_multibyte_chs.pdf'))
def test0(self): "A basic document drawing some strings" # if they do not have the Japanese font files, go away quietly from reportlab.pdfbase.cidfonts import UnicodeCIDFont, findCMapFile pdfmetrics.registerFont(UnicodeCIDFont('STSong-Light')) c = Canvas(outputfile('test_multibyte_chs.pdf')) c.setFont('Helvetica', 30) c.drawString(100,700, 'Simplified Chinese Font Support') c.setFont('Helvetica', 10) c.drawString(100,680, 'Short sample: "China - Zhang Ziyi" (famous actress)') # the two typefaces hBoxText(u'\u4e2d\u56fd - \u7ae0\u5b50\u6021', c, 100, 660, 'STSong-Light', ) c.setFont('Helvetica',10) c.drawCentredString(297, 36, 'Page %d' % c.getPageNumber()) c.showPage() ## # full kuten chart in EUC ## c.setFont('Helvetica', 18) ## c.drawString(72,750, 'Characters available in GB 2312-80, EUC encoding') ## y = 600 ## enc = 'GB_EUC_H' ## for row in range(1, 95): ## KutenRowCodeChart(row, 'STSong-Light',enc).drawOn(c, 72, y) ## y = y - 125 ## if y < 50: ## c.setFont('Helvetica',10) ## c.drawCentredString(297, 36, 'Page %d' % c.getPageNumber()) ## c.showPage() ## y = 700 ## c.save() if VERBOSE: print 'saved '+outputfile('test_multibyte_chs.pdf')
class PDFCreator(object): appName = "txt2pdf (version 1.0)" def __init__(self, args, margins): pageWidth, pageHeight = reportlab.lib.pagesizes.__dict__[args.media] if args.landscape: pageWidth, pageHeight = reportlab.lib.pagesizes.landscape( (pageWidth, pageHeight)) self.author = args.author self.title = args.title self.keywords = args.keywords self.subject = args.subject self.canvas = Canvas(args.output, pagesize=(pageWidth, pageHeight)) self.canvas.setCreator(self.appName) if len(args.author) > 0: self.canvas.setAuthor(args.author) if len(args.title) > 0: self.canvas.setTitle(args.title) if len(args.subject) > 0: self.canvas.setSubject(args.subject) if len(args.keywords) > 0: self.canvas.setKeywords(args.keywords) self.fontSize = args.font_size if args.font not in ('Courier'): self.font = 'myFont' pdfmetrics.registerFont(TTFont('myFont', args.font)) else: self.font = args.font self.kerning = args.kerning self.margins = margins self.leading = (args.extra_vertical_space + 1.2) * self.fontSize self.linesPerPage = int( (self.leading + pageHeight - margins.top - margins.bottom - self.fontSize) / self.leading) self.lppLen = len(str(self.linesPerPage)) fontWidth = self.canvas.stringWidth( ".", fontName=self.font, fontSize=self.fontSize) self.lineNumbering = args.line_numbers if self.lineNumbering: margins.adjustLeft(fontWidth * (self.lppLen + 2)) contentWidth = pageWidth - margins.left - margins.right self.charsPerLine = int( (contentWidth + self.kerning) / (fontWidth + self.kerning)) self.top = pageHeight - margins.top - self.fontSize self.filename = args.filename self.verbose = not args.quiet self.breakOnBlanks = args.break_on_blanks self.encoding = args.encoding self.pageNumbering = args.page_numbers if self.pageNumbering: self.pageNumberPlacement = \ (pageWidth / 2, margins.bottom / 2) def _process(self, data): flen = os.fstat(data.fileno()).st_size lineno = 0 read = 0 for line in data: lineno += 1 if sys.version_info.major == 2: read += len(line) yield flen == \ read, lineno, line.decode(self.encoding).rstrip('\r\n') else: read += len(line.encode(self.encoding)) yield flen == read, lineno, line.rstrip('\r\n') def _readDocument(self): with open(self.filename, 'r') as data: for done, lineno, line in self._process(data): if len(line) > self.charsPerLine: self._scribble( "Warning: wrapping line %d in %s" % (lineno + 1, self.filename)) while len(line) > self.charsPerLine: yield done, line[:self.charsPerLine] line = line[self.charsPerLine:] yield done, line def _newpage(self): textobject = self.canvas.beginText() textobject.setFont(self.font, self.fontSize, leading=self.leading) textobject.setTextOrigin(self.margins.left, self.top) textobject.setCharSpace(self.kerning) if self.pageNumbering: self.canvas.drawString( self.pageNumberPlacement[0], self.pageNumberPlacement[1], str(self.canvas.getPageNumber())) return textobject def _scribble(self, text): if self.verbose: sys.stderr.write(text + os.linesep) def generate(self): self._scribble( "Writing '%s' with %d characters per " "line and %d lines per page..." % (self.filename, self.charsPerLine, self.linesPerPage) ) if self.breakOnBlanks: pageno = self._generateBob(self._readDocument()) else: pageno = self._generatePlain(self._readDocument()) self._scribble("PDF document: %d pages" % pageno) def _generatePlain(self, data): pageno = 1 lineno = 0 page = self._newpage() for _, line in data: lineno += 1 # Handle form feed characters. (line, pageBreakCount) = re.subn(r'\f', r'', line) if pageBreakCount > 0 and lineno >= args.minimum_page_length: for _ in range(pageBreakCount): self.canvas.drawText(page) self.canvas.showPage() lineno = 0 pageno += 1 page = self._newpage() if args.minimum_page_length > 0: break page.textLine(line) if lineno == self.linesPerPage: self.canvas.drawText(page) self.canvas.showPage() lineno = 0 pageno += 1 page = self._newpage() if lineno > 0: self.canvas.drawText(page) else: pageno -= 1 self.canvas.save() return pageno def _writeChunk(self, page, chunk, lineno): if self.lineNumbering: formatstr = '%%%dd: %%s' % self.lppLen for index, line in enumerate(chunk): page.textLine( formatstr % (lineno - len(chunk) + index + 1, line)) else: for line in chunk: page.textLine(line) def _generateBob(self, data): pageno = 1 lineno = 0 page = self._newpage() chunk = list() for last, line in data: if lineno == self.linesPerPage: self.canvas.drawText(page) self.canvas.showPage() lineno = len(chunk) pageno += 1 page = self._newpage() lineno += 1 chunk.append(line) if last or len(line.strip()) == 0: self._writeChunk(page, chunk, lineno) chunk = list() if lineno > 0: self.canvas.drawText(page) self.canvas.showPage() else: pageno -= 1 if len(chunk) > 0: page = self._newpage() self.canvas.drawText(page) self.canvas.showPage() pageno += 1 self.canvas.save() return pageno
def test0(self): "A basic document drawing some strings" c = Canvas(outputfile('test_multibyte_jpn.pdf')) c.setFont('Helvetica', 30) c.drawString(100, 700, 'Japanese Font Support') c.setStrokeColor(colors.red) #unicode font automatically supplies the encoding pdfmetrics.registerFont(UnicodeCIDFont('HeiseiMin-W3')) msg = u'\u6771\u4EAC : Unicode font, unicode input' self.hDraw(c, msg, 'HeiseiMin-W3', 100, 600) msg = u'\u6771\u4EAC : Unicode font, utf8 input'.encode('utf8') self.hDraw(c, msg, 'HeiseiMin-W3', 100, 575) # now try verticals - this is broken, not sure how to make it # work in post Unicode world. pdfmetrics.registerFont(CIDFont('HeiseiMin-W3', '90ms-RKSJ-V')) c.setFont('HeiseiMin-W3-90ms-RKSJ-V', 16) c.drawString(450, 650, '\223\214\213\236 vertical Shift-JIS') height = c.stringWidth('\223\214\213\236 vertical Shift-JIS', 'HeiseiMin-W3-90ms-RKSJ-V', 16) c.rect(450 - 8, 650, 16, -height) pdfmetrics.registerFont(CIDFont('HeiseiMin-W3', 'EUC-V')) c.setFont('HeiseiMin-W3-EUC-V', 16) c.drawString(475, 650, '\xC5\xEC\xB5\xFE vertical EUC') height = c.stringWidth('\xC5\xEC\xB5\xFE vertical EUC', 'HeiseiMin-W3-EUC-V', 16) c.rect(475 - 8, 650, 16, -height) from reportlab.platypus.paragraph import Paragraph from reportlab.lib.styles import ParagraphStyle jStyle = ParagraphStyle('jtext', fontName='HeiseiMin-W3', fontSize=12, wordWrap="CJK") gatwickText = '\xe3\x82\xac\xe3\x83\x88\xe3\x82\xa6\xe3\x82\xa3\xe3\x83\x83\xe3\x82\xaf\xe7\xa9\xba\xe6\xb8\xaf\xe3\x81\xa8\xe9\x80\xa3\xe7\xb5\xa1\xe9\x80\x9a\xe8\xb7\xaf\xe3\x81\xa7\xe7\x9b\xb4\xe7\xb5\x90\xe3\x81\x95\xe3\x82\x8c\xe3\x81\xa6\xe3\x81\x84\xe3\x82\x8b\xe5\x94\xaf\xe4\xb8\x80\xe3\x81\xae\xe3\x83\x9b\xe3\x83\x86\xe3\x83\xab\xe3\x81\xa7\xe3\x81\x82\xe3\x82\x8b\xe5\xbd\x93\xe3\x83\x9b\xe3\x83\x86\xe3\x83\xab\xe3\x81\xaf\xe3\x80\x81\xe8\xa1\x97\xe3\x81\xae\xe4\xb8\xad\xe5\xbf\x83\xe9\x83\xa8\xe3\x81\x8b\xe3\x82\x8930\xe5\x88\x86\xe3\x81\xae\xe5\xa0\xb4\xe6\x89\x80\xe3\x81\xab\xe3\x81\x94\xe3\x81\x96\xe3\x81\x84\xe3\x81\xbe\xe3\x81\x99\xe3\x80\x82\xe5\x85\xa8\xe5\xae\xa2\xe5\xae\xa4\xe3\x81\xab\xe9\xab\x98\xe9\x80\x9f\xe3\x82\xa4\xe3\x83\xb3\xe3\x82\xbf\xe3\x83\xbc\xe3\x83\x8d\xe3\x83\x83\xe3\x83\x88\xe7\x92\xb0\xe5\xa2\x83\xe3\x82\x92\xe5\xae\x8c\xe5\x82\x99\xe3\x81\x97\xe3\x81\xa6\xe3\x81\x8a\xe3\x82\x8a\xe3\x81\xbe\xe3\x81\x99\xe3\x80\x82\xe3\x83\x95\xe3\x82\xa1\xe3\x83\x9f\xe3\x83\xaa\xe3\x83\xbc\xe3\x83\xab\xe3\x83\xbc\xe3\x83\xa0\xe3\x81\xaf5\xe5\x90\x8d\xe6\xa7\x98\xe3\x81\xbe\xe3\x81\xa7\xe3\x81\x8a\xe6\xb3\x8a\xe3\x82\x8a\xe3\x81\x84\xe3\x81\x9f\xe3\x81\xa0\xe3\x81\x91\xe3\x81\xbe\xe3\x81\x99\xe3\x80\x82\xe3\x81\xbe\xe3\x81\x9f\xe3\x80\x81\xe3\x82\xa8\xe3\x82\xb0\xe3\x82\xbc\xe3\x82\xaf\xe3\x83\x86\xe3\x82\xa3\xe3\x83\x96\xe3\x83\xab\xe3\x83\xbc\xe3\x83\xa0\xe3\x81\xae\xe3\x81\x8a\xe5\xae\xa2\xe6\xa7\x98\xe3\x81\xaf\xe3\x80\x81\xe3\x82\xa8\xe3\x82\xb0\xe3\x82\xbc\xe3\x82\xaf\xe3\x83\x86\xe3\x82\xa3\xe3\x83\x96\xe3\x83\xa9\xe3\x82\xa6\xe3\x83\xb3\xe3\x82\xb8\xe3\x82\x92\xe3\x81\x94\xe5\x88\xa9\xe7\x94\xa8\xe3\x81\x84\xe3\x81\x9f\xe3\x81\xa0\xe3\x81\x91\xe3\x81\xbe\xe3\x81\x99\xe3\x80\x82\xe4\xba\x8b\xe5\x89\x8d\xe3\x81\xab\xe3\x81\x94\xe4\xba\x88\xe7\xb4\x84\xe3\x81\x84\xe3\x81\x9f\xe3\x81\xa0\xe3\x81\x91\xe3\x82\x8b\xe3\x82\xbf\xe3\x82\xa4\xe3\x83\xa0\xe3\x83\x88\xe3\x82\xa5\xe3\x83\x95\xe3\x83\xa9\xe3\x82\xa4\xe3\x83\xbb\xe3\x83\x91\xe3\x83\x83\xe3\x82\xb1\xe3\x83\xbc\xe3\x82\xb8\xe3\x81\xab\xe3\x81\xaf\xe3\x80\x81\xe7\xa9\xba\xe6\xb8\xaf\xe3\x81\xae\xe9\xa7\x90\xe8\xbb\x8a\xe6\x96\x99\xe9\x87\x91\xe3\x81\x8c\xe5\x90\xab\xe3\x81\xbe\xe3\x82\x8c\xe3\x81\xa6\xe3\x81\x8a\xe3\x82\x8a\xe3\x81\xbe\xe3\x81\x99\xe3\x80\x82' gatwickText2 = '\xe3\x82\xac\xe3\x83\x88\xe3\x82\xa6\xe3\x82\xa3\xe3\x83\x83\xe3\x82\xaf<font color=red>\xe7\xa9\xba\xe6\xb8\xaf\xe3\x81\xa8\xe9\x80\xa3\xe7\xb5\xa1\xe9\x80\x9a\xe8\xb7\xaf\xe3\x81\xa7\xe7\x9b\xb4\xe7\xb5\x90</font>\xe3\x81\x95\xe3\x82\x8c\xe3\x81\xa6\xe3\x81\x84\xe3\x82\x8b\xe5\x94\xaf\xe4\xb8\x80\xe3\x81\xae\xe3\x83\x9b\xe3\x83\x86\xe3\x83\xab\xe3\x81\xa7\xe3\x81\x82\xe3\x82\x8b\xe5\xbd\x93\xe3\x83\x9b\xe3\x83\x86\xe3\x83\xab\xe3\x81\xaf\xe3\x80\x81\xe8\xa1\x97\xe3\x81\xae\xe4\xb8\xad\xe5\xbf\x83\xe9\x83\xa8\xe3\x81\x8b\xe3\x82\x8930\xe5\x88\x86\xe3\x81\xae\xe5\xa0\xb4\xe6\x89\x80\xe3\x81\xab\xe3\x81\x94\xe3\x81\x96\xe3\x81\x84\xe3\x81\xbe\xe3\x81\x99\xe3\x80\x82\xe5\x85\xa8\xe5\xae\xa2\xe5\xae\xa4\xe3\x81\xab\xe9\xab\x98\xe9\x80\x9f\xe3\x82\xa4\xe3\x83\xb3\xe3\x82\xbf\xe3\x83\xbc\xe3\x83\x8d\xe3\x83\x83\xe3\x83\x88<link fg="blue" href="http://www.reportlab.com">\xe7\x92\xb0\xe5\xa2\x83\xe3\x82\x92\xe5\xae\x8c\xe5\x82\x99</link>\xe3\x81\x97\xe3\x81\xa6<u>\xe3\x81\x8a\xe3\x82\x8a\xe3\x81\xbe\xe3\x81\x99</u>\xe3\x80\x82\xe3\x83\x95\xe3\x82\xa1\xe3\x83\x9f\xe3\x83\xaa\xe3\x83\xbc\xe3\x83\xab\xe3\x83\xbc\xe3\x83\xa0\xe3\x81\xaf5\xe5\x90\x8d\xe6\xa7\x98\xe3\x81\xbe\xe3\x81\xa7\xe3\x81\x8a\xe6\xb3\x8a\xe3\x82\x8a\xe3\x81\x84\xe3\x81\x9f\xe3\x81\xa0\xe3\x81\x91\xe3\x81\xbe\xe3\x81\x99\xe3\x80\x82\xe3\x81\xbe\xe3\x81\x9f\xe3\x80\x81\xe3\x82\xa8\xe3\x82\xb0\xe3\x82\xbc\xe3\x82\xaf\xe3\x83\x86\xe3\x82\xa3\xe3\x83\x96\xe3\x83\xab\xe3\x83\xbc\xe3\x83\xa0\xe3\x81\xae\xe3\x81\x8a\xe5\xae\xa2\xe6\xa7\x98\xe3\x81\xaf\xe3\x80\x81\xe3\x82\xa8\xe3\x82\xb0\xe3\x82\xbc\xe3\x82\xaf\xe3\x83\x86\xe3\x82\xa3\xe3\x83\x96\xe3\x83\xa9\xe3\x82\xa6\xe3\x83\xb3\xe3\x82\xb8\xe3\x82\x92\xe3\x81\x94\xe5\x88\xa9\xe7\x94\xa8\xe3\x81\x84\xe3\x81\x9f\xe3\x81\xa0\xe3\x81\x91\xe3\x81\xbe\xe3\x81\x99\xe3\x80\x82\xe4\xba\x8b\xe5\x89\x8d\xe3\x81\xab\xe3\x81\x94\xe4\xba\x88\xe7\xb4\x84\xe3\x81\x84\xe3\x81\x9f\xe3\x81\xa0\xe3\x81\x91\xe3\x82\x8b\xe3\x82\xbf\xe3\x82\xa4\xe3\x83\xa0\xe3\x83\x88\xe3\x82\xa5\xe3\x83\x95\xe3\x83\xa9\xe3\x82\xa4\xe3\x83\xbb\xe3\x83\x91\xe3\x83\x83\xe3\x82\xb1\xe3\x83\xbc\xe3\x82\xb8\xe3\x81\xab\xe3\x81\xaf\xe3\x80\x81\xe7\xa9\xba\xe6\xb8\xaf\xe3\x81\xae\xe9\xa7\x90\xe8\xbb\x8a\xe6\x96\x99\xe9\x87\x91\xe3\x81\x8c\xe5\x90\xab\xe3\x81\xbe\xe3\x82\x8c\xe3\x81\xa6\xe3\x81\x8a\xe3\x82\x8a\xe3\x81\xbe\xe3\x81\x99\xe3\x80\x82' c.setFont('HeiseiMin-W3', 12) jPara = Paragraph(gatwickText, jStyle) jPara.wrap(300, 200) jPara.drawOn(c, 100, 220) jPara = Paragraph(gatwickText2, jStyle) jPara.wrap(300, 200) jPara.drawOn(c, 100, 320) c.setFillColor(colors.purple) tx = c.beginText(100, 200) tx.setFont('Helvetica', 12) tx.textLines("""This document shows sample output in Japanese from the Reportlab PDF library. This page shows the two fonts available and tests our ability to measure the width of glyphs in both horizontal and vertical writing, with proportional and fixed-width characters. The red boxes should be the same width (or height) as the character strings they surround. The next pages show more samples and information. """) c.drawText(tx) c.setFont('Helvetica', 10) c.drawCentredString(297, 36, 'Page %d' % c.getPageNumber()) c.showPage() c.setFont('Helvetica', 30) c.drawString(100, 700, 'Japanese TrueType Font Support') msg = u'\u6771\u4EAC : Unicode font'.encode('utf8') msg2 = u'utf8 input 0123456789 ABCDEF'.encode('utf8') from reportlab.pdfbase.ttfonts import TTFont try: msmincho = TTFont('MS Mincho', 'msmincho.ttc', subfontIndex=0, asciiReadable=0) fn = ' file=msmincho.ttc subfont 0' except: try: msmincho = TTFont('MS Mincho', 'msmincho.ttf', asciiReadable=0) fn = 'file=msmincho.ttf' except: #Ubuntu - works on Lucid Lynx if xpdf-japanese installed try: msmincho = TTFont('MS Mincho', 'ttf-japanese-mincho.ttf') fn = 'file=msmincho.ttf' except: msmincho = None if msmincho is None: c.setFont('Helvetica', 12) c.drawString(100, 600, 'Cannot find msmincho.ttf or msmincho.ttc') else: pdfmetrics.registerFont(msmincho) c.setFont('MS Mincho', 30) c.drawString(100, 600, msg) c.drawString(100, 570, msg2) c.drawString(100, 540, fn) if fn.endswith('0'): try: msmincho1 = TTFont('MS Mincho 1', 'msmincho.ttc', subfontIndex=1, asciiPreload=0) pdfmetrics.registerFont(msmincho1) fn = ' file=msmincho.ttc subfont 1' c.setFont('MS Mincho 1', 30) c.drawString(100, 500, msg + fn) except: c.setFont('Helvetica', 30) c.drawString(100, 500, msg) c.drawString(100, 470, msg2) c.drawString(100, 440, fn) #test a paragraph with CJK and <br/> tags u = u'''<font color=red>\u30ac\u30c8\u30a6\u30a3\u30c3</font><br/><font color=blue>\u30af\u7a7a\u6e2f\u3068\u9023\u7d61\u901a</font><br/>\u8def\u3067\u76f4\u7d50\u3055\u308c\u3066\u3044\u308b\u552f<br/>\u4e00\u306e\u30db\u30c6\u30eb\u3067\u3042\u308b\u5f53\u30db\u30c6\u30eb\u306f\u3001\u8857\u306e\u4e2d\u5fc3\u90e8\u304b\u308930\u5206\u306e\u5834\u6240\u306b\u3054\u3056\u3044\u307e\u3059\u3002\u5168\u5ba2\u5ba4\u306b\u9ad8\u901f\u30a4\u30f3\u30bf\u30fc\u30cd\u30c3\u30c8<br/>\u74b0\u5883\u3092\u5b8c\u5099\u3057\u3066\u304a\u308a\u307e\u3059\u3002\u30d5\u30a1\u30df\u30ea\u30fc\u30eb\u30fc\u30e0\u306f5\u540d\u69d8\u307e\u3067\u304a\u6cca\u308a\u3044\u305f\u3060\u3051\u307e\u3059\u3002\u307e\u305f\u3001\u30a8\u30b0\u30bc\u30af\u30c6\u30a3\u30d6\u30eb\u30fc\u30e0\u306e\u304a\u5ba2\u69d8\u306f\u3001\u30a8\u30b0\u30bc\u30af\u30c6\u30a3\u30d6\u30e9\u30a6\u30f3\u30b8\u3092\u3054\u5229\u7528\u3044\u305f\u3060\u3051\u307e\u3059\u3002\u4e8b\u524d\u306b\u3054\u4e88\u7d04\u3044\u305f\u3060\u3051\u308b\u30bf\u30a4\u30e0\u30c8\u30a5\u30d5\u30e9\u30a4\u30fb\u30d1\u30c3\u30b1\u30fc\u30b8\u306b\u306f\u3001\u7a7a\u6e2f\u306e\u99d0\u8eca\u6599\u91d1\u304c\u542b\u307e\u308c\u3066\u304a\u308a\u307e\u3059\u3002''' jPara = Paragraph(u, jStyle) jPara.wrap(300, 500) jPara.drawOn(c, 100, 300) c.showPage() # realistic text sample ## sample = """Adobe Acrobat ##\x83h\x83L\x83\x85\x83\x81\x83\x93\x83g\x82\xaa\x8aJ\x82\xa9\x82\xc8\x82\xad\x82\xc4\x8d\xa2\x82\xc1\x82\xbd\x82\xb1\x82\xc6\x82\xcd ##\x82\xa0\x82\xe8\x82\xdc\x82\xb9\x82\xf1\x82\xa9\x81B\x8e\x96\x8b\xc6\x8cv\x89\xe6\x8f\x91\x81A\x89c\x8b\xc6\x83\x8c\x83|\x81[\x83g ##\x81A\x83J\x83^\x83\x8d\x83O\x82\xe2\x83p\x83\x93\x83t\x83\x8c\x83b\x83g\x82\xc8\x82\xc7\x90\xa7\x8d\xec\x95\xa8\x82\xcc\x8e\xed ##\x97\xde\x82\xc9\x82\xa9\x82\xa9\x82\xed\x82\xe7\x82\xb8\x81A ##\x83h\x83L\x83\x85\x83\x81\x83\x93\x83g\x82\xcdAdobe® Acrobat® 5.0\x82\xf0\x8eg\x82\xc1\x82\xc4Adobe PDF\x81iPortable Document ##Format\x81j\x83t\x83@\x83C\x83\x8b\x82\xc9\x95\xcf\x8a\xb7\x82\xb5\x82\xdc\x82\xb5\x82\xe5\x82\xa4\x81B\x96\xb3\x8f\x9e\x94z\x95z\x82\xcc ##Adobe Acrobat Reader\x82\xf0\x8eg\x82\xa6\x82\xce\x81A\x83n\x81[\x83h\x83E\x83F\x83A\x81A\x83\\\x83t\x83g\x83E\x83F\x83A\x82\xc9\x82\xa9 ##\x82\xa9\x82\xed\x82\xe7\x82\xb8\x81A\x92N\x82\xc5\x82\xe0\x82\xa0\x82\xc8\x82\xbd\x82\xcc\x83h\x83L\x83\x85\x83\x81\x83\x93\x83g\x82\xf0 ##\x83I\x83\x8a\x83W\x83i\x83\x8b\x82\xcc\x91\xcc\x8d\xd9\x82\xc5\x8aJ\x82\xad\x82\xb1\x82\xc6\x82\xaa\x82\xc5\x82\xab\x82\xdc\x82\xb7\x81B ##\x82\xa0\x82\xc8\x82\xbd\x82\xcc\x88\xd3\x90}\x82\xb5\x82\xbd\x82\xc6\x82\xa8\x82\xe8\x82\xc9\x8f\xee\x95\xf1\x82\xf0\x93`\x82\xa6\x82\xe9 ##\x82\xb1\x82\xc6\x82\xaa\x82\xc5\x82\xab\x82\xdc\x82\xb7\x81B ##\x82\xb3\x82\xe7\x82\xc9\x81AAdobe Acrobat 5.0\x82\xc5\x82\xcd\x81AWeb\x83u\x83\x89\x83E\x83U\x82\xa9\x82\xe7\x83R\x83\x81\x83\x93\x83g\x82\xe2 ##\x83}\x81[\x83N\x83A\x83b\x83v\x82\xf0\x8f\x91\x82\xab\x8d\x9e\x82\xf1\x82\xbe\x82\xe8\x81A\x93d\x8eq\x8f\x90\x96\xbc\x82\xf0\x8f\x91\x82\xab ##\x8d\x9e\x82\xdd\x81A\x8c\xb4\x96{\x82\xc6\x82\xb5\x82\xc4\x83\x8d\x81[\x83J\x83\x8b\x82\xc9\x95\xdb\x91\xb6\x82\xb7\x82\xe9\x82\xb1\x82\xc6\x82\xe0\x89\xc2\x94\\\x82\xc5\x82\xb7\x81B ##\x8a\xe9\x8b\xc6\x93\xe0\x82\xa0\x82\xe9\x82\xa2\x82\xcd\x8a\xe9\x8b\xc6\x82\xcc\x98g\x82\xf0\x92\xb4\x82\xa6\x82\xc4\x83`\x81[\x83\x80\x82\xc5 ##\x82\xcc\x83h\x83L\x83\x85\x83\x81\x83\x93\x83g\x83\x8f\x81[\x83N\x82\xcc\x90\xb6\x8eY\x90\xab\x82\xf0\x8c\xfc\x8f\xe3\x82\xb3\x82\xb9\x82\xe9\x82\xb1\x82\xc6\x82\xaa\x82\xc5\x82\xab\x82\xdc\x82\xb7\x81B ## ##Adobe Acrobat 5.0\x82\xc5\x8d\xec\x90\xac\x82\xb5\x82\xbdAdobe PDF\x82\xcd\x81A(Acrobat 5.0\x82\xc5\x82\xcc\x82\xdd\x83T\x83|\x81[\x83g ##\x82\xb5\x82\xc4\x82\xa2\x82\xe9\x88\xc3\x8d\x86\x89\xbb\x90\xdd\x92\xe8\x82\xf0\x8f\x9c\x82\xa2\x82\xc4\x82\xcd)\x8f]\x97\x88\x82\xdc ##\x82\xc5\x82\xcc\x83o\x81[\x83W\x83\x87\x83\x93(3\x82\xa8\x82\xe6\x82\xd1\x82S)\x82\xccAcrobat Reader\x82\xc5\x82\xe0\x8aJ\x82\xad ##\x82\xb1\x82\xc6\x82\xaa\x82\xc5\x82\xab\x82\xdc\x82\xb7\x81B\x8f\xee\x95\xf1\x8b\xa4\x97L\x82\xcc\x83c\x81[\x83\x8b\x82\xc6\x82\xb5 ##\x82\xc4\x81A\x82\xb3\x82\xe7\x82\xc9\x90i\x95\xe0\x82\xb5\x82\xbdAdobe Acrobat 5.0\x82\xf0\x81A\x8f]\x97\x88\x82\xcc\x8a\xc2\x8b\xab ##\x82\xc5\x82\xe0\x88\xc0\x90S\x82\xb5\x82\xc4\x82\xb2\x97\x98\x97p\x82\xa2\x82\xbd\x82\xbe\x82\xaf\x82\xdc\x82\xb7\x81B ## ##\x96{\x90\xbb\x95i\x82\xf0\x83l\x83b\x83g\x83\x8f\x81[\x83N\x82\xc8\x82\xc7\x82\xf0\x89\xee\x82\xb5\x82\xc4\x92\xbc\x90\xda\x82\xa0\x82\xe9 ##\x82\xa2\x82\xcd\x8a\xd4\x90\xda\x82\xc9\x95\xa1\x90\x94\x82\xcc\x92[\x96\x96\x82\xa9\x82\xe7\x8eg\x97p\x82\xb7\x82\xe9\x8f\xea\x8d\x87\x81A ##\x82\xbb\x82\xcc\x92[\x96\x96\x82\xc6\x93\xaf\x90\x94\x82\xcc\x83\x89\x83C\x83Z\x83\x93\x83X\x82\xf0\x82\xb2\x8dw\x93\xfc\x82\xad\x82\xbe ##\x82\xb3\x82\xa2\x81B\x96{\x90\xbb\x95i\x82\xcd\x83N\x83\x89\x83C\x83A\x83\x93\x83g\x97p\x83\\\x83t\x83g\x83E\x83F\x83A\x82\xc5\x82\xa0\x82\xe8 ##\x81A\x83T\x81[\x83o\x97p\x83\\\x83t\x83g\x83E\x83F\x83A\x82\xc6\x82\xb5\x82\xc4\x82\xa8\x8eg\x82\xa2\x82\xa2\x82\xbd\x82\xbe\x82\xad\x82\xb1\x82\xc6 ##\x82\xcd\x81A\x8f\xe3\x8bL\x95\xfb\x96@\x82\xc9\x82\xe6\x82\xe9\x88\xc8\x8aO\x81A\x8b\x96\x91\xf8\x82\xb3\x82\xea\x82\xc4\x82\xa2\x82\xdc\x82\xb9 ##\x82\xf1\x81B\x95\xa1\x90\x94\x82\xcc\x83\x89\x83C\x83Z\x83\x93\x83X\x82\xf0\x82\xb2\x8dw\x93\xfc\x82\xb3\x82\xea\x82\xe9\x8f\xea\x8d\x87\x82\xc9 ##\x82\xcd\x83\x89\x83C\x83Z\x83\x93\x83X\x83v\x83\x8d\x83O\x83\x89\x83\x80\x82\xf0\x82\xb2\x97\x98\x97p\x82\xc9\x82\xc8\x82\xe9\x82\xc6\x82\xa8\x93\xbe\x82\xc5\x82\xb7\x81B ## ## ##\x81y\x82\xa8\x92m\x82\xe7\x82\xb9\x81zMicrosoft Office XP\x82\xa9\x82\xe7PDF\x82\xf0\x8d\xec\x90\xac\x82\xb7\x82\xe9\x82\xc9\x82\xcd ##""" ## c.setFont('Helvetica', 24) ## c.drawString(100,750, "Sample text from Adobe's web site") ## tx = c.beginText(100,700) ## tx.setFont('Helvetica', 10) ## tx.textLine('Note: line wrapping has not been preserved and some lines may be wrapped in mid-word.') ## tx.textLine('We are just testing that we see Japanese and not random characters!') ## tx.setFont('HeiseiMin-W3-90ms-RKSJ-H',6) ## tx.textLines(sample) ## tx.setFont('Helvetica', 8) ## tx.textLine() ## tx.textLine() ## tx.textLines(""" ## This test document shows Japanese output from the Reportlab PDF Library. ## You may use two fonts, HeiseiMin-W3 and HeiseiKakuGo-W5, and a number of ## different encodings. ## ## The available encoding names (with comments from the PDF specification) are: ## encodings_jpn = [ ## # official encoding names, comments taken verbatim from PDF Spec ## '83pv-RKSJ-H', #Macintosh, JIS X 0208 character set with KanjiTalk6 ## #extensions, Shift-JIS encoding, Script Manager code 1 ## '90ms-RKSJ-H', #Microsoft Code Page 932 (lfCharSet 0x80), JIS X 0208 ## #character set with NEC and IBM extensions ## '90ms-RKSJ-V', #Vertical version of 90ms-RKSJ-H ## '90msp-RKSJ-H', #Same as 90ms-RKSJ-H, but replaces half-width Latin ## #characters with proportional forms ## '90msp-RKSJ-V', #Vertical version of 90msp-RKSJ-H ## '90pv-RKSJ-H', #Macintosh, JIS X 0208 character set with KanjiTalk7 ## #extensions, Shift-JIS encoding, Script Manager code 1 ## 'Add-RKSJ-H', #JIS X 0208 character set with Fujitsu FMR extensions, ## #Shift-JIS encoding ## 'Add-RKSJ-V', #Vertical version of Add-RKSJ-H ## 'EUC-H', #JIS X 0208 character set, EUC-JP encoding ## 'EUC-V', #Vertical version of EUC-H ## 'Ext-RKSJ-H', #JIS C 6226 (JIS78) character set with NEC extensions, ## #Shift-JIS encoding ## 'Ext-RKSJ-V', #Vertical version of Ext-RKSJ-H ## 'H', #JIS X 0208 character set, ISO-2022-JP encoding, ## 'V', #Vertical version of H ## 'UniJIS-UCS2-H', #Unicode (UCS-2) encoding for the Adobe-Japan1 character ## #collection ## 'UniJIS-UCS2-V', #Vertical version of UniJIS-UCS2-H ## 'UniJIS-UCS2-HW-H', #Same as UniJIS-UCS2-H, but replaces proportional Latin ## #characters with half-width forms ## 'UniJIS-UCS2-HW-V' #Vertical version of UniJIS-UCS2-HW-H ## ] ## ## The next few pages show the complete character set available in the encoding ## "90ms-RKSJ-H" - Shift-JIS with the standard Microsoft extensions. ## """) ## c.drawText(tx) ## ## c.setFont('Helvetica',10) ## c.drawCentredString(297, 36, 'Page %d' % c.getPageNumber()) ## ## ## ## c.showPage() from reportlab.lib import textsplit c.setFont('HeiseiMin-W3', 14) y = 700 c.drawString(70, y, 'cannot end line') y -= 20 for group in textsplit.CANNOT_START_LINE: c.drawString(70, y, group) y -= 20 c.setFont('Helvetica', 10) c.drawString(70, y, ' '.join(map(lambda x: repr(x)[4:-1], group))) c.setFont('HeiseiMin-W3', 14) y -= 20 y -= 20 c.drawString(70, y, 'cannot end line') y -= 20 for group in textsplit.CANNOT_END_LINE: c.drawString(70, y, group) y -= 20 c.setFont('Helvetica', 10) c.drawString(70, y, ' '.join(map(lambda x: repr(x)[2:], group))) c.setFont('HeiseiMin-W3', 14) y -= 20 c.showPage() #utf8 encoded paragraph sample2_uni = u'''\u30ac\u30c8\u30a6\u30a3\u30c3\u30af\u7a7a\u6e2f\u3068\u9023\u7d61\u901a \u8def\u3067\u76f4\u7d50\u3055\u308c\u3066\u3044\u308b\u552f\u4e00\u306e\u30db\u30c6\u30eb \u3067\u3042\u308b\u5f53\u30db\u30c6\u30eb\u306f\u3001\u8857\u306e\u4e2d\u5fc3\u90e8\u304b \u308930\u5206\u306e\u5834\u6240\u306b\u3054\u3056\u3044\u307e\u3059\u3002\u5168\u5ba2\u5ba4 \u306b\u9ad8\u901f\u30a4\u30f3\u30bf\u30fc\u30cd\u30c3\u30c8\u74b0\u5883\u3092\u5b8c\u5099 \u3057\u3066\u304a\u308a\u307e\u3059\u3002\u30d5\u30a1\u30df\u30ea\u30fc\u30eb\u30fc\u30e0 \u306f5\u540d\u69d8\u307e\u3067\u304a\u6cca\u308a\u3044\u305f\u3060\u3051\u307e\u3059\u3002 \u307e\u305f\u3001\u30a8\u30b0\u30bc\u30af\u30c6\u30a3\u30d6\u30eb\u30fc\u30e0\u306e\u304a \u5ba2\u69d8\u306f\u3001\u30a8\u30b0\u30bc\u30af\u30c6\u30a3\u30d6\u30e9\u30a6\u30f3\u30b8 \u3092\u3054\u5229\u7528\u3044\u305f\u3060\u3051\u307e\u3059\u3002\u4e8b\u524d\u306b\u3054 \u4e88\u7d04\u3044\u305f\u3060\u3051\u308b\u30bf\u30a4\u30e0\u30c8\u30a5\u30d5\u30e9\u30a4 \u30fb\u30d1\u30c3\u30b1\u30fc\u30b8\u306b\u306f\u3001\u7a7a\u6e2f\u306e\u99d0\u8eca\u6599 \u91d1\u304c\u542b\u307e\u308c\u3066\u304a\u308a\u307e\u3059\u3002''' oneline_uni = u''.join(sample2_uni.split()) sample2_utf8 = oneline_uni.encode('utf8') from reportlab.platypus import Paragraph from reportlab.lib.styles import ParagraphStyle jsty = ParagraphStyle('japanese', fontName='HeiseiMin-W3', wordWrap='CJK') jpara = Paragraph(oneline_uni, style=jsty) c.drawString( 100, 710, 'Try to wrap a paragraph using a style with wordWrap="CJK"') w, h = jpara.wrap(400, 400) jpara.drawOn(c, 100, 700 - h) #now try to split it... c.drawString(100, 510, 'Now try to split a paragraph as if over a page break') topPara, bottomPara = jpara.split(400, 30) w1, h1 = topPara.wrap(400, 30) topPara.drawOn(c, 100, 450) w2, h2 = bottomPara.wrap(400, 30) bottomPara.drawOn(c, 100, 400) #print 'split into heights %0.2f, %0.2f' % (topPara.height, bottomPara.height) ## c.showPage() ## ## ## # full kuten chart in EUC ## c.setFont('Helvetica', 24) ## c.drawString(72,750, 'Characters available in JIS 0208-1997') ## y = 600 ## for row in range(1, 95): ## KutenRowCodeChart(row, 'HeiseiMin-W3','EUC-H').drawOn(c, 72, y) ## y = y - 125 ## if y < 50: ## c.setFont('Helvetica',10) ## c.drawCentredString(297, 36, 'Page %d' % c.getPageNumber()) ## c.showPage() ## y = 700 ## ## c.showPage() #try with Unicode truetype - Mincho for starters ## import time ## started = time.clock() ## c.showPage() ## c.setFont('Helvetica',16) ## c.drawString(100,750, 'About to say Tokyo in MS Gothic...') ## ## from reportlab.pdfbase.ttfonts import TTFont, TTFontFile ## f = TTFontFile("msgothic.ttf") ## print f.name ## ## pdfmetrics.registerFont(TTFont(f.name, f)) ## ## utfText = u'Andr\202'.encode('utf8') ## c.setFont(f.name,16) ## c.drawString(100,700, utfText) ## ## ## #tokyoUCS2 = '\x67\x71\x4E\xAC' ## finished = time.clock() c.save() if VERBOSE: print 'saved test_multibyte_jpn.pdf'
def test0(self): # if they do not have the font files or encoding, go away quietly try: from reportlab.pdfbase.cidfonts import CIDFont, findCMapFile findCMapFile('KSCms-UHC-H') except: #don't have the font pack. return silently return localFontName = 'HYSMyeongJo-Medium' c = Canvas(outputfile('test_multibyte_kor.pdf')) c.setFont('Helvetica', 30) c.drawString(100,700, 'Korean Font Support') c.setFont('Helvetica', 10) c.drawString(100,680, 'Short sample in Unified Hangul Coding (UHC)') hBoxText('\xB9\xD9\xC5\xC1\xC3\xBC (HYSMyeongJo-Medium)', c, 100, 660, 'HYSMyeongJo-Medium', 'KSCms-UHC-H') ## hBoxText('\xB9\xD9\xC5\xC1\xC3\xBC (HYGothic-Medium)', ## c, 100, 640, 'HYGothic-Medium', 'KSCms-UHC-H') pdfmetrics.registerFont(CIDFont('HYSMyeongJo-Medium','KSC-EUC-H')) c.setFont('Helvetica', 10) c.drawString(100,610, "Longer sample From Adobe's Acrobat web page in EUC:") sample = """\xbf\xad \xbc\xf6 \xbe\xf8\xb4\xc2 \xb9\xae\xbc\xad\xb4\xc2 \xbe\xc6\xb9\xab\xb7\xb1 \xbc\xd2\xbf\xeb\xc0\xcc \xbe\xf8\xbd\xc0\xb4\xcf\xb4\xd9. \xbb\xe7\xbe\xf7 \xb0\xe8\xc8\xb9\xbc\xad, \xbd\xba\xc7\xc1\xb7\xb9\xb5\xe5\xbd\xc3\xc6\xae, \xb1\xd7\xb7\xa1\xc7\xc8\xc0\xcc \xb8\xb9\xc0\xcc \xc6\xf7\xc7\xd4\xb5\xc8 \xbc\xd2\xc3\xa5\xc0\xda \xb6\xc7\xb4\xc2 \xc0\xa5 \xbb\xe7\xc0\xcc\xc6\xae\xb8\xa6 \xc0\xdb\xbc\xba\xc7\xcf\xb4\xc2 \xb0\xe6\xbf\xec Adobe\xa2\xe7 Acrobat\xa2\xe7 5.0 \xbc\xd2\xc7\xc1\xc6\xae\xbf\xfe\xbe\xee\xb8\xa6 \xbb\xe7\xbf\xeb\xc7\xd8\xbc\xad \xc7\xd8\xb4\xe7 \xb9\xae\xbc\xad\xb8\xa6 Adobe Portable Document Format (PDF) \xc6\xc4\xc0\xcf\xb7\xce \xba\xaf\xc8\xaf\xc7\xd2 \xbc\xf6 \xc0\xd6\xbd\xc0\xb4\xcf\xb4\xd9. \xb4\xa9\xb1\xb8\xb3\xaa \xb1\xa4\xb9\xfc\xc0\xa7\xc7\xd1 \xc1\xbe\xb7\xf9\xc0\xc7 \xc7\xcf\xb5\xe5\xbf\xfe\xbe\xee\xbf\xcd \xbc\xd2\xc7\xc1\xc6\xae\xbf\xfe\xbe\xee\xbf\xa1\xbc\xad \xb9\xae\xbc\xad\xb8\xa6 \xbf\xad \xbc\xf6 \xc0\xd6\xc0\xb8\xb8\xe7 \xb7\xb9\xc0\xcc\xbe\xc6\xbf\xf4, \xc6\xf9\xc6\xae, \xb8\xb5\xc5\xa9, \xc0\xcc\xb9\xcc\xc1\xf6 \xb5\xee\xc0\xbb \xbf\xf8\xba\xbb \xb1\xd7\xb4\xeb\xb7\xce \xc0\xc7\xb5\xb5\xc7\xd1 \xb9\xd9 \xb4\xeb\xb7\xce \xc7\xa5\xbd\xc3\xc7\xd2 \xbc\xf6 \xc0\xd6\xbd\xc0\xb4\xcf\xb4\xd9. Acrobat 5.0\xc0\xbb \xbb\xe7\xbf\xeb\xc7\xcf\xbf\xa9 \xc0\xa5 \xba\xea\xb6\xf3\xbf\xec\xc0\xfa\xbf\xa1\xbc\xad \xb9\xae\xbc\xad\xb8\xa6 \xbd\xc2\xc0\xce\xc7\xcf\xb0\xed \xc1\xd6\xbc\xae\xc0\xbb \xc3\xdf\xb0\xa1\xc7\xcf\xb4\xc2 \xb9\xe6\xbd\xc4\xc0\xb8\xb7\xce \xb1\xe2\xbe\xf7\xc0\xc7 \xbb\xfd\xbb\xea\xbc\xba\xc0\xbb \xc7\xe2\xbb\xf3\xbd\xc3\xc5\xb3 \xbc\xf6 \xc0\xd6\xbd\xc0\xb4\xcf\xb4\xd9. \xc0\xfa\xc0\xdb\xb1\xc7 © 2001 Adobe Systems Incorporated. \xb8\xf0\xb5\xe7 \xb1\xc7\xb8\xae\xb0\xa1 \xba\xb8\xc8\xa3\xb5\xcb\xb4\xcf\xb4\xd9. \xbb\xe7\xbf\xeb\xc0\xda \xbe\xe0\xb0\xfc \xbf\xc2\xb6\xf3\xc0\xce \xbb\xe7\xbf\xeb\xc0\xda \xba\xb8\xc8\xa3 \xb1\xd4\xc1\xa4 Adobe\xc0\xc7 \xc0\xe5\xbe\xd6\xc0\xda \xc1\xf6\xbf\xf8 \xbc\xd2\xc7\xc1\xc6\xae\xbf\xfe\xbe\xee \xba\xd2\xb9\xfd \xc0\xcc\xbf\xeb \xb9\xe6\xc1\xf6 """ tx = c.beginText(100,600) tx.setFont('HYSMyeongJo-Medium-KSC-EUC-H', 7, 8) tx.textLines(sample) tx.setFont('Helvetica', 10, 12) tx.textLine() tx.textLines("""This test document shows Korean output from the Reportlab PDF Library. You may use one Korean font, HYSMyeongJo-Medium, and a number of different encodings. The available encoding names (with comments from the PDF specification) are: encodings_kor = [ 'KSC-EUC-H', # KS X 1001:1992 character set, EUC-KR encoding 'KSC-EUC-V', # Vertical version of KSC-EUC-H 'KSCms-UHC-H', # Microsoft Code Page 949 (lfCharSet 0x81), KS X 1001:1992 #character set plus 8,822 additional hangul, Unified Hangul #Code (UHC) encoding 'KSCms-UHC-V', #Vertical version of KSCms-UHC-H 'KSCms-UHC-HW-H', #Same as KSCms-UHC-H, but replaces proportional Latin # characters with halfwidth forms 'KSCms-UHC-HW-V', #Vertical version of KSCms-UHC-HW-H 'KSCpc-EUC-H', #Macintosh, KS X 1001:1992 character set with MacOS-KH #extensions, Script Manager Code 3 'UniKS-UCS2-H', #Unicode (UCS-2) encoding for the Adobe-Korea1 character collection 'UniKS-UCS2-V' #Vertical version of UniKS-UCS2-H ] The following pages show all characters in the KS X 1001:1992 standard, using the encoding 'KSC-EUC-H' above. More characters (a LOT more) are available if you use UHC encoding or the Korean Unicode subset, for which the correct encoding names are also listed above. """) c.drawText(tx) c.setFont('Helvetica',10) c.drawCentredString(297, 36, 'Page %d' % c.getPageNumber()) c.showPage() # full kuten chart in EUC c.setFont('Helvetica', 18) c.drawString(72,750, 'Characters available in KS X 1001:1992, EUC encoding') y = 600 for row in range(1, 95): KutenRowCodeChart(row, 'HYSMyeongJo-Medium','KSC-EUC-H').drawOn(c, 72, y) y = y - 125 if y < 50: c.setFont('Helvetica',10) c.drawCentredString(297, 36, 'Page %d' % c.getPageNumber()) c.showPage() y = 700 c.save() if VERBOSE: print 'saved '+outputfile('test_multibyte_kor.pdf')
def test0(self): "A basic document drawing some strings" # if they do not have the Japanese font files, go away quietly from reportlab.pdfbase.cidfonts import CIDFont, findCMapFile enc = 'ETenms-B5-H' try: findCMapFile(enc) except: #they don't have the font pack, return silently return pdfmetrics.registerFont(CIDFont('MSung-Light',enc)) c = Canvas(outputfile('test_multibyte_cht.pdf')) c.setFont('Helvetica', 24) c.drawString(100,700, 'Traditional Chinese Font Support') c.setFont('Helvetica', 10) c.drawString(100,680, 'Short sample: headline from Yahoo Hong Kong, 20 Oct 2001') c.setFont('MSung-Light-' + enc, 12) # this came from Yahoo Hong Kong leading story today message1 = '\xa5\xac\xae\xed\xbbP\xa6\xbf\xbfA\xa5\xc1\xa6b\xad\xba\xa6\xb8\xb7|\xad\xb1\xab\xe1\xa4@\xa6P\xa8\xa3\xb0O\xaa\xcc\xa1A\xa5L\xbb\xa1\xa1A\xa8\xe2\xa4H\xaa\xba\xad\xba\xa6\xb8\xb7|\xad\xb1\xabD\xb1`' message2 = '\xa6n\xa1A\xa8\xc3\xaa\xed\xa5\xdc\xb2@\xb5L\xba\xc3\xb0\xdd\xa4\xa4\xb0\xea\xa6b\xb3o\xad\xd3\xa5i\xa9\xc6\xaa\xba\xae\xc9\xa8\xe8\xa1A\xb7|\xbbP\xac\xfc\xb0\xea\xa4H\xa5\xc1\xaf\xb8\xa6b\xa4@\xb0_\xa1C' message3 = '\xA7\x41\xA6\x6E\xB6\xDC' c.drawString(100, 655, message1) c.drawString(100, 639, message2) hBoxText(message3 + ' MSung-Light' , c, 100, 600, 'MSung-Light', enc) #hBoxText(message3 + ' MHei-Medium', c, 100, 580, 'MHei-Medium', enc) c.setFont('Helvetica', 10) tx = c.beginText(100, 500) tx.textLines(""" This test document shows Traditional Chinese output from Reportlab PDF Library. You may use one Chinese font, MSung-Light, and a number of different encodings. The available encoding names (with comments from the PDF specification) are: encodings_cht = [ 'B5pc-H', # Macintosh, Big Five character set, Big Five encoding, # Script Manager code 2 'B5pc-V', # Vertical version of B5pc-H 'ETen-B5-H', # Microsoft Code Page 950 (lfCharSet 0x88), Big Five # character set with ETen extensions 'ETen-B5-V', # Vertical version of ETen-B5-H 'ETenms-B5-H', # Microsoft Code Page 950 (lfCharSet 0x88), Big Five # character set with ETen extensions; this uses proportional # forms for half-width Latin characters. 'ETenms-B5-V', # Vertical version of ETenms-B5-H 'CNS-EUC-H', # CNS 11643-1992 character set, EUC-TW encoding 'CNS-EUC-V', # Vertical version of CNS-EUC-H 'UniCNS-UCS2-H', # Unicode (UCS-2) encoding for the Adobe-CNS1 # character collection 'UniCNS-UCS2-V' # Vertical version of UniCNS-UCS2-H. ] The next 32 pages show the complete character set available in the encoding "ETen-B5-H". This is Big5 with the ETen extensions. ETen extensions are the most common extension to Big5 and include circled and roman numbers, Japanese hiragana and katakana, Cyrillic and fractions in rows C6-C8; and 7 extra characters and some line drawing characters in row F9. """) c.drawText(tx) c.setFont('Helvetica',10) c.drawCentredString(297, 36, 'Page %d' % c.getPageNumber()) c.showPage() # full Big5 code page c.setFont('Helvetica', 18) c.drawString(72,750, 'Characters available in Big 5') y = 500 for row in range(0xA1,0xFF): cc = Big5CodeChart(row, 'MSung-Light',enc) cc.charsPerRow = 16 cc.rows = 10 cc.codePoints = 160 cc.drawOn(c, 72, y) y = y - cc.height - 25 if y < 50: c.setFont('Helvetica',10) c.drawCentredString(297, 36, 'Page %d' % c.getPageNumber()) c.showPage() y = 600 c.save() if VERBOSE: print 'saved '+outputfile('test_multibyte_cht.pdf')
def test0(self): "A basic document drawing some strings" # if they do not have the Japanese font files, go away quietly from reportlab.pdfbase.cidfonts import CIDFont, findCMapFile enc = 'GB-EUC-H' try: findCMapFile(enc) except: #they don't have the font pack, return silently return pdfmetrics.registerFont(CIDFont('STSong-Light',enc)) c = Canvas(outputfile('test_multibyte_chs.pdf')) c.setFont('Helvetica', 30) c.drawString(100,700, 'Simplified Chinese Font Support') c.setFont('Helvetica', 10) c.drawString(100,680, 'Short sample: "Reportlab is cool!" (or so we are told)') # the two typefaces hBoxText('\xce\xc4\xbd\xa1\xb5\xc3\xb5\xbd\xc1\xcb \xc4\xc7\xd5\xfd\xba\xc3\xb0\xa2 \xce\xd2 \xba\xdc\xcf\xb2\xbb\xb6. Cool!', c, 100, 660, 'STSong-Light', enc) c.setFont('Helvetica', 10) tx = c.beginText(100, 500) tx.textLines(""" This test document shows Simplified Chinese output from the Reportlab PDF Library. You may use one Chinese font, STSong-Light, and a number of different encodings. The available encoding names (with comments from the PDF specification) are: encodings_chs = [ 'GB-EUC-H', # Microsoft Code Page 936 (lfCharSet 0x86), GB 2312-80 # character set, EUC-CN encoding 'GB-EUC-V', # Vertical version of GB-EUC-H 'GBpc-EUC-H', # Macintosh, GB 2312-80 character set, EUC-CN encoding, # Script Manager code 2 'GBpc-EUC-V', # Vertical version of GBpc-EUC-H 'GBK-EUC-H', # Microsoft Code Page 936 (lfCharSet 0x86), GBK character # set, GBK encoding 'GBK-EUC-V', # Vertical version of GBK-EUC-V 'UniGB-UCS2-H', # Unicode (UCS-2) encoding for the Adobe-GB1 # character collection 'UniGB-UCS2-V' # Vertical version of UniGB-UCS2-H. ] The next few pages show the complete character set available in the encoding "GB-EUC-H". This is the GB 2312-80 character set. """) c.drawText(tx) c.setFont('Helvetica',10) c.drawCentredString(297, 36, 'Page %d' % c.getPageNumber()) c.showPage() # full kuten chart in EUC c.setFont('Helvetica', 18) c.drawString(72,750, 'Characters available in GB 2312-80, EUC encoding') y = 600 for row in range(1, 95): KutenRowCodeChart(row, 'STSong-Light',enc).drawOn(c, 72, y) y = y - 125 if y < 50: c.setFont('Helvetica',10) c.drawCentredString(297, 36, 'Page %d' % c.getPageNumber()) c.showPage() y = 700 c.save() if VERBOSE: print 'saved '+outputfile('test_multibyte_chs.pdf')
def test0(self): "A basic document drawing some strings" c = Canvas(outputfile('test_multibyte_jpn.pdf')) c.setFont('Helvetica', 30) c.drawString(100,700, 'Japanese Font Support') c.setStrokeColor(colors.red) #unicode font automatically supplies the encoding pdfmetrics.registerFont(UnicodeCIDFont('HeiseiMin-W3')) msg = u'\u6771\u4EAC : Unicode font, unicode input' self.hDraw(c, msg, 'HeiseiMin-W3', 100, 600) msg = u'\u6771\u4EAC : Unicode font, utf8 input'.encode('utf8') self.hDraw(c, msg, 'HeiseiMin-W3', 100, 575) # now try verticals - this is broken, not sure how to make it # work in post Unicode world. pdfmetrics.registerFont(CIDFont('HeiseiMin-W3','90ms-RKSJ-V')) c.setFont('HeiseiMin-W3-90ms-RKSJ-V', 16) c.drawString(450, 650, '\223\214\213\236 vertical Shift-JIS') height = c.stringWidth('\223\214\213\236 vertical Shift-JIS', 'HeiseiMin-W3-90ms-RKSJ-V', 16) c.rect(450-8,650,16,-height) pdfmetrics.registerFont(CIDFont('HeiseiMin-W3','EUC-V')) c.setFont('HeiseiMin-W3-EUC-V', 16) c.drawString(475, 650, '\xC5\xEC\xB5\xFE vertical EUC') height = c.stringWidth('\xC5\xEC\xB5\xFE vertical EUC', 'HeiseiMin-W3-EUC-V', 16) c.rect(475-8,650,16,-height) from reportlab.platypus.paragraph import Paragraph from reportlab.lib.styles import ParagraphStyle jStyle = ParagraphStyle('jtext', fontName='HeiseiMin-W3', fontSize=12, wordWrap="CJK" ) gatwickText = '\xe3\x82\xac\xe3\x83\x88\xe3\x82\xa6\xe3\x82\xa3\xe3\x83\x83\xe3\x82\xaf\xe7\xa9\xba\xe6\xb8\xaf\xe3\x81\xa8\xe9\x80\xa3\xe7\xb5\xa1\xe9\x80\x9a\xe8\xb7\xaf\xe3\x81\xa7\xe7\x9b\xb4\xe7\xb5\x90\xe3\x81\x95\xe3\x82\x8c\xe3\x81\xa6\xe3\x81\x84\xe3\x82\x8b\xe5\x94\xaf\xe4\xb8\x80\xe3\x81\xae\xe3\x83\x9b\xe3\x83\x86\xe3\x83\xab\xe3\x81\xa7\xe3\x81\x82\xe3\x82\x8b\xe5\xbd\x93\xe3\x83\x9b\xe3\x83\x86\xe3\x83\xab\xe3\x81\xaf\xe3\x80\x81\xe8\xa1\x97\xe3\x81\xae\xe4\xb8\xad\xe5\xbf\x83\xe9\x83\xa8\xe3\x81\x8b\xe3\x82\x8930\xe5\x88\x86\xe3\x81\xae\xe5\xa0\xb4\xe6\x89\x80\xe3\x81\xab\xe3\x81\x94\xe3\x81\x96\xe3\x81\x84\xe3\x81\xbe\xe3\x81\x99\xe3\x80\x82\xe5\x85\xa8\xe5\xae\xa2\xe5\xae\xa4\xe3\x81\xab\xe9\xab\x98\xe9\x80\x9f\xe3\x82\xa4\xe3\x83\xb3\xe3\x82\xbf\xe3\x83\xbc\xe3\x83\x8d\xe3\x83\x83\xe3\x83\x88\xe7\x92\xb0\xe5\xa2\x83\xe3\x82\x92\xe5\xae\x8c\xe5\x82\x99\xe3\x81\x97\xe3\x81\xa6\xe3\x81\x8a\xe3\x82\x8a\xe3\x81\xbe\xe3\x81\x99\xe3\x80\x82\xe3\x83\x95\xe3\x82\xa1\xe3\x83\x9f\xe3\x83\xaa\xe3\x83\xbc\xe3\x83\xab\xe3\x83\xbc\xe3\x83\xa0\xe3\x81\xaf5\xe5\x90\x8d\xe6\xa7\x98\xe3\x81\xbe\xe3\x81\xa7\xe3\x81\x8a\xe6\xb3\x8a\xe3\x82\x8a\xe3\x81\x84\xe3\x81\x9f\xe3\x81\xa0\xe3\x81\x91\xe3\x81\xbe\xe3\x81\x99\xe3\x80\x82\xe3\x81\xbe\xe3\x81\x9f\xe3\x80\x81\xe3\x82\xa8\xe3\x82\xb0\xe3\x82\xbc\xe3\x82\xaf\xe3\x83\x86\xe3\x82\xa3\xe3\x83\x96\xe3\x83\xab\xe3\x83\xbc\xe3\x83\xa0\xe3\x81\xae\xe3\x81\x8a\xe5\xae\xa2\xe6\xa7\x98\xe3\x81\xaf\xe3\x80\x81\xe3\x82\xa8\xe3\x82\xb0\xe3\x82\xbc\xe3\x82\xaf\xe3\x83\x86\xe3\x82\xa3\xe3\x83\x96\xe3\x83\xa9\xe3\x82\xa6\xe3\x83\xb3\xe3\x82\xb8\xe3\x82\x92\xe3\x81\x94\xe5\x88\xa9\xe7\x94\xa8\xe3\x81\x84\xe3\x81\x9f\xe3\x81\xa0\xe3\x81\x91\xe3\x81\xbe\xe3\x81\x99\xe3\x80\x82\xe4\xba\x8b\xe5\x89\x8d\xe3\x81\xab\xe3\x81\x94\xe4\xba\x88\xe7\xb4\x84\xe3\x81\x84\xe3\x81\x9f\xe3\x81\xa0\xe3\x81\x91\xe3\x82\x8b\xe3\x82\xbf\xe3\x82\xa4\xe3\x83\xa0\xe3\x83\x88\xe3\x82\xa5\xe3\x83\x95\xe3\x83\xa9\xe3\x82\xa4\xe3\x83\xbb\xe3\x83\x91\xe3\x83\x83\xe3\x82\xb1\xe3\x83\xbc\xe3\x82\xb8\xe3\x81\xab\xe3\x81\xaf\xe3\x80\x81\xe7\xa9\xba\xe6\xb8\xaf\xe3\x81\xae\xe9\xa7\x90\xe8\xbb\x8a\xe6\x96\x99\xe9\x87\x91\xe3\x81\x8c\xe5\x90\xab\xe3\x81\xbe\xe3\x82\x8c\xe3\x81\xa6\xe3\x81\x8a\xe3\x82\x8a\xe3\x81\xbe\xe3\x81\x99\xe3\x80\x82' gatwickText2= '\xe3\x82\xac\xe3\x83\x88\xe3\x82\xa6\xe3\x82\xa3\xe3\x83\x83\xe3\x82\xaf<font color=red>\xe7\xa9\xba\xe6\xb8\xaf\xe3\x81\xa8\xe9\x80\xa3\xe7\xb5\xa1\xe9\x80\x9a\xe8\xb7\xaf\xe3\x81\xa7\xe7\x9b\xb4\xe7\xb5\x90</font>\xe3\x81\x95\xe3\x82\x8c\xe3\x81\xa6\xe3\x81\x84\xe3\x82\x8b\xe5\x94\xaf\xe4\xb8\x80\xe3\x81\xae\xe3\x83\x9b\xe3\x83\x86\xe3\x83\xab\xe3\x81\xa7\xe3\x81\x82\xe3\x82\x8b\xe5\xbd\x93\xe3\x83\x9b\xe3\x83\x86\xe3\x83\xab\xe3\x81\xaf\xe3\x80\x81\xe8\xa1\x97\xe3\x81\xae\xe4\xb8\xad\xe5\xbf\x83\xe9\x83\xa8\xe3\x81\x8b\xe3\x82\x8930\xe5\x88\x86\xe3\x81\xae\xe5\xa0\xb4\xe6\x89\x80\xe3\x81\xab\xe3\x81\x94\xe3\x81\x96\xe3\x81\x84\xe3\x81\xbe\xe3\x81\x99\xe3\x80\x82\xe5\x85\xa8\xe5\xae\xa2\xe5\xae\xa4\xe3\x81\xab\xe9\xab\x98\xe9\x80\x9f\xe3\x82\xa4\xe3\x83\xb3\xe3\x82\xbf\xe3\x83\xbc\xe3\x83\x8d\xe3\x83\x83\xe3\x83\x88<link fg="blue" href="http://www.reportlab.com">\xe7\x92\xb0\xe5\xa2\x83\xe3\x82\x92\xe5\xae\x8c\xe5\x82\x99</link>\xe3\x81\x97\xe3\x81\xa6<u>\xe3\x81\x8a\xe3\x82\x8a\xe3\x81\xbe\xe3\x81\x99</u>\xe3\x80\x82\xe3\x83\x95\xe3\x82\xa1\xe3\x83\x9f\xe3\x83\xaa\xe3\x83\xbc\xe3\x83\xab\xe3\x83\xbc\xe3\x83\xa0\xe3\x81\xaf5\xe5\x90\x8d\xe6\xa7\x98\xe3\x81\xbe\xe3\x81\xa7\xe3\x81\x8a\xe6\xb3\x8a\xe3\x82\x8a\xe3\x81\x84\xe3\x81\x9f\xe3\x81\xa0\xe3\x81\x91\xe3\x81\xbe\xe3\x81\x99\xe3\x80\x82\xe3\x81\xbe\xe3\x81\x9f\xe3\x80\x81\xe3\x82\xa8\xe3\x82\xb0\xe3\x82\xbc\xe3\x82\xaf\xe3\x83\x86\xe3\x82\xa3\xe3\x83\x96\xe3\x83\xab\xe3\x83\xbc\xe3\x83\xa0\xe3\x81\xae\xe3\x81\x8a\xe5\xae\xa2\xe6\xa7\x98\xe3\x81\xaf\xe3\x80\x81\xe3\x82\xa8\xe3\x82\xb0\xe3\x82\xbc\xe3\x82\xaf\xe3\x83\x86\xe3\x82\xa3\xe3\x83\x96\xe3\x83\xa9\xe3\x82\xa6\xe3\x83\xb3\xe3\x82\xb8\xe3\x82\x92\xe3\x81\x94\xe5\x88\xa9\xe7\x94\xa8\xe3\x81\x84\xe3\x81\x9f\xe3\x81\xa0\xe3\x81\x91\xe3\x81\xbe\xe3\x81\x99\xe3\x80\x82\xe4\xba\x8b\xe5\x89\x8d\xe3\x81\xab\xe3\x81\x94\xe4\xba\x88\xe7\xb4\x84\xe3\x81\x84\xe3\x81\x9f\xe3\x81\xa0\xe3\x81\x91\xe3\x82\x8b\xe3\x82\xbf\xe3\x82\xa4\xe3\x83\xa0\xe3\x83\x88\xe3\x82\xa5\xe3\x83\x95\xe3\x83\xa9\xe3\x82\xa4\xe3\x83\xbb\xe3\x83\x91\xe3\x83\x83\xe3\x82\xb1\xe3\x83\xbc\xe3\x82\xb8\xe3\x81\xab\xe3\x81\xaf\xe3\x80\x81\xe7\xa9\xba\xe6\xb8\xaf\xe3\x81\xae\xe9\xa7\x90\xe8\xbb\x8a\xe6\x96\x99\xe9\x87\x91\xe3\x81\x8c\xe5\x90\xab\xe3\x81\xbe\xe3\x82\x8c\xe3\x81\xa6\xe3\x81\x8a\xe3\x82\x8a\xe3\x81\xbe\xe3\x81\x99\xe3\x80\x82' c.setFont('HeiseiMin-W3', 12) jPara = Paragraph(gatwickText, jStyle) jPara.wrap(300, 200) jPara.drawOn(c, 100, 220) jPara = Paragraph(gatwickText2, jStyle) jPara.wrap(300, 200) jPara.drawOn(c, 100, 320) c.setFillColor(colors.purple) tx = c.beginText(100, 200) tx.setFont('Helvetica', 12) tx.textLines("""This document shows sample output in Japanese from the Reportlab PDF library. This page shows the two fonts available and tests our ability to measure the width of glyphs in both horizontal and vertical writing, with proportional and fixed-width characters. The red boxes should be the same width (or height) as the character strings they surround. The next pages show more samples and information. """) c.drawText(tx) c.setFont('Helvetica',10) c.drawCentredString(297, 36, 'Page %d' % c.getPageNumber()) c.showPage() c.setFont('Helvetica', 30) c.drawString(100,700, 'Japanese TrueType Font Support') msg = u'\u6771\u4EAC : Unicode font'.encode('utf8') msg2 = u'utf8 input 0123456789 ABCDEF'.encode('utf8') from reportlab.pdfbase.ttfonts import TTFont try: msmincho = TTFont('MS Mincho','msmincho.ttc',subfontIndex=0,asciiReadable=0) fn = ' file=msmincho.ttc subfont 0' except: try: msmincho = TTFont('MS Mincho','msmincho.ttf',asciiReadable=0) fn = 'file=msmincho.ttf' except: #Ubuntu - works on Lucid Lynx if xpdf-japanese installed try: msmincho = TTFont('MS Mincho','ttf-japanese-mincho.ttf') fn = 'file=msmincho.ttf' except: msmincho = None if msmincho is None: c.setFont('Helvetica', 12) c.drawString(100,600, 'Cannot find msmincho.ttf or msmincho.ttc') else: pdfmetrics.registerFont(msmincho) c.setFont('MS Mincho', 30) c.drawString(100,600, msg) c.drawString(100,570, msg2) c.drawString(100,540, fn) if fn.endswith('0'): try: msmincho1 = TTFont('MS Mincho 1','msmincho.ttc',subfontIndex=1,asciiPreload=0) pdfmetrics.registerFont(msmincho1) fn = ' file=msmincho.ttc subfont 1' c.setFont('MS Mincho 1',30) c.drawString(100,500,msg+fn) except: c.setFont('Helvetica',30) c.drawString(100,500,msg) c.drawString(100,470, msg2) c.drawString(100,440, fn) #test a paragraph with CJK and <br/> tags u = u'''<font color=red>\u30ac\u30c8\u30a6\u30a3\u30c3</font><br/><font color=blue>\u30af\u7a7a\u6e2f\u3068\u9023\u7d61\u901a</font><br/>\u8def\u3067\u76f4\u7d50\u3055\u308c\u3066\u3044\u308b\u552f<br/>\u4e00\u306e\u30db\u30c6\u30eb\u3067\u3042\u308b\u5f53\u30db\u30c6\u30eb\u306f\u3001\u8857\u306e\u4e2d\u5fc3\u90e8\u304b\u308930\u5206\u306e\u5834\u6240\u306b\u3054\u3056\u3044\u307e\u3059\u3002\u5168\u5ba2\u5ba4\u306b\u9ad8\u901f\u30a4\u30f3\u30bf\u30fc\u30cd\u30c3\u30c8<br/>\u74b0\u5883\u3092\u5b8c\u5099\u3057\u3066\u304a\u308a\u307e\u3059\u3002\u30d5\u30a1\u30df\u30ea\u30fc\u30eb\u30fc\u30e0\u306f5\u540d\u69d8\u307e\u3067\u304a\u6cca\u308a\u3044\u305f\u3060\u3051\u307e\u3059\u3002\u307e\u305f\u3001\u30a8\u30b0\u30bc\u30af\u30c6\u30a3\u30d6\u30eb\u30fc\u30e0\u306e\u304a\u5ba2\u69d8\u306f\u3001\u30a8\u30b0\u30bc\u30af\u30c6\u30a3\u30d6\u30e9\u30a6\u30f3\u30b8\u3092\u3054\u5229\u7528\u3044\u305f\u3060\u3051\u307e\u3059\u3002\u4e8b\u524d\u306b\u3054\u4e88\u7d04\u3044\u305f\u3060\u3051\u308b\u30bf\u30a4\u30e0\u30c8\u30a5\u30d5\u30e9\u30a4\u30fb\u30d1\u30c3\u30b1\u30fc\u30b8\u306b\u306f\u3001\u7a7a\u6e2f\u306e\u99d0\u8eca\u6599\u91d1\u304c\u542b\u307e\u308c\u3066\u304a\u308a\u307e\u3059\u3002''' jPara = Paragraph(u, jStyle) jPara.wrap(300, 500) jPara.drawOn(c, 100, 300) c.showPage() # realistic text sample ## sample = """Adobe Acrobat ##\x83h\x83L\x83\x85\x83\x81\x83\x93\x83g\x82\xaa\x8aJ\x82\xa9\x82\xc8\x82\xad\x82\xc4\x8d\xa2\x82\xc1\x82\xbd\x82\xb1\x82\xc6\x82\xcd ##\x82\xa0\x82\xe8\x82\xdc\x82\xb9\x82\xf1\x82\xa9\x81B\x8e\x96\x8b\xc6\x8cv\x89\xe6\x8f\x91\x81A\x89c\x8b\xc6\x83\x8c\x83|\x81[\x83g ##\x81A\x83J\x83^\x83\x8d\x83O\x82\xe2\x83p\x83\x93\x83t\x83\x8c\x83b\x83g\x82\xc8\x82\xc7\x90\xa7\x8d\xec\x95\xa8\x82\xcc\x8e\xed ##\x97\xde\x82\xc9\x82\xa9\x82\xa9\x82\xed\x82\xe7\x82\xb8\x81A ##\x83h\x83L\x83\x85\x83\x81\x83\x93\x83g\x82\xcdAdobe® Acrobat® 5.0\x82\xf0\x8eg\x82\xc1\x82\xc4Adobe PDF\x81iPortable Document ##Format\x81j\x83t\x83@\x83C\x83\x8b\x82\xc9\x95\xcf\x8a\xb7\x82\xb5\x82\xdc\x82\xb5\x82\xe5\x82\xa4\x81B\x96\xb3\x8f\x9e\x94z\x95z\x82\xcc ##Adobe Acrobat Reader\x82\xf0\x8eg\x82\xa6\x82\xce\x81A\x83n\x81[\x83h\x83E\x83F\x83A\x81A\x83\\\x83t\x83g\x83E\x83F\x83A\x82\xc9\x82\xa9 ##\x82\xa9\x82\xed\x82\xe7\x82\xb8\x81A\x92N\x82\xc5\x82\xe0\x82\xa0\x82\xc8\x82\xbd\x82\xcc\x83h\x83L\x83\x85\x83\x81\x83\x93\x83g\x82\xf0 ##\x83I\x83\x8a\x83W\x83i\x83\x8b\x82\xcc\x91\xcc\x8d\xd9\x82\xc5\x8aJ\x82\xad\x82\xb1\x82\xc6\x82\xaa\x82\xc5\x82\xab\x82\xdc\x82\xb7\x81B ##\x82\xa0\x82\xc8\x82\xbd\x82\xcc\x88\xd3\x90}\x82\xb5\x82\xbd\x82\xc6\x82\xa8\x82\xe8\x82\xc9\x8f\xee\x95\xf1\x82\xf0\x93`\x82\xa6\x82\xe9 ##\x82\xb1\x82\xc6\x82\xaa\x82\xc5\x82\xab\x82\xdc\x82\xb7\x81B ##\x82\xb3\x82\xe7\x82\xc9\x81AAdobe Acrobat 5.0\x82\xc5\x82\xcd\x81AWeb\x83u\x83\x89\x83E\x83U\x82\xa9\x82\xe7\x83R\x83\x81\x83\x93\x83g\x82\xe2 ##\x83}\x81[\x83N\x83A\x83b\x83v\x82\xf0\x8f\x91\x82\xab\x8d\x9e\x82\xf1\x82\xbe\x82\xe8\x81A\x93d\x8eq\x8f\x90\x96\xbc\x82\xf0\x8f\x91\x82\xab ##\x8d\x9e\x82\xdd\x81A\x8c\xb4\x96{\x82\xc6\x82\xb5\x82\xc4\x83\x8d\x81[\x83J\x83\x8b\x82\xc9\x95\xdb\x91\xb6\x82\xb7\x82\xe9\x82\xb1\x82\xc6\x82\xe0\x89\xc2\x94\\\x82\xc5\x82\xb7\x81B ##\x8a\xe9\x8b\xc6\x93\xe0\x82\xa0\x82\xe9\x82\xa2\x82\xcd\x8a\xe9\x8b\xc6\x82\xcc\x98g\x82\xf0\x92\xb4\x82\xa6\x82\xc4\x83`\x81[\x83\x80\x82\xc5 ##\x82\xcc\x83h\x83L\x83\x85\x83\x81\x83\x93\x83g\x83\x8f\x81[\x83N\x82\xcc\x90\xb6\x8eY\x90\xab\x82\xf0\x8c\xfc\x8f\xe3\x82\xb3\x82\xb9\x82\xe9\x82\xb1\x82\xc6\x82\xaa\x82\xc5\x82\xab\x82\xdc\x82\xb7\x81B ## ##Adobe Acrobat 5.0\x82\xc5\x8d\xec\x90\xac\x82\xb5\x82\xbdAdobe PDF\x82\xcd\x81A(Acrobat 5.0\x82\xc5\x82\xcc\x82\xdd\x83T\x83|\x81[\x83g ##\x82\xb5\x82\xc4\x82\xa2\x82\xe9\x88\xc3\x8d\x86\x89\xbb\x90\xdd\x92\xe8\x82\xf0\x8f\x9c\x82\xa2\x82\xc4\x82\xcd)\x8f]\x97\x88\x82\xdc ##\x82\xc5\x82\xcc\x83o\x81[\x83W\x83\x87\x83\x93(3\x82\xa8\x82\xe6\x82\xd1\x82S)\x82\xccAcrobat Reader\x82\xc5\x82\xe0\x8aJ\x82\xad ##\x82\xb1\x82\xc6\x82\xaa\x82\xc5\x82\xab\x82\xdc\x82\xb7\x81B\x8f\xee\x95\xf1\x8b\xa4\x97L\x82\xcc\x83c\x81[\x83\x8b\x82\xc6\x82\xb5 ##\x82\xc4\x81A\x82\xb3\x82\xe7\x82\xc9\x90i\x95\xe0\x82\xb5\x82\xbdAdobe Acrobat 5.0\x82\xf0\x81A\x8f]\x97\x88\x82\xcc\x8a\xc2\x8b\xab ##\x82\xc5\x82\xe0\x88\xc0\x90S\x82\xb5\x82\xc4\x82\xb2\x97\x98\x97p\x82\xa2\x82\xbd\x82\xbe\x82\xaf\x82\xdc\x82\xb7\x81B ## ##\x96{\x90\xbb\x95i\x82\xf0\x83l\x83b\x83g\x83\x8f\x81[\x83N\x82\xc8\x82\xc7\x82\xf0\x89\xee\x82\xb5\x82\xc4\x92\xbc\x90\xda\x82\xa0\x82\xe9 ##\x82\xa2\x82\xcd\x8a\xd4\x90\xda\x82\xc9\x95\xa1\x90\x94\x82\xcc\x92[\x96\x96\x82\xa9\x82\xe7\x8eg\x97p\x82\xb7\x82\xe9\x8f\xea\x8d\x87\x81A ##\x82\xbb\x82\xcc\x92[\x96\x96\x82\xc6\x93\xaf\x90\x94\x82\xcc\x83\x89\x83C\x83Z\x83\x93\x83X\x82\xf0\x82\xb2\x8dw\x93\xfc\x82\xad\x82\xbe ##\x82\xb3\x82\xa2\x81B\x96{\x90\xbb\x95i\x82\xcd\x83N\x83\x89\x83C\x83A\x83\x93\x83g\x97p\x83\\\x83t\x83g\x83E\x83F\x83A\x82\xc5\x82\xa0\x82\xe8 ##\x81A\x83T\x81[\x83o\x97p\x83\\\x83t\x83g\x83E\x83F\x83A\x82\xc6\x82\xb5\x82\xc4\x82\xa8\x8eg\x82\xa2\x82\xa2\x82\xbd\x82\xbe\x82\xad\x82\xb1\x82\xc6 ##\x82\xcd\x81A\x8f\xe3\x8bL\x95\xfb\x96@\x82\xc9\x82\xe6\x82\xe9\x88\xc8\x8aO\x81A\x8b\x96\x91\xf8\x82\xb3\x82\xea\x82\xc4\x82\xa2\x82\xdc\x82\xb9 ##\x82\xf1\x81B\x95\xa1\x90\x94\x82\xcc\x83\x89\x83C\x83Z\x83\x93\x83X\x82\xf0\x82\xb2\x8dw\x93\xfc\x82\xb3\x82\xea\x82\xe9\x8f\xea\x8d\x87\x82\xc9 ##\x82\xcd\x83\x89\x83C\x83Z\x83\x93\x83X\x83v\x83\x8d\x83O\x83\x89\x83\x80\x82\xf0\x82\xb2\x97\x98\x97p\x82\xc9\x82\xc8\x82\xe9\x82\xc6\x82\xa8\x93\xbe\x82\xc5\x82\xb7\x81B ## ## ##\x81y\x82\xa8\x92m\x82\xe7\x82\xb9\x81zMicrosoft Office XP\x82\xa9\x82\xe7PDF\x82\xf0\x8d\xec\x90\xac\x82\xb7\x82\xe9\x82\xc9\x82\xcd ##""" ## c.setFont('Helvetica', 24) ## c.drawString(100,750, "Sample text from Adobe's web site") ## tx = c.beginText(100,700) ## tx.setFont('Helvetica', 10) ## tx.textLine('Note: line wrapping has not been preserved and some lines may be wrapped in mid-word.') ## tx.textLine('We are just testing that we see Japanese and not random characters!') ## tx.setFont('HeiseiMin-W3-90ms-RKSJ-H',6) ## tx.textLines(sample) ## tx.setFont('Helvetica', 8) ## tx.textLine() ## tx.textLine() ## tx.textLines(""" ## This test document shows Japanese output from the Reportlab PDF Library. ## You may use two fonts, HeiseiMin-W3 and HeiseiKakuGo-W5, and a number of ## different encodings. ## ## The available encoding names (with comments from the PDF specification) are: ## encodings_jpn = [ ## # official encoding names, comments taken verbatim from PDF Spec ## '83pv-RKSJ-H', #Macintosh, JIS X 0208 character set with KanjiTalk6 ## #extensions, Shift-JIS encoding, Script Manager code 1 ## '90ms-RKSJ-H', #Microsoft Code Page 932 (lfCharSet 0x80), JIS X 0208 ## #character set with NEC and IBM extensions ## '90ms-RKSJ-V', #Vertical version of 90ms-RKSJ-H ## '90msp-RKSJ-H', #Same as 90ms-RKSJ-H, but replaces half-width Latin ## #characters with proportional forms ## '90msp-RKSJ-V', #Vertical version of 90msp-RKSJ-H ## '90pv-RKSJ-H', #Macintosh, JIS X 0208 character set with KanjiTalk7 ## #extensions, Shift-JIS encoding, Script Manager code 1 ## 'Add-RKSJ-H', #JIS X 0208 character set with Fujitsu FMR extensions, ## #Shift-JIS encoding ## 'Add-RKSJ-V', #Vertical version of Add-RKSJ-H ## 'EUC-H', #JIS X 0208 character set, EUC-JP encoding ## 'EUC-V', #Vertical version of EUC-H ## 'Ext-RKSJ-H', #JIS C 6226 (JIS78) character set with NEC extensions, ## #Shift-JIS encoding ## 'Ext-RKSJ-V', #Vertical version of Ext-RKSJ-H ## 'H', #JIS X 0208 character set, ISO-2022-JP encoding, ## 'V', #Vertical version of H ## 'UniJIS-UCS2-H', #Unicode (UCS-2) encoding for the Adobe-Japan1 character ## #collection ## 'UniJIS-UCS2-V', #Vertical version of UniJIS-UCS2-H ## 'UniJIS-UCS2-HW-H', #Same as UniJIS-UCS2-H, but replaces proportional Latin ## #characters with half-width forms ## 'UniJIS-UCS2-HW-V' #Vertical version of UniJIS-UCS2-HW-H ## ] ## ## The next few pages show the complete character set available in the encoding ## "90ms-RKSJ-H" - Shift-JIS with the standard Microsoft extensions. ## """) ## c.drawText(tx) ## ## c.setFont('Helvetica',10) ## c.drawCentredString(297, 36, 'Page %d' % c.getPageNumber()) ## ## ## ## c.showPage() from reportlab.lib import textsplit c.setFont('HeiseiMin-W3', 14) y = 700 c.drawString(70, y, 'cannot end line') y -= 20 for group in textsplit.CANNOT_START_LINE: c.drawString(70, y, group) y -= 20 c.setFont('Helvetica',10) c.drawString(70, y, ' '.join([ascii(x)[4:-1] for x in group])) c.setFont('HeiseiMin-W3', 14) y -= 20 y -= 20 c.drawString(70, y, 'cannot end line') y -= 20 for group in textsplit.CANNOT_END_LINE: c.drawString(70, y, group) y -= 20 c.setFont('Helvetica',10) c.drawString(70, y, ' '.join([ascii(x)[2:] for x in group])) c.setFont('HeiseiMin-W3', 14) y -= 20 c.showPage() #utf8 encoded paragraph sample2_uni = u'''\u30ac\u30c8\u30a6\u30a3\u30c3\u30af\u7a7a\u6e2f\u3068\u9023\u7d61\u901a \u8def\u3067\u76f4\u7d50\u3055\u308c\u3066\u3044\u308b\u552f\u4e00\u306e\u30db\u30c6\u30eb \u3067\u3042\u308b\u5f53\u30db\u30c6\u30eb\u306f\u3001\u8857\u306e\u4e2d\u5fc3\u90e8\u304b \u308930\u5206\u306e\u5834\u6240\u306b\u3054\u3056\u3044\u307e\u3059\u3002\u5168\u5ba2\u5ba4 \u306b\u9ad8\u901f\u30a4\u30f3\u30bf\u30fc\u30cd\u30c3\u30c8\u74b0\u5883\u3092\u5b8c\u5099 \u3057\u3066\u304a\u308a\u307e\u3059\u3002\u30d5\u30a1\u30df\u30ea\u30fc\u30eb\u30fc\u30e0 \u306f5\u540d\u69d8\u307e\u3067\u304a\u6cca\u308a\u3044\u305f\u3060\u3051\u307e\u3059\u3002 \u307e\u305f\u3001\u30a8\u30b0\u30bc\u30af\u30c6\u30a3\u30d6\u30eb\u30fc\u30e0\u306e\u304a \u5ba2\u69d8\u306f\u3001\u30a8\u30b0\u30bc\u30af\u30c6\u30a3\u30d6\u30e9\u30a6\u30f3\u30b8 \u3092\u3054\u5229\u7528\u3044\u305f\u3060\u3051\u307e\u3059\u3002\u4e8b\u524d\u306b\u3054 \u4e88\u7d04\u3044\u305f\u3060\u3051\u308b\u30bf\u30a4\u30e0\u30c8\u30a5\u30d5\u30e9\u30a4 \u30fb\u30d1\u30c3\u30b1\u30fc\u30b8\u306b\u306f\u3001\u7a7a\u6e2f\u306e\u99d0\u8eca\u6599 \u91d1\u304c\u542b\u307e\u308c\u3066\u304a\u308a\u307e\u3059\u3002''' oneline_uni = u''.join(sample2_uni.split()) sample2_utf8 = oneline_uni.encode('utf8') from reportlab.platypus import Paragraph from reportlab.lib.styles import ParagraphStyle jsty = ParagraphStyle('japanese',fontName='HeiseiMin-W3', wordWrap='CJK') jpara = Paragraph(oneline_uni, style=jsty) c.drawString(100, 710, 'Try to wrap a paragraph using a style with wordWrap="CJK"') w, h = jpara.wrap(400,400) jpara.drawOn(c, 100, 700 - h) #now try to split it... c.drawString(100, 510, 'Now try to split a paragraph as if over a page break') topPara, bottomPara = jpara.split(400, 30) w1, h1 = topPara.wrap(400, 30) topPara.drawOn(c, 100, 450) w2, h2 = bottomPara.wrap(400, 30) bottomPara.drawOn(c, 100, 400) #print 'split into heights %0.2f, %0.2f' % (topPara.height, bottomPara.height) ## c.showPage() ## ## ## # full kuten chart in EUC ## c.setFont('Helvetica', 24) ## c.drawString(72,750, 'Characters available in JIS 0208-1997') ## y = 600 ## for row in range(1, 95): ## KutenRowCodeChart(row, 'HeiseiMin-W3','EUC-H').drawOn(c, 72, y) ## y = y - 125 ## if y < 50: ## c.setFont('Helvetica',10) ## c.drawCentredString(297, 36, 'Page %d' % c.getPageNumber()) ## c.showPage() ## y = 700 ## ## c.showPage() #try with Unicode truetype - Mincho for starters ## import time ## started = time.clock() ## c.showPage() ## c.setFont('Helvetica',16) ## c.drawString(100,750, 'About to say Tokyo in MS Gothic...') ## ## from reportlab.pdfbase.ttfonts import TTFont, TTFontFile ## f = TTFontFile("msgothic.ttf") ## print f.name ## ## pdfmetrics.registerFont(TTFont(f.name, f)) ## ## utfText = u'Andr\202'.encode('utf8') ## c.setFont(f.name,16) ## c.drawString(100,700, utfText) ## ## ## #tokyoUCS2 = '\x67\x71\x4E\xAC' ## finished = time.clock() c.save() if VERBOSE: print('saved test_multibyte_jpn.pdf')
def test0(self): "A basic document drawing some strings" # if they do not have the Japanese font files, go away quietly try: from reportlab.pdfbase.cidfonts import CIDFont, findCMapFile findCMapFile("90ms-RKSJ-H") findCMapFile("90msp-RKSJ-H") findCMapFile("UniJIS-UCS2-H") findCMapFile("EUC-H") except: # don't have the font pack. return silently return pdfmetrics.registerFont(CIDFont("HeiseiMin-W3", "90ms-RKSJ-H")) pdfmetrics.registerFont(CIDFont("HeiseiKakuGo-W5", "90ms-RKSJ-H")) c = Canvas(outputfile("test_multibyte_jpn.pdf")) c.setFont("Helvetica", 30) c.drawString(100, 700, "Japanese Font Support") c.setStrokeColor(colors.red) # the two typefaces c.setFont("HeiseiMin-W3-90ms-RKSJ-H", 16) # this says "This is HeiseiMincho" in shift-JIS. Not all our readers # have a Japanese PC, so I escaped it. On a Japanese-capable # system, print the string to see Kanji message1 = "\202\261\202\352\202\315\225\275\220\254\226\276\222\251\202\305\202\267\201B" c.drawString(100, 675, message1) wid = pdfmetrics.stringWidth(message1, "HeiseiMin-W3-90ms-RKSJ-H", 16) c.rect(100, 675, wid, 16, stroke=1, fill=0) c.setFont("HeiseiKakuGo-W5-90ms-RKSJ-H", 16) # this says "This is HeiseiKakugo" in shift-JIS message2 = "\202\261\202\352\202\315\225\275\220\254\212p\203S\203V\203b\203N\202\305\202\267\201B" c.drawString(100, 650, message2) wid = pdfmetrics.stringWidth(message2, "HeiseiKakuGo-W5-90ms-RKSJ-H", 16) c.rect(100, 650, wid, 16, stroke=1, fill=0) self.hDraw(c, "\223\214\213\236 says Tokyo in Shift-JIS", "HeiseiMin-W3-90ms-RKSJ-H", 100, 600) pdfmetrics.registerFont(CIDFont("HeiseiMin-W3", "90msp-RKSJ-H")) self.hDraw(c, "\223\214\213\236, but in proportional Shift-JIS.", "HeiseiMin-W3-90msp-RKSJ-H", 100, 575) pdfmetrics.registerFont(CIDFont("HeiseiMin-W3", "EUC-H")) self.hDraw(c, "\xC5\xEC\xB5\xFE says Tokyo in EUC", "HeiseiMin-W3-EUC-H", 100, 550) if 0: # this is super-slow until we do encoding caching. pdfmetrics.registerFont(CIDFont("HeiseiMin-W3", "UniJIS-UCS2-H")) def asciiToUCS2(text): s = "" for ch in text: s = s + chr(0) + ch return s self.hDraw( c, "\x67\x71\x4E\xAC" + asciiToUCS2(" says Tokyo in UCS2"), "HeiseiMin-W3-UniJIS-UCS2-H", 100, 525 ) # now try verticals pdfmetrics.registerFont(CIDFont("HeiseiMin-W3", "90ms-RKSJ-V")) c.setFont("HeiseiMin-W3-90ms-RKSJ-V", 16) c.drawString(400, 650, "\223\214\213\236 vertical Shift-JIS") height = c.stringWidth("\223\214\213\236 vertical Shift-JIS", "HeiseiMin-W3-90ms-RKSJ-V", 16) c.rect(400 - 8, 650, 16, -height) pdfmetrics.registerFont(CIDFont("HeiseiMin-W3", "EUC-V")) c.setFont("HeiseiMin-W3-EUC-V", 16) c.drawString(425, 650, "\xC5\xEC\xB5\xFE vertical EUC") height = c.stringWidth("\xC5\xEC\xB5\xFE vertical EUC", "HeiseiMin-W3-EUC-V", 16) c.rect(425 - 8, 650, 16, -height) c.setFillColor(colors.purple) tx = c.beginText(100, 250) tx.setFont("Helvetica", 12) tx.textLines( """This document shows sample output in Japanese from the Reportlab PDF library. This page shows the two fonts available and tests our ability to measure the width of glyphs in both horizontal and vertical writing, with proportional and fixed-width characters. The red boxes should be the same width (or height) as the character strings they surround. The next pages show more samples and information. """ ) c.drawText(tx) c.setFont("Helvetica", 10) c.drawCentredString(297, 36, "Page %d" % c.getPageNumber()) c.showPage() # realistic text sample sample = """Adobe Acrobat \x83h\x83L\x83\x85\x83\x81\x83\x93\x83g\x82\xaa\x8aJ\x82\xa9\x82\xc8\x82\xad\x82\xc4\x8d\xa2\x82\xc1\x82\xbd\x82\xb1\x82\xc6\x82\xcd \x82\xa0\x82\xe8\x82\xdc\x82\xb9\x82\xf1\x82\xa9\x81B\x8e\x96\x8b\xc6\x8cv\x89\xe6\x8f\x91\x81A\x89c\x8b\xc6\x83\x8c\x83|\x81[\x83g \x81A\x83J\x83^\x83\x8d\x83O\x82\xe2\x83p\x83\x93\x83t\x83\x8c\x83b\x83g\x82\xc8\x82\xc7\x90\xa7\x8d\xec\x95\xa8\x82\xcc\x8e\xed \x97\xde\x82\xc9\x82\xa9\x82\xa9\x82\xed\x82\xe7\x82\xb8\x81A \x83h\x83L\x83\x85\x83\x81\x83\x93\x83g\x82\xcdAdobe® Acrobat® 5.0\x82\xf0\x8eg\x82\xc1\x82\xc4Adobe PDF\x81iPortable Document Format\x81j\x83t\x83@\x83C\x83\x8b\x82\xc9\x95\xcf\x8a\xb7\x82\xb5\x82\xdc\x82\xb5\x82\xe5\x82\xa4\x81B\x96\xb3\x8f\x9e\x94z\x95z\x82\xcc Adobe Acrobat Reader\x82\xf0\x8eg\x82\xa6\x82\xce\x81A\x83n\x81[\x83h\x83E\x83F\x83A\x81A\x83\\\x83t\x83g\x83E\x83F\x83A\x82\xc9\x82\xa9 \x82\xa9\x82\xed\x82\xe7\x82\xb8\x81A\x92N\x82\xc5\x82\xe0\x82\xa0\x82\xc8\x82\xbd\x82\xcc\x83h\x83L\x83\x85\x83\x81\x83\x93\x83g\x82\xf0 \x83I\x83\x8a\x83W\x83i\x83\x8b\x82\xcc\x91\xcc\x8d\xd9\x82\xc5\x8aJ\x82\xad\x82\xb1\x82\xc6\x82\xaa\x82\xc5\x82\xab\x82\xdc\x82\xb7\x81B \x82\xa0\x82\xc8\x82\xbd\x82\xcc\x88\xd3\x90}\x82\xb5\x82\xbd\x82\xc6\x82\xa8\x82\xe8\x82\xc9\x8f\xee\x95\xf1\x82\xf0\x93`\x82\xa6\x82\xe9 \x82\xb1\x82\xc6\x82\xaa\x82\xc5\x82\xab\x82\xdc\x82\xb7\x81B \x82\xb3\x82\xe7\x82\xc9\x81AAdobe Acrobat 5.0\x82\xc5\x82\xcd\x81AWeb\x83u\x83\x89\x83E\x83U\x82\xa9\x82\xe7\x83R\x83\x81\x83\x93\x83g\x82\xe2 \x83}\x81[\x83N\x83A\x83b\x83v\x82\xf0\x8f\x91\x82\xab\x8d\x9e\x82\xf1\x82\xbe\x82\xe8\x81A\x93d\x8eq\x8f\x90\x96\xbc\x82\xf0\x8f\x91\x82\xab \x8d\x9e\x82\xdd\x81A\x8c\xb4\x96{\x82\xc6\x82\xb5\x82\xc4\x83\x8d\x81[\x83J\x83\x8b\x82\xc9\x95\xdb\x91\xb6\x82\xb7\x82\xe9\x82\xb1\x82\xc6\x82\xe0\x89\xc2\x94\\\x82\xc5\x82\xb7\x81B \x8a\xe9\x8b\xc6\x93\xe0\x82\xa0\x82\xe9\x82\xa2\x82\xcd\x8a\xe9\x8b\xc6\x82\xcc\x98g\x82\xf0\x92\xb4\x82\xa6\x82\xc4\x83`\x81[\x83\x80\x82\xc5 \x82\xcc\x83h\x83L\x83\x85\x83\x81\x83\x93\x83g\x83\x8f\x81[\x83N\x82\xcc\x90\xb6\x8eY\x90\xab\x82\xf0\x8c\xfc\x8f\xe3\x82\xb3\x82\xb9\x82\xe9\x82\xb1\x82\xc6\x82\xaa\x82\xc5\x82\xab\x82\xdc\x82\xb7\x81B Adobe Acrobat 5.0\x82\xc5\x8d\xec\x90\xac\x82\xb5\x82\xbdAdobe PDF\x82\xcd\x81A(Acrobat 5.0\x82\xc5\x82\xcc\x82\xdd\x83T\x83|\x81[\x83g \x82\xb5\x82\xc4\x82\xa2\x82\xe9\x88\xc3\x8d\x86\x89\xbb\x90\xdd\x92\xe8\x82\xf0\x8f\x9c\x82\xa2\x82\xc4\x82\xcd)\x8f]\x97\x88\x82\xdc \x82\xc5\x82\xcc\x83o\x81[\x83W\x83\x87\x83\x93(3\x82\xa8\x82\xe6\x82\xd1\x82S)\x82\xccAcrobat Reader\x82\xc5\x82\xe0\x8aJ\x82\xad \x82\xb1\x82\xc6\x82\xaa\x82\xc5\x82\xab\x82\xdc\x82\xb7\x81B\x8f\xee\x95\xf1\x8b\xa4\x97L\x82\xcc\x83c\x81[\x83\x8b\x82\xc6\x82\xb5 \x82\xc4\x81A\x82\xb3\x82\xe7\x82\xc9\x90i\x95\xe0\x82\xb5\x82\xbdAdobe Acrobat 5.0\x82\xf0\x81A\x8f]\x97\x88\x82\xcc\x8a\xc2\x8b\xab \x82\xc5\x82\xe0\x88\xc0\x90S\x82\xb5\x82\xc4\x82\xb2\x97\x98\x97p\x82\xa2\x82\xbd\x82\xbe\x82\xaf\x82\xdc\x82\xb7\x81B \x96{\x90\xbb\x95i\x82\xf0\x83l\x83b\x83g\x83\x8f\x81[\x83N\x82\xc8\x82\xc7\x82\xf0\x89\xee\x82\xb5\x82\xc4\x92\xbc\x90\xda\x82\xa0\x82\xe9 \x82\xa2\x82\xcd\x8a\xd4\x90\xda\x82\xc9\x95\xa1\x90\x94\x82\xcc\x92[\x96\x96\x82\xa9\x82\xe7\x8eg\x97p\x82\xb7\x82\xe9\x8f\xea\x8d\x87\x81A \x82\xbb\x82\xcc\x92[\x96\x96\x82\xc6\x93\xaf\x90\x94\x82\xcc\x83\x89\x83C\x83Z\x83\x93\x83X\x82\xf0\x82\xb2\x8dw\x93\xfc\x82\xad\x82\xbe \x82\xb3\x82\xa2\x81B\x96{\x90\xbb\x95i\x82\xcd\x83N\x83\x89\x83C\x83A\x83\x93\x83g\x97p\x83\\\x83t\x83g\x83E\x83F\x83A\x82\xc5\x82\xa0\x82\xe8 \x81A\x83T\x81[\x83o\x97p\x83\\\x83t\x83g\x83E\x83F\x83A\x82\xc6\x82\xb5\x82\xc4\x82\xa8\x8eg\x82\xa2\x82\xa2\x82\xbd\x82\xbe\x82\xad\x82\xb1\x82\xc6 \x82\xcd\x81A\x8f\xe3\x8bL\x95\xfb\x96@\x82\xc9\x82\xe6\x82\xe9\x88\xc8\x8aO\x81A\x8b\x96\x91\xf8\x82\xb3\x82\xea\x82\xc4\x82\xa2\x82\xdc\x82\xb9 \x82\xf1\x81B\x95\xa1\x90\x94\x82\xcc\x83\x89\x83C\x83Z\x83\x93\x83X\x82\xf0\x82\xb2\x8dw\x93\xfc\x82\xb3\x82\xea\x82\xe9\x8f\xea\x8d\x87\x82\xc9 \x82\xcd\x83\x89\x83C\x83Z\x83\x93\x83X\x83v\x83\x8d\x83O\x83\x89\x83\x80\x82\xf0\x82\xb2\x97\x98\x97p\x82\xc9\x82\xc8\x82\xe9\x82\xc6\x82\xa8\x93\xbe\x82\xc5\x82\xb7\x81B \x81y\x82\xa8\x92m\x82\xe7\x82\xb9\x81zMicrosoft Office XP\x82\xa9\x82\xe7PDF\x82\xf0\x8d\xec\x90\xac\x82\xb7\x82\xe9\x82\xc9\x82\xcd """ c.setFont("Helvetica", 24) c.drawString(100, 750, "Sample text from Adobe's web site") tx = c.beginText(100, 700) tx.setFont("Helvetica", 10) tx.textLine("Note: line wrapping has not been preserved and some lines may be wrapped in mid-word.") tx.textLine("We are just testing that we see Japanese and not random characters!") tx.setFont("HeiseiMin-W3-90ms-RKSJ-H", 6) tx.textLines(sample) tx.setFont("Helvetica", 8) tx.textLine() tx.textLine() tx.textLines( """ This test document shows Japanese output from the Reportlab PDF Library. You may use two fonts, HeiseiMin-W3 and HeiseiKakuGo-W5, and a number of different encodings. The available encoding names (with comments from the PDF specification) are: encodings_jpn = [ # official encoding names, comments taken verbatim from PDF Spec '83pv-RKSJ-H', #Macintosh, JIS X 0208 character set with KanjiTalk6 #extensions, Shift-JIS encoding, Script Manager code 1 '90ms-RKSJ-H', #Microsoft Code Page 932 (lfCharSet 0x80), JIS X 0208 #character set with NEC and IBM extensions '90ms-RKSJ-V', #Vertical version of 90ms-RKSJ-H '90msp-RKSJ-H', #Same as 90ms-RKSJ-H, but replaces half-width Latin #characters with proportional forms '90msp-RKSJ-V', #Vertical version of 90msp-RKSJ-H '90pv-RKSJ-H', #Macintosh, JIS X 0208 character set with KanjiTalk7 #extensions, Shift-JIS encoding, Script Manager code 1 'Add-RKSJ-H', #JIS X 0208 character set with Fujitsu FMR extensions, #Shift-JIS encoding 'Add-RKSJ-V', #Vertical version of Add-RKSJ-H 'EUC-H', #JIS X 0208 character set, EUC-JP encoding 'EUC-V', #Vertical version of EUC-H 'Ext-RKSJ-H', #JIS C 6226 (JIS78) character set with NEC extensions, #Shift-JIS encoding 'Ext-RKSJ-V', #Vertical version of Ext-RKSJ-H 'H', #JIS X 0208 character set, ISO-2022-JP encoding, 'V', #Vertical version of H 'UniJIS-UCS2-H', #Unicode (UCS-2) encoding for the Adobe-Japan1 character #collection 'UniJIS-UCS2-V', #Vertical version of UniJIS-UCS2-H 'UniJIS-UCS2-HW-H', #Same as UniJIS-UCS2-H, but replaces proportional Latin #characters with half-width forms 'UniJIS-UCS2-HW-V' #Vertical version of UniJIS-UCS2-HW-H ] The next few pages show the complete character set available in the encoding "90ms-RKSJ-H" - Shift-JIS with the standard Microsoft extensions. """ ) c.drawText(tx) c.setFont("Helvetica", 10) c.drawCentredString(297, 36, "Page %d" % c.getPageNumber()) c.showPage() # full kuten chart in EUC c.setFont("Helvetica", 24) c.drawString(72, 750, "Characters available in JIS 0208-1997") y = 600 for row in range(1, 95): KutenRowCodeChart(row, "HeiseiMin-W3", "EUC-H").drawOn(c, 72, y) y = y - 125 if y < 50: c.setFont("Helvetica", 10) c.drawCentredString(297, 36, "Page %d" % c.getPageNumber()) c.showPage() y = 700 c.save() if VERBOSE: print "saved test_multibyte_jpn.pdf"