예제 #1
0
    def begin(self, name='', typ=''):
        styleSheet = getSampleStyleSheet()
        self.code = styleSheet['Code']
        self.bt = styleSheet['BodyText']
        self.story = []

        # Cover page
        t = time.gmtime(time.time())
        timeString = time.strftime("%Y-%m-%d %H:%M", t)
        self.story.append(
            Paragraph(
                '<font size=18>Documentation for %s "%s"</font>' % (typ, name),
                self.bt))
        self.story.append(
            Paragraph(
                '<font size=18>Generated by: graphdocpy.py version %s</font>' %
                __version__, self.bt))
        self.story.append(
            Paragraph('<font size=18>Date generated: %s</font>' % timeString,
                      self.bt))
        self.story.append(
            Paragraph('<font size=18>Format: PDF</font>', self.bt))
        self.story.append(PageBreak())

        # Table of contents
        toc = TableOfContents()
        self.story.append(toc)
        self.story.append(PageBreak())
예제 #2
0
    def begin(self, name='', typ=''):
        styleSheet = getSampleStyleSheet()
        self.code = styleSheet['Code']
        self.bt = styleSheet['BodyText']
        self.story = []

        # Cover page
        t = time.gmtime(time.time())
        timeString = time.strftime("%Y-%m-%d %H:%M", t)
        self.story.append(Paragraph('<font size=18>Documentation for %s "%s"</font>' % (typ, name), self.bt))
        self.story.append(Paragraph('<font size=18>Generated by: graphdocpy.py version %s</font>' %  __version__, self.bt))
        self.story.append(Paragraph('<font size=18>Date generated: %s</font>' % timeString, self.bt))
        self.story.append(Paragraph('<font size=18>Format: PDF</font>', self.bt))
        self.story.append(PageBreak())

        # Table of contents
        toc = TableOfContents()
        self.story.append(toc)
        self.story.append(PageBreak())
예제 #3
0
from wordaxe.rl.xpreformatted import XPreformatted


def myFirstPage(canvas, doc):
    canvas.saveState()
    canvas.restoreState()


def myLaterPages(canvas, doc):
    canvas.saveState()
    canvas.setFont('Times-Roman', 9)
    canvas.drawString(inch, 0.75 * inch, "Seite %d" % doc.page)
    canvas.restoreState()


stylesheet = getSampleStyleSheet()
for name in ["Heading1", "Heading2", "Heading3", "Code", "BodyText"]:
    style = stylesheet[name]
    style.language = 'DE'
    style.hyphenation = True

import wordaxe
from wordaxe.plugins.PyHyphenHyphenator import PyHyphenHyphenator

wordaxe.hyphRegistry['DE'] = PyHyphenHyphenator('de_DE', 5)


def makeParagraphs(txt, style):
    """Convert plain text into a list of paragraphs."""
    lines = txt.split("\n")
    retval = [
예제 #4
0
            l = l + 1

    def try_it(text,style,dedent,aW,aH):
        P=XPreformatted(text,style,dedent=dedent)
        dumpXPreformattedFrags(P)
        w,h = P.wrap(aW, aH)
        dumpXPreformattedLines(P)
        S = P.split(aW,aH)
        dumpXPreformattedLines(P)
        for s in S:
            s.wrap(aW,aH)
            dumpXPreformattedLines(s)
            aH = 500

    from wordaxe.rl.styles import getSampleStyleSheet, ParagraphStyle
    styleSheet = getSampleStyleSheet()
    B = styleSheet['BodyText']
    DTstyle = ParagraphStyle("discussiontext", parent=B)
    DTstyle.fontName= 'Helvetica'
    for (text,dedent,style, aW, aH, active) in [('''


The <font name=courier color=green>CMYK</font> or subtractive

method follows the way a printer
mixes three pigments (cyan, magenta, and yellow) to form colors.
Because mixing chemicals is more difficult than combining light there
is a fourth parameter for darkness.  For example a chemical
combination of the <font name=courier color=green>CMY</font> pigments generally never makes a perfect

black -- instead producing a muddy color -- so, to get black printers
예제 #5
0
    def test0(self):
        "This makes one long multi-page paragraph."

        # Build story.
        story = []

        styleSheet = getSampleStyleSheet()
        h1 = styleSheet['Heading1']
        h1.spaceBefore = 18
        bt = styleSheet['BodyText']
        bt.spaceBefore = 6

        story.append(Paragraph('Test of context-relative indentation', h1))

        story.append(Spacer(18, 18))

        story.append(Indenter(0, 0))
        story.append(
            Paragraph(
                "This should be indented 0 points at each edge. " +
                ("spam " * 25), bt))
        story.append(Indenter(0, 0))

        story.append(Indenter(36, 0))
        story.append(
            Paragraph(
                "This should be indented 36 points at the left. " +
                ("spam " * 25), bt))
        story.append(Indenter(-36, 0))

        story.append(Indenter(0, 36))
        story.append(
            Paragraph(
                "This should be indented 36 points at the right. " +
                ("spam " * 25), bt))
        story.append(Indenter(0, -36))

        story.append(Indenter(36, 36))
        story.append(
            Paragraph(
                "This should be indented 36 points at each edge. " +
                ("spam " * 25), bt))
        story.append(Indenter(36, 36))
        story.append(
            Paragraph(
                "This should be indented a FURTHER 36 points at each edge. " +
                ("spam " * 25), bt))
        story.append(Indenter(-72, -72))

        story.append(
            Paragraph(
                "This should be back to normal at each edge. " +
                ("spam " * 25), bt))

        story.append(Indenter(36, 36))
        story.append(
            Paragraph(("""This should be indented 36 points at the left
        and right.  It should run over more than one page and the indent should
        continue on the next page. """ + (random.randint(0, 10) * 'x') + ' ') *
                      20, bt))
        story.append(Indenter(-36, -36))

        story.append(NextPageTemplate('updown'))
        story.append(FrameBreak())
        story.append(
            Paragraph('Another test of context-relative indentation', h1))
        story.append(NextPageTemplate(
            'normal'))  # so NEXT page is different template...
        story.append(
            Paragraph(
                """This time we see if the indent level is continued across
            frames...this page has 2 frames, let's see if it carries top to bottom. Then
            onto a totally different template.""", bt))

        story.append(Indenter(0, 0))
        story.append(
            Paragraph(
                "This should be indented 0 points at each edge. " +
                ("spam " * 25), bt))
        story.append(Indenter(0, 0))
        story.append(Indenter(36, 72))
        story.append(
            Paragraph(("""This should be indented 36 points at the left
        and 72 at the right.  It should run over more than one frame and one page, and the indent should
        continue on the next page. """ + (random.randint(0, 10) * 'x') + ' ') *
                      35, bt))

        story.append(Indenter(-36, -72))
        story.append(
            Paragraph(
                "This should be back to normal at each edge. " +
                ("spam " * 25), bt))
        doc = MyDocTemplate(outputfile('test_platypus_indents.pdf'))
        doc.multiBuild(story)
예제 #6
0
    def generatePDF(self, model_data):
        """
        Dieses Beispiel zeigt nicht annähernd die Möglichkeiten von ReportLab!
        Es demonstriert nur, wie einfach es sein kann.
        """
        stylesheet = getSampleStyleSheet()
        # Formatstil für die Überschrift festlegen
        sth1 = stylesheet['Heading1']
        # Formatstil für den Absatz festlegen
        stn = stylesheet['Normal']
        stn.fontName = 'Helvetica'
        stn.fontSize = 10
        stn.leading = 12
        #print stn.spaceAfter
        #print stn.spaceBefore
        #print stn.leading

        print("TODO: Why is the text so close to the top of the cells?")

        # Automatische Silbentrennung für diesen Stil einschalten
        stn.language = 'DE'
        stn.hyphenation = True

        # Wir machen erstmal einen Fake,
        # nämlich den ASCII-Text zeilenweise.
        self.generateDUMP(model_data)
        pure_text = "".join(self.text)
        story = []
        para = Paragraph(
            "Beispiel für einen Datenbankbericht".decode("iso-8859-1"), sth1)
        '''
        story.append(para)
        
        para = Paragraph("""Dies ist ein längerer Absatz, der eigentlich nur den Zweck hat,
die automatische Silbentrennung von WordAxe zu demonstrieren. Aus diesem Grund enthält dieser
Absatz auch einige besonders schöne lange Wörter wie etwa "Donaudampfschifffahrtsgesellschaftskapitän"
oder "Bundeskanzleramt" oder "Landesgesundheitsbehörden", sogar gleich mehrfach:
Schiff Dampfschiff Dampfschifffahrt Donaudampfschiffahrt oder Donaudampfschiffahrtsgesellschaft
Donaudampfschiffahrtsgesellschaftsvorsitzender (Ha! damit habt Ihr wohl nicht gerechnet, oder?)
und nebenbei auch HTML-Formatierung wie <b>fett</b> oder <i>kursiv!</i>
Mal sehen, ob das Euro-Zeichen geht - ich befürchte aber, dass das auf Anhieb nicht funktioniert.
Hier kommt es: € - nee, das sehe ich schon im Quelltext nicht richtig.
""".decode("iso-8859-1"), stn)        
        story.append(para)
        for line in pure_text.splitlines():
            para = Paragraph(line.decode("iso-8859-1"), stn)
            story.append(para)
        '''

        # Jetzt mal anders:
        # Ausgabe als Master-Detail-Liste, wobei die Details
        # eine Spalte weiter eingerückt sind.
        if model_data:
            headers1 = [Paragraph(toUnicode(x), stn) for x in DEPT.headers()]
            headers2 = [None] + [
                Paragraph(toUnicode(x), stn) for x in EMP.headers()
            ]
            nColumns = max(len(headers1), len(headers2))
            fill1 = ([None] * (nColumns - len(headers1)))
            fill2 = ([None] * (nColumns - len(headers2)))
            headers1 += fill1
            headers2 += fill2
            tableData = [headers1, headers2]
            colWidths = [None] * nColumns
            colWidths[-1] = 40 * mm
            nRows = len(model_data)
            tableStyle = TableStyle([
                ('BOX', (0, 0), (-1, -1), 1, colors.black),
                ('BACKGROUND', (0, 0), (-1, 1), colors.orange),
                ('BACKGROUND', (0, 1), (-1, 1), colors.yellow),
                ('INNERGRID', (0, 0), (-1, -1), 0.5, colors.black),
                ('LEFTPADDING', (0, 0), (-1, -1), 3),
                ('RIGHTPADDING', (0, 0), (-1, -1), 3),
                ('VALIGN', (0, 0), (-1, -1), 'TOP'),
            ])
            for dept in model_data:
                tableData.append(dept.genParagraphList(stn) + fill1)
                tableStyle.add('BACKGROUND', (0, len(tableData) - 1),
                               (-1, len(tableData) - 1), colors.orange)
                for emp in dept.children["emp"]:
                    tableData.append([""] + emp.genParagraphList(stn) + fill2)
            table = LongTable(tableData,
                              style=tableStyle,
                              colWidths=colWidths,
                              repeatRows=2)
            story.append(table)
        self.story = story
예제 #7
0
 def begin(self, name='', typ=''):
     styleSheet = getSampleStyleSheet()
     self.code = styleSheet['Code']
     self.bt = styleSheet['BodyText']
     self.story = []
예제 #8
0
def run():
    for language, fname, title in [
        ("DE", "dokumentation_de", u"wordaxe Anleitung (deutsch)"),
        ("EN", "dokumentation_en", u"wordaxe User Guide (english)"),
    ]:
        print("Generating", fname + ".pdf")
        stylesheet = getSampleStyleSheet()
        for name in ["Heading1", "Heading2", "Heading3", "Code", "BodyText"]:
            style = stylesheet[name]
            style.language = language
            style.hyphenation = True

        doc = SimpleDocTemplate(fname + ".pdf",
                                title=title,
                                author="Henning von Bargen",
                                pagesize=pagesizes.portrait(pagesizes.A4),
                                allowSplitting=1)

        # Content einlesen und parsen

        content = open(fname + ".txt").read()

        story = []
        frags = []
        opts = []

        def emit(f, o):
            if len(f):
                if "PRE" in o:
                    # Preformatted
                    txt = "\n".join(f)
                    story.append(XPreformatted(txt, stylesheet["Code"]))
                else:
                    txt = " ".join([s.strip() for s in f])
                    story.append(Paragraph(txt, stylesheet["BodyText"]))
            del o[:]
            del f[:]

        for zeile in content.splitlines():
            # Umkodieren nach utf8
            zeile = zeile.decode("iso-8859-1").encode("utf8")
            zstrip = zeile.strip()
            # Überschrift?
            level = 0
            while zeile.startswith("=") and zeile.endswith("="):
                level += 1
                zeile = zeile[1:-1]
            if level > 0:
                emit(frags, opts)
                stil = "Heading%d" % level
                story.append(Paragraph(zeile, stylesheet[stil]))
            elif zstrip == "" and not "PRE" in opts:
                emit(frags, opts)
            elif zstrip == "{{{":
                emit(frags, opts)
                opts.append("PRE")
            elif zstrip == "}}}":
                emit(frags, opts)
            else:
                frags.append(zeile)

        emit(frags, opts)
        doc.build(story, onFirstPage=myFirstPage, onLaterPages=myLaterPages)
예제 #9
0
 def begin(self, name='', typ=''):
     styleSheet = getSampleStyleSheet()
     self.code = styleSheet['Code']
     self.bt = styleSheet['BodyText']
     self.story = []