コード例 #1
0
ファイル: test_headerfooter.py プロジェクト: vildritt/pyrtf
    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
コード例 #2
0
ファイル: test_headerfooter.py プロジェクト: vildritt/pyrtf
    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
コード例 #3
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()
コード例 #4
0
ファイル: test_headerfooter.py プロジェクト: vildritt/pyrtf
    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
コード例 #5
0
def createSection(document, survey, request, first_page_number=1):
    t = lambda txt: "".join(
        ["\u%s?" % str(ord(e)) for e in translate(txt, context=request)])
    section = Section(break_type=Section.PAGE,
                      first_page_number=first_page_number)
    footer_txt = t(
        _("report_survey_revision",
            default=u"This report was based on the OiRA Tool '${title}' "\
                    u"of revision date ${date}.",
            mapping={"title": survey.published[1],
                    "date": formatDate(request, survey.published[2])}))

    header = Table(4750, 4750)
    c1 = Cell(
        Paragraph(document.StyleSheet.ParagraphStyles.Footer,
                  survey.published[1]))

    pp = ParagraphPropertySet
    header_props = pp(alignment=pp.RIGHT)
    c2 = Cell(
        Paragraph(document.StyleSheet.ParagraphStyles.Footer, header_props,
                  formatDate(request, datetime.today())))
    header.AddRow(c1, c2)
    section.Header.append(header)

    footer = Table(9000, 500)
    # rtfng does not like unicode footers
    c1 = Cell(
        Paragraph(document.StyleSheet.ParagraphStyles.Footer,
                  pp(alignment=pp.LEFT), footer_txt))

    c2 = Cell(Paragraph(pp(alignment=pp.RIGHT), PAGE_NUMBER))
    footer.AddRow(c1, c2)
    section.Footer.append(footer)
    document.Sections.append(section)
    return section
コード例 #6
0
def createIdentificationReportSection(document, survey, request):
    t = lambda txt: "".join(
        ["\u%s?" % str(ord(e)) for e in translate(txt, context=request)])
    section = Section()

    footer_txt = t(
        _("report_identification_revision",
          default=u"This document was based on the OiRA Tool '${title}' of "
          u"revision date ${date}.",
          mapping={
              "title": survey.published[1],
              "date": formatDate(request, survey.published[2])
          }))
    header = Table(4750, 4750)
    c1 = Cell(
        Paragraph(document.StyleSheet.ParagraphStyles.Footer,
                  SessionManager.session.title))

    pp = ParagraphPropertySet
    header_props = pp(alignment=pp.RIGHT)
    c2 = Cell(
        Paragraph(document.StyleSheet.ParagraphStyles.Footer, header_props,
                  formatDate(request, datetime.today())))
    header.AddRow(c1, c2)
    section.Header.append(header)

    footer = Table(9000, 500)
    c1 = Cell(
        Paragraph(document.StyleSheet.ParagraphStyles.Footer,
                  pp(alignment=pp.LEFT), footer_txt))
    c2 = Cell(Paragraph(pp(alignment=pp.RIGHT), PAGE_NUMBER))
    footer.AddRow(c1, c2)
    section.Footer.append(footer)
    section.SetBreakType(section.PAGE)
    document.Sections.append(section)
    return section
コード例 #7
0
# 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))
ss.ParagraphStyles.append(ps)

section = Section()
doc.Sections.append(section)

section.FirstHeader.append(' ')
p = Paragraph(ss.ParagraphStyles.Normal)
p.append(PAGE_NUMBER, ' of ', TOTAL_PAGES)
section.FirstFooter.append(p)

section.Header.append(report_title)
p = Paragraph(ss.ParagraphStyles.Normal)
p.append(PAGE_NUMBER, ' of ', TOTAL_PAGES)
section.Footer.append(p)

p = Paragraph(ss.ParagraphStyles.Title)
p.append(report_title)
section.append(p)
コード例 #8
0
print str(datetime.datetime.now())

thin_edge = BorderPropertySet(width=11, style=BorderPropertySet.SINGLE)
topBottom = FramePropertySet(top=thin_edge, bottom=thin_edge)
bottom_frame = FramePropertySet(bottom=thin_edge)
bottom_right_frame = FramePropertySet(right=thin_edge, bottom=thin_edge)
right_frame = FramePropertySet(right=thin_edge)
top_frame = FramePropertySet(top=thin_edge)

doc = Document()
ss = doc.StyleSheet

# Set the margins for the section at 0.5 inch on all sides

ms = MarginsPropertySet(top=720, left=720, right=720, bottom=720)
section = Section(margins=ms)
doc.Sections.append(section)

# Improve the style sheet.  1440 twips to the inch

ps = ParagraphStyle(
    'Title',
    TextStyle(TextPropertySet(ss.Fonts.Arial, 22, bold=True)).Copy(),
    ParagraphPropertySet(alignment=3, space_before=270, space_after=30))
ss.ParagraphStyles.append(ps)
ps = ParagraphStyle(
    'Subtitle',
    TextStyle(TextPropertySet(ss.Fonts.Arial, 16)).Copy(),
    ParagraphPropertySet(alignment=3, space_before=0, space_after=0))
ss.ParagraphStyles.append(ps)
ps = ParagraphStyle('SubtitleLeft',
コード例 #9
0
ファイル: Elements.py プロジェクト: vildritt/pyrtf
 def NewSection(self, *params, **kwargs):
     result = Section(*params, **kwargs)
     self.Sections.append(result)
     return result
コード例 #10
0
    def render(self):
        """ Mostly a copy of the render method in OSHAActionPlanReportDownload, but with
            some changes to handle the special reqs of Italy
        """
        document = report.createDocument(self.session)
        ss = document.StyleSheet

        # Define some more custom styles
        ss.ParagraphStyles.append(
            ParagraphStyle(
                "RiskPriority",
                TextStyle(
                    TextPropertySet(font=ss.Fonts.Arial,
                                    size=22,
                                    italic=True,
                                    colour=ss.Colours.Blue)),
                ParagraphPropertySet(left_indent=300, right_indent=300)))
        ss.ParagraphStyles.append(
            ParagraphStyle(
                "MeasureField",
                TextStyle(
                    TextPropertySet(font=ss.Fonts.Arial,
                                    size=18,
                                    underline=True)),
                ParagraphPropertySet(left_indent=300, right_indent=300)))
        ss.ParagraphStyles.append(
            ParagraphStyle(
                "ITTitle",
                TextStyle(
                    TextPropertySet(font=ss.Fonts.Arial,
                                    size=36,
                                    italic=True,
                                    bold=True)),
                ParagraphPropertySet(left_indent=300, right_indent=300)))
        ss.ParagraphStyles.append(
            ParagraphStyle(
                "ITSubtitle",
                TextStyle(
                    TextPropertySet(font=ss.Fonts.Arial,
                                    size=32,
                                    italic=True,
                                    bold=True)),
                ParagraphPropertySet(left_indent=300, right_indent=300)))
        ss.ParagraphStyles.append(
            ParagraphStyle(
                "ITSubSubtitle",
                TextStyle(
                    TextPropertySet(font=ss.Fonts.Arial,
                                    size=28,
                                    italic=True,
                                    bold=True)),
                ParagraphPropertySet(left_indent=300, right_indent=300)))
        ss.ParagraphStyles.append(
            ParagraphStyle(
                "ITNormalBold",
                TextStyle(
                    TextPropertySet(font=ss.Fonts.Arial, size=24, bold=True)),
                ParagraphPropertySet(left_indent=50, right_indent=50)))
        # XXX: This part is removed
        # self.addActionPlan(document)

        # XXX: and replaced with this part:
        t = lambda txt: "".join([
            "\u%s?" % str(ord(e)) for e in translate(txt, context=self.request)
        ])
        intro = createItalianIntro(document, self.context, self.request)
        toc = createSection(document,
                            self.context,
                            self.request,
                            first_page_number=2)

        body = Section()
        heading = t(
            _("header_oira_report_download",
              default=u"OiRA Report: \"${title}\"",
              mapping=dict(title=self.session.title)))

        toc.append(
            Paragraph(
                ss.ParagraphStyles.Heading1,
                ParagraphPropertySet(alignment=ParagraphPropertySet.CENTER),
                heading,
            ))

        if self.session.report_comment:
            # Add comment. #5985
            normal_style = document.StyleSheet.ParagraphStyles.Normal
            toc.append(Paragraph(normal_style, self.session.report_comment))

        toc_props = ParagraphPropertySet()
        toc_props.SetLeftIndent(TabPropertySet.DEFAULT_WIDTH * 1)
        toc_props.SetRightIndent(TabPropertySet.DEFAULT_WIDTH * 1)
        p = Paragraph(ss.ParagraphStyles.Heading6, toc_props)
        txt = t(_("toc_header", default=u"Contents"))
        p.append(character.Text(txt))
        toc.append(p)

        headings = [
            t(u"Adempimenti/rischi identificati, valutati e gestiti con misure "
              "obbligatorie adottate ed eventuali misure di miglioramento"),
            t(u"Adempimenti/rischi non pertinenti"),
        ]
        nodes = [
            self.actioned_nodes,
            self.risk_not_present_nodes,
        ]

        for nodes, heading in zip(nodes, headings):
            if not nodes:
                continue
            self.addReportNodes(document, nodes, heading, toc, body)

        toc.append(Paragraph(LINE))
        body.append(Paragraph(LINE))
        document.Sections.append(body)
        # Until here...

        renderer = Renderer()
        output = StringIO()
        renderer.Write(document, output)

        # Custom filename
        filename = u"Documento di valutazione dei rischi {}".format(
            self.session.title)
        self.request.response.setHeader(
            "Content-Disposition",
            "attachment; filename=\"%s.rtf\"" % filename.encode("utf-8"))
        self.request.response.setHeader("Content-Type", "application/rtf")
        return output.getvalue()
コード例 #11
0
    def render(self):
        """ Mostly a copy of the render method in euphorie.client, but with
            some changes to also show unanswered risks and non-present risks.
            #1517 and #1518
        """
        document = report.createDocument(self.session)
        ss = document.StyleSheet

        # Define some more custom styles
        ss.ParagraphStyles.append(
            ParagraphStyle(
                "RiskPriority",
                TextStyle(
                    TextPropertySet(font=ss.Fonts.Arial,
                                    size=22,
                                    italic=True,
                                    colour=ss.Colours.Blue)),
                ParagraphPropertySet(left_indent=300, right_indent=300)))
        ss.ParagraphStyles.append(
            ParagraphStyle(
                "MeasureField",
                TextStyle(
                    TextPropertySet(font=ss.Fonts.Arial,
                                    size=18,
                                    underline=True)),
                ParagraphPropertySet(left_indent=300, right_indent=300)))
        # XXX: This part is removed
        # self.addActionPlan(document)

        # XXX: and replaced with this part:
        t = lambda txt: "".join([
            "\u%s?" % str(ord(e)) for e in translate(txt, context=self.request)
        ])
        toc = createSection(document, self.context, self.request)

        body = Section()
        heading = t(
            _("header_oira_report_download",
              default=u"OiRA Report: \"${title}\"",
              mapping=dict(title=self.session.title)))

        toc.append(
            Paragraph(
                ss.ParagraphStyles.Heading1,
                ParagraphPropertySet(alignment=ParagraphPropertySet.CENTER),
                heading,
            ))

        if self.session.report_comment:
            # Add comment. #5985
            normal_style = document.StyleSheet.ParagraphStyles.Normal
            toc.append(Paragraph(normal_style, self.session.report_comment))

        toc_props = ParagraphPropertySet()
        toc_props.SetLeftIndent(TabPropertySet.DEFAULT_WIDTH * 1)
        toc_props.SetRightIndent(TabPropertySet.DEFAULT_WIDTH * 1)
        p = Paragraph(ss.ParagraphStyles.Heading6, toc_props)
        txt = t(_("toc_header", default=u"Contents"))
        p.append(character.Text(txt))
        toc.append(p)

        headings = [
            t(
                _("header_present_risks",
                  default=u"Risks that have been identified, "
                  u"evaluated and have an Action Plan")),
            t(
                _("header_unevaluated_risks",
                  default=u"Risks that have been identified but "
                  u"do NOT have an Action Plan")),
            t(
                _("header_unanswered_risks",
                  default=u'Hazards/problems that have been "parked" '
                  u'and are still to be dealt with')),
            t(
                _("header_risks_not_present",
                  default=u"Hazards/problems that have been managed "
                  u"or are not present in your organisation"))
        ]
        nodes = [
            self.actioned_nodes,
            self.unactioned_nodes,
            self.unanswered_nodes,
            self.risk_not_present_nodes,
        ]

        for nodes, heading in zip(nodes, headings):
            if not nodes:
                continue
            self.addReportNodes(document, nodes, heading, toc, body)

        toc.append(Paragraph(LINE))
        body.append(Paragraph(LINE))
        self.addConsultationBox(body, document)
        document.Sections.append(body)
        # Until here...

        renderer = Renderer()
        output = StringIO()
        renderer.Write(document, output)

        filename = translate(
            _("filename_report_actionplan",
              default=u"Action plan ${title}",
              mapping=dict(title=self.session.title)),
            context=self.request,
        )
        self.request.response.setHeader(
            "Content-Disposition",
            "attachment; filename=\"%s.rtf\"" % filename.encode("utf-8"))
        self.request.response.setHeader("Content-Type", "application/rtf")
        return output.getvalue()
コード例 #12
0
def createItalianIntro(document, survey, request):
    t = lambda txt: "".join(
        ["\u%s?" % str(ord(e)) for e in translate(txt, context=request)])
    ss = document.StyleSheet
    pp = ParagraphPropertySet
    section = Section(break_type=Section.PAGE, first_page_number=1)
    footer_txt = t(
        u"1) Il documento deve essere munito di “data certa” o attestata dalla "
        "sottoscrizione del documento, ai soli fini della prova della data, "
        "da parte del RSPP, RLS o RLST, e del medico competente, ove nominato. In "
        "assenza di MC o RLS o RLST, la data certa va documentata con PEC o altra "
        "forma prevista dalla legge.")
    section.append(Paragraph(LINE))
    section.append(Paragraph(LINE))
    section.append(Paragraph(LINE))
    section.append(Paragraph(LINE))
    section.append(
        Paragraph(
            ss.ParagraphStyles.ITTitle,
            pp(alignment=pp.CENTER),
            t(u"Azienda ....................."),
        ))
    section.append(Paragraph(LINE))
    section.append(Paragraph(LINE))
    section.append(Paragraph(LINE))
    section.append(Paragraph(LINE))
    dots = u"……………………………………"
    section.append(
        Paragraph(
            ss.ParagraphStyles.ITSubtitle,
            pp(alignment=pp.CENTER),
            t(u"DOCUMENTO DI VALUTAZIONE DEI RISCHI"),
        ))
    section.append(Paragraph(LINE))
    section.append(
        Paragraph(
            ss.ParagraphStyles.ITSubSubtitle,
            pp(alignment=pp.CENTER),
            t(u"(artt. 17, 28  D.Lgs. 81/08)"),
        ))
    section.append(Paragraph(LINE))
    section.append(Paragraph(LINE))
    section.append(Paragraph(LINE))
    section.append(Paragraph(LINE))

    data1 = Table(4750, 4750)
    c1 = Cell(
        Paragraph(ss.ParagraphStyles.ITNormalBold, pp(alignment=pp.LEFT),
                  t(u"Data (1), {}".format(dots))))
    c2 = Cell(
        Paragraph(ss.ParagraphStyles.ITNormalBold, pp(alignment=pp.LEFT),
                  t(u"")))
    data1.AddRow(c1, c2)
    c1 = Cell(
        Paragraph(ss.ParagraphStyles.ITNormalBold, pp(alignment=pp.LEFT),
                  t(u"Datore di lavoro:")))
    c2 = Cell(
        Paragraph(ss.ParagraphStyles.ITNormalBold, pp(alignment=pp.LEFT),
                  t(dots)))
    data1.AddRow(c1, c2)
    section.append(data1)
    section.append(Paragraph(LINE))
    section.append(
        Paragraph(
            ss.ParagraphStyles.ITNormalBold,
            pp(alignment=pp.CENTER),
            t(u"Se necessario, ai soli fini della prova della data:"),
        ))

    section.append(Paragraph(LINE))
    data2 = Table(4750, 4750)
    c1 = Cell(
        Paragraph(ss.ParagraphStyles.ITNormalBold, pp(alignment=pp.LEFT),
                  t(u"RSPP")))
    c2 = Cell(
        Paragraph(ss.ParagraphStyles.ITNormalBold, pp(alignment=pp.LEFT),
                  t(dots)))
    data2.AddRow(c1, c2)
    c1 = Cell(
        Paragraph(ss.ParagraphStyles.ITNormalBold, pp(alignment=pp.LEFT),
                  t(u"Medico Competente (ove nominato)")))
    c2 = Cell(
        Paragraph(ss.ParagraphStyles.ITNormalBold, pp(alignment=pp.LEFT),
                  t(dots)))
    data2.AddRow(c1, c2)
    c1 = Cell(
        Paragraph(ss.ParagraphStyles.ITNormalBold, pp(alignment=pp.LEFT),
                  t(u"RLS/RLST")))
    c2 = Cell(
        Paragraph(ss.ParagraphStyles.ITNormalBold, pp(alignment=pp.LEFT),
                  t(dots)))
    data2.AddRow(c1, c2)
    section.append(data2)

    footer = Table(9500)
    # rtfng does not like unicode footers
    c1 = Cell(
        Paragraph(ss.ParagraphStyles.Footer, pp(alignment=pp.LEFT),
                  footer_txt))

    # c2 = Cell(Paragraph(pp(alignment=pp.RIGHT), PAGE_NUMBER))
    footer.AddRow(c1)
    section.Footer.append(footer)
    document.Sections.append(section)
    return section