Exemplo n.º 1
0
def dotest(outputname, nostamp):
    pdf = FPDF()
    if nostamp:
        pdf._putinfo = lambda: common.test_putinfo(pdf)
    pdf.add_page()
    pdf.add_font('DejaVu',
                 '',
                 os.path.join(common.basepath, 'font/DejaVuSansCondensed.ttf'),
                 uni=True)
    pdf.set_font('DejaVu', '', 14)

    # Note: this line cause syntax error in Python 3.0-3.2
    text = u"""
Veľké písmená
A   Á   Ä   B   C   Č   D   Ď   DZ  DŽ  E   É   F   G   H   CH  I   Í   J   K   L   Ĺ   Ľ
Malé písmená
a   á   ä   b   c   č   d   ď   dz  dž  e   é   f   g   h   ch  i   í   j   k   l   ĺ   ľ
Veľké písmená
M   N   Ň   O   Ó   Ô   P   Q   R   Ŕ   S   Š   T   Ť   U   Ú   V   W   X   Y   Ý   Z   Ž
Malé písmená
m   n   ň   o   ó   ô   p   q   r   ŕ   s   š   t   ť   u   ú   v   w   x   y   ý   z   ž
"""

    pdf.write(8, text)
    pdf.ln(8)
    pdf.output(outputname, 'F')
Exemplo n.º 2
0
def dotest(outputname, nostamp):
    try:
        from bidi.algorithm import get_display
    except ImportError:
        from unittest import SkipTest
        raise SkipTest("Need python-bidi")
    pdf = FPDF()
    if nostamp:
        pdf._putinfo = lambda: common.test_putinfo(pdf)

    pdf.compress = False
    pdf.add_page()
    pdf.add_font('DejaVu', '', \
        os.path.join(common.basepath, 'font/DejaVuSans.ttf'), uni=True)
    pdf.set_font('DejaVu', '', 14)
    # this will be displayed wrong as actually it is stored LTR:
    text= u"این یک متن پارسی است. This is a Persian text !!"
    pdf.write(8, text)
    pdf.ln(8)
    # Reverse the RLT using the Bidirectional Algorithm to be displayed correctly:
    # (http://unicode.org/reports/tr9/)
    rtl_text = get_display(text)
    pdf.write(8, rtl_text)

    pdf.output(outputname, 'F')
Exemplo n.º 3
0
def dotest(outputname, nostamp):

    pdf = FPDF()
    pdf.set_font('Arial', '', 14)
    s = 'Texto largo que no cabe en esta celda pero que será ajustado'
    w = pdf.get_string_width(s)
    if not nostamp:
        print(s, w)
    assert round(w, 2) == 135.90
    font = os.path.join(common.basepath, 'font', 'DejaVuSans.ttf')
    pdf.add_font('DejaVu', '', font, uni=True)
    pdf.set_font('DejaVu', '', 14)
    s = u('Texto largo que no cabe en esta celda pero que será ajustado')
    w = pdf.get_string_width(s)
    if not nostamp:
        print(s, w)
    assert round(w, 2) == 153.64
Exemplo n.º 4
0
def dotest(outputname, nostamp):
    pdf = FPDF()
    if nostamp:
        pdf._putinfo = lambda: common.test_putinfo(pdf)

    pdf.add_page()
    # Add a Unicode font (uses UTF-8)
    pdf.add_font('DejaVu', '', \
        os.path.join(common.basepath, "font", 'DejaVuSansCondensed.ttf'), \
        uni = True)
    pdf.set_font('DejaVu', '', 14)

    # Load a UTF-8 string from a file and print it
    with open(os.path.join(common.basepath, "HelloWorld.txt"), "rb") as file:
        txt = file.read().decode("UTF-8")
    pdf.write(8, txt)

    pdf.output(outputname, 'F')
Exemplo n.º 5
0
def dotest(outputname, nostamp):
    gaefpdf.set_global("FPDF_CACHE_MODE", 1)
    pdf = FPDF()
    if nostamp:
        pdf._putinfo = lambda: common.test_putinfo(pdf)

    pdf.add_page()
    # Add a Unicode font (uses UTF-8)
    pdf.add_font('DejaVu', '', \
        os.path.join(common.basepath, "font", 'DejaVuSans.ttf'), \
        uni = True)
    pdf.set_font('DejaVu', '', 14)
    with open(os.path.join(common.basepath, "HelloWorld.txt"), "rb") as file:
        txt = file.read().decode("UTF-8")

    if not nostamp:
        text(pdf, txt, 100, nostamp)
    text(pdf, txt, 75, nostamp)
    text(pdf, txt, 125, nostamp)

    pdf.output(outputname, 'F')
Exemplo n.º 6
0
#!/usr/bin/env python
# -*- coding: utf8 -*-

from gaefpdf import FPDF
import sys

fn = 'unicode.pdf'

pdf = FPDF()
pdf.add_page()

# Add a DejaVu Unicode font (uses UTF-8)
# Supports more than 200 languages. For a coverage status see:
# http://dejavu.svn.sourceforge.net/viewvc/dejavu/trunk/dejavu-fonts/langcover.txt
pdf.add_font('DejaVu', '', 'DejaVuSansCondensed.ttf', uni=True)
pdf.set_font('DejaVu', '', 14)

text = u"""
English: Hello World
Greek: Γειά σου κόσμος
Polish: Witaj świecie
Portuguese: Olá mundo
Russian: Здравствуй, Мир
Vietnamese: Xin chào thế giới
Arabic: مرحبا العالم
Hebrew: שלום עולם
"""

for txt in text.split('\n'):
    pdf.write(8, txt)
    pdf.ln(8)
Exemplo n.º 7
0
pdf = FPDF()
pdf.add_page()

#font_dir = fpdf.FPDF_FONT_DIR
font_dir = os.path.join(base, 'font')

with open(os.path.join(base, 'HelloWorld.txt')) as file:
    txt = file.read()

# Add a Unicode font (uses UTF-8)
for font in os.listdir(font_dir):
    if font.lower().endswith('.ttf'):
        fontpath = os.path.join(font_dir, font)
        print(fontpath)
        t0 = time.time()
        pdf.add_font(font, '', fontpath, uni=True)
        t1 = time.time()
        pdf.set_font(font, '', 14)
        t2 = time.time()
        pdf.write(8, font)
        pdf.ln()
        pdf.write(8, txt)
        pdf.ln()
        t3 = time.time()
        print("ttf loading time", t1 - t0)
        print("ttf total time", t3 - t0)
        print()

fn = 'unifonts.pdf'
pdf.output(fn, 'F')
import os
Exemplo n.º 8
0
                            charToGlyph)
        self.saveChar = charToGlyph

    def getCMAP12(self, unicode_cmap_offset, glyphToChar, charToGlyph):
        TTFontFile.getCMAP12(self, unicode_cmap_offset, glyphToChar,
                             charToGlyph)
        self.saveChar = charToGlyph


pdf = FPDF()
pdf.compression = True
pdf.add_page()

#fontpath = "font/DroidSansFallback.ttf"
fontpath = "font/DejaVuSans.ttf"
pdf.add_font("font", '', fontpath, uni=True)
ttf = MyTTFontFile()
ttf.getMetrics(fontpath)

if sys.version_info >= (3, 0):
    unichr = chr

pdf.set_font("font", '', 10)

# create PDF with first 999 charters in font
cnt = 0
for char in ttf.saveChar:
    cnt += 1
    pdf.write(8, u"%03d) %06x - %c" % (cnt, char, char))
    pdf.ln()
    if cnt >= 999: