Ejemplo n.º 1
0
    def make_headerFooterDiffPages():
        doc = Document()
        ss = doc.StyleSheet
        section = Section()
        doc.Sections.append(section)

        section.FirstHeader.append('This is the header for the first page.')
        section.FirstFooter.append('This is the footer for the first page.')

        section.Header.append(
            'This is the header that will appear on subsequent pages.')
        section.Footer.append(
            'This is the footer that will appear on subsequent pages.')

        p = Paragraph(ss.ParagraphStyles.Heading1)
        p.append('Example 6')
        section.append(p)

        #    blank paragraphs are just empty strings
        section.append('')

        p = Paragraph(ss.ParagraphStyles.Normal)
        p.append(
            'This document has different headers and footers for the first and then subsequent pages. '
            'If you insert a page break you should see a different header and footer.'
        )
        section.append(p)

        return doc
Ejemplo n.º 2
0
    def make_headerFooterDiffPagesAndSections():
        doc = Document()
        ss = doc.StyleSheet
        section = Section()
        doc.Sections.append(section)

        section.FirstHeader.append('This is the header for the first page.')
        section.FirstFooter.append('This is the footer for the first page.')

        section.Header.append(
            'This is the header that will appear on subsequent pages.')
        section.Footer.append(
            'This is the footer that will appear on subsequent pages.')

        p = Paragraph(ss.ParagraphStyles.Heading1)
        p.append('Example 7')
        section.append(p)

        p = Paragraph(ss.ParagraphStyles.Normal)
        p.append(
            'This document has different headers and footers for the first and then subsequent pages. '
            'If you insert a page break you should see a different header and footer.'
        )
        section.append(p)

        p = Paragraph(ss.ParagraphStyles.Normal,
                      ParagraphPropertySet().SetPageBreakBefore(True))
        p.append('This should be page 2 '
                 'with the subsequent headers and footers.')
        section.append(p)

        section = Section(break_type=Section.PAGE, first_page_number=1)
        doc.Sections.append(section)

        section.FirstHeader.append(
            'This is the header for the first page of the second section.')
        section.FirstFooter.append(
            'This is the footer for the first page of the second section.')

        section.Header.append(
            'This is the header that will appear on subsequent pages for the second section.'
        )
        p = Paragraph(
            'This is the footer that will appear on subsequent pages for the second section.',
            LINE)
        p.append(PAGE_NUMBER, ' of ', SECTION_PAGES)
        section.Footer.append(p)

        section.append('This is the first page')

        p = Paragraph(ParagraphPropertySet().SetPageBreakBefore(True),
                      'This is the second page')
        section.append(p)

        return doc
Ejemplo n.º 3
0
    def export(self, tempdir):
        self.outpath = os.path.join(tempdir, 'export.rtf')
        self.imgnum = 1

        doc = Document()
        self.ss = doc.StyleSheet

        export_title = u'Export (%d records)' % len(self.objs)

        on_empty_page = True

        if self.custom_order:
            emitter = self.custom_emit_fields
        else:
            emitter = self.record_emit_fields

        count = 0
        size = len(self.objs)
        while len(self.objs) > 0:
            count += 1
            yield "Formatting record %d of %d" % (count, size)
            r = self.objs.pop(0)

            if on_empty_page:
                section = Section()
            else:
                section = Section(break_type=Section.PAGE)
            on_empty_page = False

            p = Paragraph(self.ss.ParagraphStyles.Heading1)
            p.append(r.title)
            section.append(p)

            for p in self.emit_paragraphs(r, emitter(r)):
                section.append(p)

            if len(section) > 0:
                doc.Sections.append(section)

        fd = open(self.outpath, "wb")
        doc.write(fd)
        fd.close()
Ejemplo n.º 4
0
 def render(self, output):
     document = Document()
     section = Section()
     for o in output:
         section.append(o)
     document.Sections.append(section)
     renderer = Renderer()
     renderer.Write(document, StringIO())  # Setup instance variables
     renderer._doc = document
     renderer._fout = StringIO()
     renderer._CurrentStyle = ""
     renderer._WriteSection(section, True, False)
     return renderer._fout.getvalue()
Ejemplo n.º 5
0
def main():
    """
    Main processing for command line invocation
    """
    cmdline = process_command_line()
    cfg = json.load(file(cmdline.configfile))
    if cmdline.lang:
        langs = [cmdline.lang]
    else:
        langs = LANGS
    
    if cmdline.wiki:
        for lang in sorted(langs):
            conv = SubdimensionsToWikiConverter(lang,cfg[lang])
            conv.create_cms_schemas()
            conv.create_lms()
            ofname = lang + '_' + cmdline.outfile
            lines = conv.get_wiki_pages()
            with codecs.open(ofname,"w",encoding="utf-8") as of:
                for line in lines:
                    print >> of, line
    else:
        plog = {}
        if cmdline.prevlog:
            plog = json.load(file(cmdline.prevlog),encoding='utf-8')
        doc = Document()
        section = Section()
        doc.Sections.append(section)
        ss = doc.StyleSheet
        logdoc = {}
        for lang in sorted(langs):
            conv = SubdimensionsConverter(lang,cfg[lang],plog)
            conv.set_ss(ss)
            conv.add_tables(section)
            conv.add_to_json(logdoc)
        DR = Renderer()
        ofile = codecs.open(cmdline.outfile, "w", encoding="utf-8")
        DR.Write( doc, ofile )
        lfile = codecs.open(cmdline.outfile+'.log', "w", encoding="utf-8")
        json.dump(logdoc, lfile, indent=2, encoding='utf-8')
    
    return 0
Ejemplo n.º 6
0
    def make_headerFooterSimple():
        doc = Document()
        ss = doc.StyleSheet
        section = Section()
        doc.Sections.append(section)

        section.Header.append('This is the header')
        section.Footer.append('This is the footer')

        p = Paragraph(ss.ParagraphStyles.Heading1)
        p.append('Example 5')
        section.append(p)

        #    blank paragraphs are just empty strings
        section.append('')

        p = Paragraph(ss.ParagraphStyles.Normal)
        p.append('This document has a header and a footer.')
        section.append(p)

        return doc
# Start here

print str(datetime.datetime.now())
print "Creating UFID dictionary"
ufid_dictionary = vt.make_ufid_dictionary()
print "Dictionary has", len(ufid_dictionary), "people"
print str(datetime.datetime.now())
csvReader = csv.reader(open('Award Data Collection Effort Sample.csv', 'rb'),
                       delimiter='|')
n = 0

previousYear = None
previousRFA = None
report_title = 'Sample CTSI Pilot Award Report'

doc = Document()
ss = doc.StyleSheet

# Improve the style sheet

ps = ParagraphStyle('Title',
                    TextStyle(TextPropertySet(ss.Fonts.Arial, 44)).Copy(),
                    ParagraphPropertySet(space_before=60, space_after=60))
ss.ParagraphStyles.append(ps)
ps = ParagraphStyle('Heading 3',
                    TextStyle(TextPropertySet(ss.Fonts.Arial, 22)).Copy(),
                    ParagraphPropertySet(space_before=60, space_after=60))
ss.ParagraphStyles.append(ps)
ps = ParagraphStyle('Heading 4',
                    TextStyle(TextPropertySet(ss.Fonts.Arial, 22)).Copy(),
                    ParagraphPropertySet(space_before=60, space_after=60))
Ejemplo n.º 8
0
 def initializeDoc():
     doc = Document()
     section = Section()
     doc.Sections.append(section)
     return (doc, section, doc.StyleSheet)
Ejemplo n.º 9
0
def generateReport(window, plot, evals, lagranges):
    """Save session report to rtf document
    """
    fileName = Qt.QFileDialog.getSaveFileName(window, u'Сохранить отчет', '.',
                                              'Word (*.doc)')
    if not fileName.isNull():
        doc = Document()
        #ss      = doc.StyleSheet
        section = Section()
        doc.Sections.append(section)

        minX, maxX, minY, maxY = plot.getBounds()

        section.append(u'Полотно растеризации:')
        section.append('')
        table = Table(TabPropertySet.DEFAULT_WIDTH, \
                      TabPropertySet.DEFAULT_WIDTH * 3, \
                      TabPropertySet.DEFAULT_WIDTH * 3)
        table.AddRow(Cell(Paragraph(u'ось')), Cell(Paragraph(u'от')),
                     Cell(Paragraph(u'до')))
        table.AddRow(Cell(Paragraph('x')), Cell(Paragraph(str(minX))),
                     Cell(Paragraph(str(maxX))))
        table.AddRow(Cell(Paragraph('y')), Cell(Paragraph(str(minY))),
                     Cell(Paragraph(str(maxY))))
        section.append(table)
        section.append(u'Детализация: %d %s на график' %
                       (plot.width(),
                        langMorph(plot.width(),
                                  (u'точек', u'точка', u'точки'))))

        section.append(Paragraph(getPlotImage(plot)))

        section.append('')
        section.append(u'%d %s:' %
                       (len(evals),
                        langMorph(len(evals),
                                  (u'функций', u'функция', u'функции'))))
        #for s in evals:
        #    section.append('f(x) = %s' % s)
        for i in evals:
            section.append('f(x) = %s' % i.getExpression())

        section.append('')
        section.append(u'%d %s Лагранжа' %
                       (len(lagranges),
                        langMorph(len(lagranges),
                                  (u'полиномов', u'полином', u'полинома'))))
        for i in lagranges:
            points = i.count()
            section.append(ur'\u2014' * 30)
            section.append(
                u'%d %s:' %
                (points, langMorph(points, (u'точек', u'точка', u'точки'))))
            table = Table(TabPropertySet.DEFAULT_WIDTH / 2, \
                          TabPropertySet.DEFAULT_WIDTH * 3, \
                          TabPropertySet.DEFAULT_WIDTH * 3)
            for j in xrange(points):
                table.AddRow(Cell(Paragraph('%d' % j)),
                             Cell(Paragraph('%g' % i.pointX[j])),
                             Cell(Paragraph('%g' % i.pointY[j])))
            section.append(table)
            section.append(u'L(x) = %s' % i.toString())

        Renderer().Write(doc, file(unicode(fileName), 'w'))