def save_rtf(self, file_name): import PyRTF DR = PyRTF.Renderer() doc = self.format_as_rtf() f = open(file_name, "w") DR.Write(doc, f) f.close()
def renderRTF(questions, fname): """ Format and write the list of Questions to a file with name /fname/. """ rtfObj = _genRtfFile(questions) renderer = rtf.Renderer() with open(fname, 'wb') as f: renderer.Write(rtfObj, f)
def main(): aves=model.getAves() doc3 = MakeExample3(aves=aves) DR = PyRTF.Renderer() DR.Write( doc3, OpenFile( 'gen_SingleAve' ) ) cmd=r'"%s%s.rtf"' %(initpath,'gen_SingleAve') #start "I:\Aptana Studio 3 Workspace\ncs_report\src\gen_singleave.rtf" #os.system(cmd) os.spawnl(os.P_NOWAIT,os.environ['COMSPEC'],"/C "+cmd)
def get_rtf(self): self._do_queue() DR = PyRTF.Renderer() fp = StringIO() try: DR.Write(self._doc, fp) return fp.getvalue() except: pass finally: fp.close()
def _license_text(self, license_file): """ Generates rich text given a license file-like object :param license_file: file-like object :return: """ wordpad_header = textwrap.dedent(r''' {\rtf1\ansi\ansicpg1252\deff0\nouicompat\deflang1033{\fonttbl{\f0\fnil\fcharset255 Times New Roman;} {\*\generator Riched20 10.0.14393}\viewkind4\uc1 ''').strip().replace('\n', '\r\n') center_space = ' ' r = PyRTF.Renderer() doc = PyRTF.Document() ss = doc.StyleSheet sec = PyRTF.Section() doc.Sections.append(sec) is_blank = False paragraph_text = [''] for line in license_file: if not line or line.isspace(): is_blank = True if is_blank: # first element of paragraph_text is left-aligned, subsequent elements are centered is_centered = False for sec_line in paragraph_text: if is_centered: para_props = PyRTF.ParagraphPS( alignment=PyRTF.ParagraphPS.CENTER) p = PyRTF.Paragraph(ss.ParagraphStyles.Normal, para_props) p.append(sec_line) sec.append(p) elif sec_line: # first element may be nothing, but not whitespace sec.append(sec_line) is_centered = True is_blank = False paragraph_text = [''] if line.startswith(center_space): paragraph_text.append(line.strip()) is_blank = True else: paragraph_text[0] += ' ' + line paragraph_text[0] = paragraph_text[0].strip() f = StringIO() f.write(wordpad_header) r.Write(doc, f) return f.getvalue()
def write_license_rtf(self, rtf_path): # PyRTF and PyRTF-ng it seems do not support Unicode types # when they do this code should read the file using the codecs # module and create a Unicode RTF. if not p.exists(rtf_path): license_file = p.join(self.get_contents_dir(), 'LICENSE.txt') if p.exists(license_file): license_text = open(license_file, 'r').read() else: license_text = 'This software was not shipped with a license.' doc = PyRTF.Document() section = PyRTF.Section() doc.Sections.append(section) for paragraph in re.split("\n\n|\r\n\r\n", license_text): section.append(paragraph) renderer = PyRTF.Renderer() renderer.Write(doc, open(rtf_path, 'w'))
def write_foot(self): if not self.multidoc: renderer = PyRTF.Renderer() renderer.Write(self.doc, self.out)
def write_footer(self): renderer = PyRTF.Renderer() renderer.Write(self.doc, self.ofi)
def exportRtf(self): infoString = QtCore.QString("estrazione anagrafiche in word") reply = QtGui.QMessageBox.question( self, infoString, "Esportare solo le anagrafiche selezionate?", QtGui.QMessageBox.Yes | QtGui.QMessageBox.No | QtGui.QMessageBox.Cancel, QtGui.QMessageBox.No) if reply == QtGui.QMessageBox.Yes: selected = self.selectSome(self.ui.tabella.selectedItems()) elif reply == QtGui.QMessageBox.No: selected = self.selectAll() else: return filexl = QFileDialog(self) #setto filexl in anymode cioe' ritorna il path del file anche se non esiste filexl.setFileMode(0) # filexl.setNameFilter("word(*.doc *.rtf)") nfile = filexl.getSaveFileName(self, "esporta anagrafiche in word", "", filter="(*.doc *.rtf)") DR = rtf.Renderer() doc = rtf.Document() ss = doc.StyleSheet n = 0 thin_edge = rtf.BorderPropertySet(width=20, style=rtf.BorderPropertySet.SINGLE) thick_edge = rtf.BorderPropertySet(width=80, style=rtf.BorderPropertySet.DOUBLE) mixed_frame = rtf.FramePropertySet(thin_edge, thick_edge, thin_edge, thick_edge) for i in enumerate(selected): section = rtf.Section() table = rtf.Table(rtf.TabPropertySet.DEFAULT_WIDTH * 7, rtf.TabPropertySet.DEFAULT_WIDTH * 3) #section.append(table) img = rtf.Image("pictures/logo.jpg") c1 = rtf.Cell(rtf.Paragraph(img)) c2 = rtf.Cell( rtf.Paragraph( ss.ParagraphStyles.Heading2, "Scheda anagrafica {0}".format(self.activeDb.getNameDb()))) table.AddRow(c1, c2) section.Header.append(table) oggi = datetime.date.today() section.Footer.append( rtf.Paragraph( ss.ParagraphStyles.Normal, "® Copyright Marketing & Telematica mail: [email protected] Data Esportazione: {0}/{1}/{2}" .format(oggi.day, oggi.month, oggi.year))) Id = i[1].data(1).toInt()[0] p = rtf.Paragraph(rtf.ParagraphPS().SetPageBreakBefore(True), '') section.append(p) doc = self.makeRtf(doc, section, Id, i[0] + 1, len((selected))) #doc=self.makeRtf(doc,section) ##print "scrivo",self.OpenFile( 'rtf/vero' ) DR.Write(doc, self.OpenFile(nfile))