def make_pictures(): doc, section, styles = RTFTestCase.initializeDoc() # text can be added directly to the section a paragraph object is create as needed section.append( 'Image Example 1' ) section.append( 'You can add images in one of two ways, either converting the ' 'image each and every time like;' ) image = Image( 'examples/image.jpg' ) section.append( Paragraph( image ) ) section.append( 'Or you can use the image object to convert the image and then ' 'save it to a raw code element that can be included later.' ) # Test RawCode -- split into separate test? rawCodeDecl = image.ToRawCode('TEST_IMAGE') assert rawCodeDecl.startswith('TEST_IMAGE = RawCode( """') assert rawCodeDecl.endswith('""" )') rawCode = RawCode(image.Data) section.append(rawCode) section.append('The above picture was displayed from a RawCode object without a Paragraph wrapper.') section.append( 'Here are some png files' ) for f in [ 'examples/img1.png', 'examples/img2.png', 'examples/img3.png', 'examples/img4.png' ] : section.append( Paragraph( Image( f ) ) ) return doc
def make_tableMarginInCell(): doc, section, styles = RTFTestCase.initializeDoc() cell_margins0 = MarginsPropertySet(top=0, right=0, bottom=0, left=0) cell_margins1 = MarginsPropertySet(top=500, right=500, bottom=500, left=500) cell_margins2 = MarginsPropertySet(top=1000, right=1000, bottom=1000, left=1000) section.append('Table with Margin in Cells') table = Table(TableTestCase.col1, TableTestCase.col2, TableTestCase.col3) table.AddRow(Cell(cell_margins0, 'Marign 0'), Cell( cell_margins1, 'Margin 500', ), Cell(cell_margins2, 'Margin 1000')) table.AddRow(Cell(cell_margins0, 'Marign 0'), Cell( cell_margins1, 'Margin 500', ), Cell(cell_margins2, 'Margin 1000')) table.AddRow(Cell(cell_margins0, 'Marign 0'), Cell( cell_margins1, 'Margin 500', ), Cell(cell_margins2, 'Margin 1000')) section.append(table) return doc
def make_paraTabs(): doc, section, styles = RTFTestCase.initializeDoc() p = Paragraph() p.append( "The paragraph itself can also be overridden in lots of ways: " "tabs, borders, alignment, etc., can all be modified either in " "the style or as an override during the creation of the " "paragraph. This is demonstrated below with custom tab widths " "and embedded carriage returns (i.e., new line markers that do " "not cause a paragraph break)." ) section.append(p) tabs = [ TabPropertySet(width=TabPropertySet.DEFAULT_WIDTH), TabPropertySet(width=TabPropertySet.DEFAULT_WIDTH * 2), TabPropertySet(width=TabPropertySet.DEFAULT_WIDTH), ] para_props = ParagraphPropertySet(tabs=tabs) p = Paragraph(styles.ParagraphStyles.Normal, para_props) p.append( "Phrase at Left Tab", TAB, "Middle Phrase One", TAB, "Right Phrase", LINE, "Second Left Phrase", TAB, "Middle Phrase Two", TAB, "Another Right Phrase", ) section.append(p) return doc
def test_CustomElementInsidePara(self): # It's just too hard to write a standard test with a custom renderer. doc, section, styles = RTFTestCase.initializeDoc() p = Paragraph() p.append('This is a standard paragraph with the default style.') class CustomClass(object): pass p.append(CustomClass()) section.append(p) # Define renderer with custom element support. specialString = "ABC I'm unique" def customElementWriter(renderer, element): renderer._write(specialString) r = Renderer(write_custom_element_callback=customElementWriter) # Render with custom element. result = StringIO() r.Write(doc, result) testData = result.getvalue() result.close() # Confirm generate result has custom rendering. assert specialString in testData
def make_paraTabs(): doc, section, styles = RTFTestCase.initializeDoc() p = Paragraph() p.append( 'The paragraph itself can also be overridden in lots of ways: ' 'tabs, borders, alignment, etc., can all be modified either in ' 'the style or as an override during the creation of the ' 'paragraph. This is demonstrated below with custom tab widths ' 'and embedded carriage returns (i.e., new line markers that do ' 'not cause a paragraph break).') section.append(p) tabs = [ TabPropertySet(width=TabPropertySet.DEFAULT_WIDTH), TabPropertySet(width=TabPropertySet.DEFAULT_WIDTH * 2), TabPropertySet(width=TabPropertySet.DEFAULT_WIDTH)] para_props = ParagraphPropertySet(tabs=tabs) p = Paragraph(styles.ParagraphStyles.Normal, para_props) p.append( 'Phrase at Left Tab', TAB, 'Middle Phrase One', TAB, 'Right Phrase', LINE, 'Second Left Phrase', TAB, 'Middle Phrase Two', TAB, 'Another Right Phrase' ) section.append(p) return doc
def make_tableVerticalCellMerge(): doc, section, styles = RTFTestCase.initializeDoc() section.append('Table with Vertical Cells Merged') table = Table(TableTestCase.col1, TableTestCase.col2, TableTestCase.col3) table.AddRow(Cell('A-one'), Cell('A-two', vertical_merge=True), Cell('A-three')) table.AddRow(Cell('A-one'), Cell(vertical_merge=True), Cell('A-three')) table.AddRow(Cell('A-one'), Cell('A-two', start_vertical_merge=True), Cell('A-three')) table.AddRow(Cell('A-one'), Cell(vertical_merge=True), Cell('A-three')) table.AddRow( Cell(Paragraph( ParagraphPropertySet(alignment=ParagraphPropertySet.CENTER), 'SPREAD'), span=3)) table.AddRow(Cell('A-one'), Cell('A-two', vertical_merge=True), Cell('A-three')) table.AddRow(Cell('A-one'), Cell(vertical_merge=True), Cell('A-three')) table.AddRow(Cell('A-one'), Cell('A-two', start_vertical_merge=True), Cell('A-three')) table.AddRow(Cell('A-one'), Cell(vertical_merge=True), Cell('A-three')) section.append(table) return doc
def make_spaceBetweenLines(): doc, section, styles = RTFTestCase.initializeDoc() para_props = ParagraphPropertySet() quarterInch = 1440/2 para_props.SetSpaceBetweenLines(quarterInch) p = Paragraph(para_props) p.append( 'Paragraph One', LINE, 'Second line', LINE, 'Third line', ) section.append(p) para_props = ParagraphPropertySet() para_props.SetSpaceBetweenLines(-quarterInch) p = Paragraph(para_props) p.append( 'Paragraph Two', LINE, 'Second line', LINE, 'Third line', ) section.append(p) return doc
def make_docCopy(): doc, section, styles = RTFTestCase.initializeDoc() section.append('First section') secondSection = doc.NewSection() secondSection.append('Second section.') copyDoc = doc.Copy() return doc
def make_charTab(): doc, section, styles = RTFTestCase.initializeDoc() p = Paragraph() p.append('Before tab') p.append(Text(TAB)) p.append('After tab') section.append(p) return doc
def make_charFrame(): doc, section, styles = RTFTestCase.initializeDoc() p = Paragraph() thinEdge = BorderPropertySet(width=20, style=BorderPropertySet.SINGLE, colour=styles.Colours.Blue) textWithFrame = TextPropertySet(frame=thinEdge) p.append(Text('This tests frame drawn around text.', textWithFrame)) section.append(p) return doc
def make_sectionWithParas(): doc, section, styles = RTFTestCase.initializeDoc() section.append('Small paragraph.') section.append('') # a lot of useful documents can be created with little more than this section.append( 'A lot of useful documents can be created in this way. More ' 'advanced formatting is available, but a lot of users just want ' 'to see their data in something other than a text file.') return doc
def make_charStyleOverride(): doc, section, styles = RTFTestCase.initializeDoc() p = Paragraph() p.append('This is a standard paragraph with the default style.') p = Paragraph() p.append('It is also possible to manully override a style. ', 'This is a change of just the font ', TEXT('size', size=48), ' an this is for just the font ', TEXT('typeface', font=styles.Fonts.Impact), '.') section.append(p) return doc
def make_paraNormal(): doc, section, styles = RTFTestCase.initializeDoc() p1 = Paragraph(styles.ParagraphStyles.Heading1) p1.append('Heading 1') section.append(p1) p2 = Paragraph(styles.ParagraphStyles.Normal) p2.append( 'In this case we have used two styles. The first paragraph is ' 'marked with the Heading1 style, and this one is marked with the ' 'Normal style.') section.append(p2) return doc
def make_hyperlinks(): doc, section, styles = RTFTestCase.initializeDoc() p = Paragraph() p.append('This is a standard paragraph with the default style.') p = Paragraph() p.append('This is also a standard paragraph. ', 'But lets add a ', TEXT('Washington Post', hyperlink='https://washingtonpost.com'), ' hyperlink to this paragraph. ', ) section.append(p) return doc
def make_tableHorizontalCellMerge(): doc, section, styles = RTFTestCase.initializeDoc() section.append( 'Table with Horizontal Cells Merged' ) table = Table( TableTestCase.col1, TableTestCase.col2, TableTestCase.col3 ) table.AddRow( Cell( 'A-one' ), Cell( 'A-two' ), Cell( 'A-three' ) ) table.AddRow( Cell( 'A-one' ), Cell( 'A-two', span=2 ) ) table.AddRow( Cell( 'A-one', span=3 ) ) table.AddRow( Cell( 'A-one' ), Cell( 'A-two' ), Cell( 'A-three' ) ) table.AddRow( Cell( 'A-one', span=2 ), Cell( 'A-two' ) ) section.append( table ) return doc
def test_ExceptionOnUnknownElement(self): # Create document with unknown element type. doc, section, styles = RTFTestCase.initializeDoc() class CustomClass(object): pass section.append(CustomClass()) # Try to render. r = Renderer() result = StringIO() self.assertRaises(Exception, r.Write, doc, result)
def make_tableFlowRightToLeft(): doc, section, styles = RTFTestCase.initializeDoc() section.append( 'Table with content flowing right to left' ) table = Table( TableTestCase.col4, TableTestCase.col1, TableTestCase.col2, TableTestCase.col3 ) table.AddRow( Cell( 'one' ), Cell( 'two' ), Cell( 'three' ), Cell( 'This is pretty amazing', flow=Cell.FLOW_RL_TB, start_vertical_merge=True ) ) for i in range( 10 ) : table.AddRow( Cell( 'one' ), Cell( 'two' ), Cell( 'three' ), Cell( vertical_merge=True )) section.append( table ) return doc
def test_documentWrite(self): doc, section, styles = RTFTestCase.initializeDoc() fd, filename = tempfile.mkstemp(prefix='test-pyrtf', suffix='.rtf') os.close(fd) doc.write(filename) result = StringIO.StringIO() doc.write(result) assert open(filename, 'r').read() == result.getvalue() os.remove(filename)
def test_documentWrite(self): doc, section, styles = RTFTestCase.initializeDoc() fd, filename = tempfile.mkstemp(prefix='test-pyrtf', suffix='.rtf') os.close(fd) doc.write(filename) result = io.StringIO() doc.write(result) assert open(filename, 'r').read() == result.getvalue() os.remove(filename)
def make_charUnicode(): doc, section, styles = RTFTestCase.initializeDoc() section.append('This tests unicode.') p = Paragraph() p.append('32\u00B0 Fahrenheit is 0\u00B0 Celsuis') section.append(p) p = Paragraph() p.append('Henry \u2163 is Henry IV in unicode.') section.append(p) return doc
def make_charInline(): doc, section, styles = RTFTestCase.initializeDoc() p = Paragraph() p.append(Inline('Simple Inline Element')) section.append(p) # Test various element types inside Inline element. p = Paragraph() p.append( Inline('First Inline Element', TAB, 'Second Inline Element', RawCode(r'\tab '), 'After tab')) section.append(p) return doc
def make_charStyleOverride(): doc, section, styles = RTFTestCase.initializeDoc() p = Paragraph() p.append('This is a standard paragraph with the default style.') p = Paragraph() p.append('It is also possible to manully override a style. ', 'This is a change of just the font ', TEXT('size', size=48), ' an this is for just the font ', TEXT('typeface', font=styles.Fonts.Impact) , '.') section.append(p) return doc
def make_paraIndents(): doc, section, styles = RTFTestCase.initializeDoc() section.append( "The paragraphs below demonstrate the flexibility , the following is all at the " "same indent level and the one after it has the first line at a " "different indent to the rest. The third has the first line " "going in the other direction and is also separated by a page " "break. Note that the FirstLineIndent is defined as being the " "difference from the LeftIndent." ) creditURL = "http://www.shakespeare-online.com/plots/1kh4ps.html" section.append("(Paragraph text from %s.)" % creditURL) sampleParagraph = """The play opens one year after the death of Richard II, and King Henry is making plans for a crusade to the Holy Land to cleanse himself of the guilt he feels over the usurpation of Richard's crown. But the crusade must be postponed when Henry learns that Welsh rebels, led by Owen Glendower, have defeated and captured Mortimer. Although the brave Henry Percy, nicknamed Hotspur, has quashed much of the uprising, there is still much trouble in Scotland. King Henry has a deep admiration for Hotspur and he longs for his own son, Prince Hal, to display some of Hotspur's noble qualities. Hal is more comfortable in a tavern than on the battlefield, and he spends his days carousing with riff-raff in London. But King Henry also has his problems with the headstrong Hotspur, who refuses to turn over his prisoners to the state as he has been so ordered. Westmoreland tells King Henry that Hotspur has many of the traits of his uncle, Thomas Percy, the Earl of Worcester, and defying authority runs in the family.""" sampleParagraph = re.sub("\s+", " ", sampleParagraph) para_props = ParagraphPropertySet() para_props.SetLeftIndent(TabPropertySet.DEFAULT_WIDTH * 3) p = Paragraph(styles.ParagraphStyles.Normal, para_props) p.append(sampleParagraph) section.append(p) para_props = ParagraphPropertySet() para_props.SetFirstLineIndent(TabPropertySet.DEFAULT_WIDTH * -2) para_props.SetLeftIndent(TabPropertySet.DEFAULT_WIDTH * 3) p = Paragraph(styles.ParagraphStyles.Normal, para_props) p.append(sampleParagraph) section.append(p) para_props = ParagraphPropertySet() para_props.SetFirstLineIndent(TabPropertySet.DEFAULT_WIDTH) para_props.SetLeftIndent(TabPropertySet.DEFAULT_WIDTH) p = Paragraph(styles.ParagraphStyles.Normal, para_props) p.append(sampleParagraph) section.append(p) return doc
def make_charUnicode(): doc, section, styles = RTFTestCase.initializeDoc() section.append('This tests unicode.') p = Paragraph() p.append(u'32\u00B0 Fahrenheit is 0\u00B0 Celsuis') section.append(p) p = Paragraph() p.append(u'Henry \u2163 is Henry IV in unicode.') section.append(p) return doc
def make_paraIndents(): doc, section, styles = RTFTestCase.initializeDoc() section.append( 'The paragraphs below demonstrate the flexibility , the following is all at the ' 'same indent level and the one after it has the first line at a ' 'different indent to the rest. The third has the first line ' 'going in the other direction and is also separated by a page ' 'break. Note that the FirstLineIndent is defined as being the ' 'difference from the LeftIndent.') creditURL = 'http://www.shakespeare-online.com/plots/1kh4ps.html' section.append('(Paragraph text from %s.)' % creditURL) sampleParagraph = """The play opens one year after the death of Richard II, and King Henry is making plans for a crusade to the Holy Land to cleanse himself of the guilt he feels over the usurpation of Richard's crown. But the crusade must be postponed when Henry learns that Welsh rebels, led by Owen Glendower, have defeated and captured Mortimer. Although the brave Henry Percy, nicknamed Hotspur, has quashed much of the uprising, there is still much trouble in Scotland. King Henry has a deep admiration for Hotspur and he longs for his own son, Prince Hal, to display some of Hotspur's noble qualities. Hal is more comfortable in a tavern than on the battlefield, and he spends his days carousing with riff-raff in London. But King Henry also has his problems with the headstrong Hotspur, who refuses to turn over his prisoners to the state as he has been so ordered. Westmoreland tells King Henry that Hotspur has many of the traits of his uncle, Thomas Percy, the Earl of Worcester, and defying authority runs in the family.""" sampleParagraph = re.sub('\s+', ' ', sampleParagraph) para_props = ParagraphPropertySet() para_props.SetLeftIndent(TabPropertySet.DEFAULT_WIDTH * 3) p = Paragraph(styles.ParagraphStyles.Normal, para_props) p.append(sampleParagraph) section.append(p) para_props = ParagraphPropertySet() para_props.SetFirstLineIndent(TabPropertySet.DEFAULT_WIDTH * -2) para_props.SetLeftIndent(TabPropertySet.DEFAULT_WIDTH * 3) p = Paragraph(styles.ParagraphStyles.Normal, para_props) p.append(sampleParagraph) section.append(p) para_props = ParagraphPropertySet() para_props.SetFirstLineIndent(TabPropertySet.DEFAULT_WIDTH) para_props.SetLeftIndent(TabPropertySet.DEFAULT_WIDTH) p = Paragraph(styles.ParagraphStyles.Normal, para_props) p.append(sampleParagraph) section.append(p) return doc
def make_charInline(): doc, section, styles = RTFTestCase.initializeDoc() p = Paragraph() p.append(Inline('Simple Inline Element')) section.append(p) # Test various element types inside Inline element. p = Paragraph() p.append(Inline('First Inline Element', TAB, 'Second Inline Element', RawCode(r'\tab '), 'After tab' )) section.append(p) return doc
def make_tableMarginInCell(): doc, section, styles = RTFTestCase.initializeDoc() cell_margins0 = MarginsPropertySet(top = 0, right = 0, bottom =0 , left = 0) cell_margins1 = MarginsPropertySet(top = 500, right = 500, bottom =500 , left = 500) cell_margins2 = MarginsPropertySet(top = 1000, right = 1000, bottom =1000 , left = 1000) section.append( 'Table with Margin in Cells' ) table = Table( TableTestCase.col1, TableTestCase.col2, TableTestCase.col3 ) table.AddRow( Cell( cell_margins0, 'Marign 0' ), Cell( cell_margins1, 'Margin 500', ), Cell( cell_margins2, 'Margin 1000' ) ) table.AddRow( Cell( cell_margins0, 'Marign 0' ), Cell( cell_margins1, 'Margin 500', ), Cell( cell_margins2, 'Margin 1000' ) ) table.AddRow( Cell( cell_margins0, 'Marign 0' ), Cell( cell_margins1, 'Margin 500', ), Cell( cell_margins2, 'Margin 1000' ) ) section.append( table ) return doc
def make_spaceBetweenLines(): doc, section, styles = RTFTestCase.initializeDoc() para_props = ParagraphPropertySet() quarterInch = 1440 / 2 para_props.SetSpaceBetweenLines(quarterInch) p = Paragraph(para_props) p.append("Paragraph One", LINE, "Second line", LINE, "Third line") section.append(p) para_props = ParagraphPropertySet() para_props.SetSpaceBetweenLines(-quarterInch) p = Paragraph(para_props) p.append("Paragraph Two", LINE, "Second line", LINE, "Third line") section.append(p) return doc
def make_paraDefaultPreviousStyle(): doc, section, styles = RTFTestCase.initializeDoc() p1 = Paragraph(styles.ParagraphStyles.Heading1) p1.append('Heading 1') section.append(p1) p2 = Paragraph(styles.ParagraphStyles.Normal) p2.append( 'In this case we have used two styles. The first paragraph is ' 'marked with the Heading1 style, and this one is marked with the ' 'Normal style.') section.append(p2) p3 = Paragraph() p3.append( 'Notice that after changing the style of the paragraph to Normal ' '(in the previous paragraph), all subsequent paragraphs have ' 'that style automatically. This saves typing and is actually the ' 'default native behaviour for RTF documents.') section.append(p3) return doc
def make_paraTabLeaders(): doc, section, styles = RTFTestCase.initializeDoc() section.append( 'The alignment of tabs and style can also be controlled. The ' 'following demonstrates how to use flush right tabs and the ' 'supported leaders.') def _makePara(name): tabs = TabPropertySet( section.TwipsToRightMargin(), alignment=TabPropertySet.RIGHT, leader=getattr(TabPropertySet, name.upper().replace(' ', '_'))) para_props = ParagraphPropertySet(tabs=[tabs]) return Paragraph(styles.ParagraphStyles.Normal, para_props) for name in ['Dots', 'Hyphens', 'Underline', 'Thick Line', 'Equal Sign']: p = _makePara(name) p.append('Before %s' % name, TAB, 'After %s' % name) section.append(p) return doc
def make_tableVerticalCellMerge(): doc, section, styles = RTFTestCase.initializeDoc() section.append( 'Table with Vertical Cells Merged' ) table = Table( TableTestCase.col1, TableTestCase.col2, TableTestCase.col3 ) table.AddRow( Cell( 'A-one' ), Cell( 'A-two', vertical_merge=True ), Cell( 'A-three' ) ) table.AddRow( Cell( 'A-one' ), Cell( vertical_merge=True ), Cell( 'A-three' ) ) table.AddRow( Cell( 'A-one' ), Cell( 'A-two', start_vertical_merge=True ), Cell( 'A-three' ) ) table.AddRow( Cell( 'A-one' ), Cell( vertical_merge=True ), Cell( 'A-three' ) ) table.AddRow( Cell( Paragraph( ParagraphPropertySet( alignment=ParagraphPropertySet.CENTER ), 'SPREAD' ), span=3 ) ) table.AddRow( Cell( 'A-one' ), Cell( 'A-two', vertical_merge=True ), Cell( 'A-three' ) ) table.AddRow( Cell( 'A-one' ), Cell( vertical_merge=True ), Cell( 'A-three' ) ) table.AddRow( Cell( 'A-one' ), Cell( 'A-two', start_vertical_merge=True ), Cell( 'A-three' ) ) table.AddRow( Cell( 'A-one' ), Cell( vertical_merge=True ), Cell( 'A-three' ) ) section.append( table ) return doc
def make_paraTabLeaders(): doc, section, styles = RTFTestCase.initializeDoc() section.append( "The alignment of tabs and style can also be controlled. The " "following demonstrates how to use flush right tabs and the " "supported leaders." ) def _makePara(name): tabs = TabPropertySet( section.TwipsToRightMargin(), alignment=TabPropertySet.RIGHT, leader=getattr(TabPropertySet, name.upper().replace(" ", "_")), ) para_props = ParagraphPropertySet(tabs=[tabs]) return Paragraph(styles.ParagraphStyles.Normal, para_props) for name in ["Dots", "Hyphens", "Underline", "Thick Line", "Equal Sign"]: p = _makePara(name) p.append("Before %s" % name, TAB, "After %s" % name) section.append(p) return doc
def make_charColours(): doc, section, styles = RTFTestCase.initializeDoc() section.append('This example test changing the colour of fonts.') # Text properties can be specified in two ways, either a text object # can have its text properties specified via the TextPropertySet # object, or by passing the colour parameter as a style. red = TextPropertySet(colour=styles.Colours.Red) green = TextPropertySet(colour=styles.Colours.Green) blue = TextPropertySet(colour=styles.Colours.Blue) yellow = TextPropertySet(colour=styles.Colours.Yellow) p = Paragraph() p.append('This next word should be in ') p.append(Text('red', red)) p.append(', while the following should be in their respective ') p.append('colours: ', Text('blue ', blue), Text('green ', green)) p.append('and ', TEXT('yellow', colour=styles.Colours.Yellow), '.') # When specifying colours it is important to use the colours from the # style sheet supplied with the document and not the StandardColours # object each document get its own copy of the stylesheet so that # changes can be made on a document by document basis without mucking # up other documents that might be based on the same basic stylesheet. section.append(p) return doc
def make_paraHeading(): doc, section, styles = RTFTestCase.initializeDoc() p1 = Paragraph(styles.ParagraphStyles.Heading1) p1.append('Heading 1') section.append(p1) return doc
def make_landscapeMode(): doc, section, styles = RTFTestCase.initializeDoc() section.SetLandscape(True) section.append( 'This should be going along the long side of the paper.') return doc
def make_sectionEmpty(): """ Used by a script to generate docs. """ return RTFTestCase.initializeDoc()[0]
def make_landscapeMode(): doc, section, styles = RTFTestCase.initializeDoc() section.SetLandscape(True) section.append('This should be going along the long side of the paper.') return doc
def make_sectionWithBlankPara(): doc, section, styles = RTFTestCase.initializeDoc() section.append('Small paragraph.') # blank paragraphs are just empty strings section.append('') return doc
def make_tables(): doc, section, styles = RTFTestCase.initializeDoc() p = Paragraph( styles.ParagraphStyles.Heading1 ) p.append( 'Example 3' ) section.append( p ) # changes what is now the default style of Heading1 back to Normal p = Paragraph( styles.ParagraphStyles.Normal ) p.append( 'Example 3 demonstrates tables, tables represent one of the ' 'harder things to control in RTF as they offer alot of ' 'flexibility in formatting and layout.' ) section.append( p ) section.append( 'Table columns are specified in widths, the following example ' 'consists of a table with 3 columns, the first column is ' '7 tab widths wide, the next two are 3 tab widths wide. ' 'The widths chosen are arbitrary, they do not have to be ' 'multiples of tab widths.' ) table = Table( TabPropertySet.DEFAULT_WIDTH * 7, TabPropertySet.DEFAULT_WIDTH * 3, TabPropertySet.DEFAULT_WIDTH * 3 ) c1 = Cell( Paragraph( 'Row One, Cell One' ) ) c2 = Cell( Paragraph( 'Row One, Cell Two' ) ) c3 = Cell( Paragraph( 'Row One, Cell Three' ) ) table.AddRow( c1, c2, c3 ) c1 = Cell( Paragraph( styles.ParagraphStyles.Heading2, 'Heading2 Style' ) ) c2 = Cell( Paragraph( styles.ParagraphStyles.Normal, 'Back to Normal Style' ) ) c3 = Cell( Paragraph( 'More Normal Style' ) ) table.AddRow( c1, c2, c3 ) c1 = Cell( Paragraph( styles.ParagraphStyles.Heading2, 'Heading2 Style' ) ) c2 = Cell( Paragraph( styles.ParagraphStyles.Normal, 'Back to Normal Style' ) ) c3 = Cell( Paragraph( 'More Normal Style' ) ) table.AddRow( c1, c2, c3 ) section.append( table ) section.append( 'Different frames can also be specified for each cell in the table ' 'and each frame can have a different width and style for each border.' ) thin_edge = BorderPropertySet( width=20, style=BorderPropertySet.SINGLE ) thick_edge = BorderPropertySet( width=80, style=BorderPropertySet.SINGLE ) thin_frame = FramePropertySet( thin_edge, thin_edge, thin_edge, thin_edge ) thick_frame = FramePropertySet( thick_edge, thick_edge, thick_edge, thick_edge ) mixed_frame = FramePropertySet( thin_edge, thick_edge, thin_edge, thick_edge ) table = Table( TabPropertySet.DEFAULT_WIDTH * 3, TabPropertySet.DEFAULT_WIDTH * 3, TabPropertySet.DEFAULT_WIDTH * 3 ) c1 = Cell( Paragraph( 'R1C1' ), thin_frame ) c2 = Cell( Paragraph( 'R1C2' ) ) c3 = Cell( Paragraph( 'R1C3' ), thick_frame ) table.AddRow( c1, c2, c3 ) c1 = Cell( Paragraph( 'R2C1' ) ) c2 = Cell( Paragraph( 'R2C2' ) ) c3 = Cell( Paragraph( 'R2C3' ) ) table.AddRow( c1, c2, c3 ) c1 = Cell( Paragraph( 'R3C1' ), mixed_frame ) c2 = Cell( Paragraph( 'R3C2' ) ) c3 = Cell( Paragraph( 'R3C3' ), mixed_frame ) table.AddRow( c1, c2, c3 ) section.append( table ) section.append( 'In fact frames can be applied to paragraphs too, not just cells.' ) p = Paragraph( styles.ParagraphStyles.Normal, thin_frame ) p.append( 'This whole paragraph is in a frame.' ) section.append( p ) return doc
def make_paraHeading(): doc, section, styles = RTFTestCase.initializeDoc() p1 = Paragraph(styles.ParagraphStyles.Heading1) p1.append("Heading 1") section.append(p1) return doc
def make_sectionWithSmallPara(): doc, section, styles = RTFTestCase.initializeDoc() # text can be added directly to the section a paragraph object is # create as needed section.append('Small paragraph.') return doc