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()
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
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
def render(self, output): from cStringIO import StringIO from rtfng.Elements import Document from rtfng.document.section import Section from rtfng.Renderer import Renderer 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()
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
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
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
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
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()
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
def createOrderForm(cart, member_details): """Creates and returns an order form pdf.""" member_name = unicode(member_details.get('member_name')) # member_email = unicode(member_details.get('member_email')) member_phone = unicode(member_details.get('member_phone')) # order_comments = unicode(member_details.get('order_comments')) ss = makeReportStylesheet() doc = Document(ss, default_language=Languages.EnglishUK) paper = Paper('A4', 9, 'A4 297 x 210 mm', 16838, 11907) section = Section(margins=MarginsPropertySet(top=100, left=400, bottom=100, right=400), paper=paper, landscape=True, headery=0, footery=300) doc.Sections.append(section) footer_text = member_name + " " + member_phone footer_p = Paragraph(ss.ParagraphStyles.Heading1) footer_p.append(unicode(footer_text)) section.Footer.append(footer_p) thin_edge = BorderPropertySet(width=10, style=BorderPropertySet.SINGLE) thin_frame = FramePropertySet(thin_edge, thin_edge, thin_edge, thin_edge) # based on twirps or 567/cm. table = Table(567, 3118, 709) # header header_props = ParagraphPropertySet(alignment=3) c2_para = Paragraph(ss.ParagraphStyles.Normal, header_props) c2_para.append(u'No.') c2 = Cell(c2_para, thin_frame) c3_para = Paragraph(ss.ParagraphStyles.Normal, header_props) c3_para.append(u'Product') c3 = Cell(c3_para, thin_frame) c4_para = Paragraph(ss.ParagraphStyles.Normal, header_props) c4_para.append(u'Cost') c4 = Cell(c4_para, thin_frame) table.AddRow(c2, c3, c4) # list for cart_item in cart.cartitem_set.all().order_by('product__picking_order', 'product__aisle', 'product__sort_name'): centre_props = ParagraphPropertySet(alignment=3) c2_para = Paragraph(centre_props) if cart_item.cart_bundle: c2_para.append(u"PnM") else: c2_para.append(unicode(cart_item.quantity)) c2 = Cell(c2_para, thin_frame) c3_para = Paragraph(ss.ParagraphStyles.Normal) c3_para.append(unicode(cart_item.product.order_name)) if cart_item.product.bundle: c3_para.append(u": ") for bundle_item in cart_item.cart_bundle.cartitem_set.all(): c3_para.append(unicode(bundle_item.product.order_name)) c3_para.append(u" x " + unicode(bundle_item.quantity) + u", ") c3 = Cell(c3_para, thin_frame) cost_props = ParagraphPropertySet(alignment=2) c4_para = Paragraph(cost_props) c4_para.append(unicode(cart_item.line_total)) c4 = Cell(c4_para, thin_frame) table.AddRow(c2, c3, c4) # table footer c1_para = Paragraph(ss.ParagraphStyles.Heading2Short, ParagraphPropertySet(alignment=2)) c1_para.append(u'Total cost') c1 = Cell(c1_para, thin_frame, span=2) c2_para = Paragraph(ParagraphPropertySet(alignment=2)) c2_para.append(unicode(cart.total)) c2 = Cell(c2_para, thin_frame) table.AddRow(c1, c2) # write ins for writein_item in cart.cartwriteinitem_set.all(): centre_props = ParagraphPropertySet(alignment=3) c2_para = Paragraph(centre_props) # c2_para.append(unicode(cart_item.quantity)) c2 = Cell(c2_para, thin_frame) c3_para = Paragraph(ss.ParagraphStyles.Normal) c3_para.append(u"{0} -- {1}".format(unicode(writein_item.name), unicode(writein_item.code))) c3 = Cell(c3_para, thin_frame) cost_props = ParagraphPropertySet(alignment=2) c4_para = Paragraph(cost_props) # c4_para.append(unicode(cart_item.line_total)) c4 = Cell(c4_para, thin_frame) table.AddRow(c2, c3, c4) # virtual shop items. for virtualshop_item in cart.cartvirtualshopitem_set.all(): centre_props = ParagraphPropertySet(alignment=3) c2_para = Paragraph(centre_props) c2_para.append(unicode(virtualshop_item.quantity)) c2 = Cell(c2_para, thin_frame) c3_para = Paragraph(ss.ParagraphStyles.Normal) c3_para.append(unicode(virtualshop_item.name) + u" -- VS") c3 = Cell(c3_para, thin_frame) cost_props = ParagraphPropertySet(alignment=2) c4_para = Paragraph(cost_props) # c4_para.append(unicode(cart_item.line_total)) c4 = Cell(c4_para, thin_frame) table.AddRow(c2, c3, c4) section.append(table) section.append(Paragraph()) rtf_doc = StringIO() document_renderer = Renderer() document_renderer.Write(doc, rtf_doc) return rtf_doc
def NewSection(self, *params, **kwargs): result = Section(*params, **kwargs) self.Sections.append(result) return result
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()
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
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', TextStyle(TextPropertySet(ss.Fonts.Arial, 16)).Copy(), ParagraphPropertySet(space_before=0, space_after=0)) ss.ParagraphStyles.append(ps)
# 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)
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()
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()
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()
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',
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
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