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_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
(2, TabPropertySet.DEFAULT_WIDTH * 2), (3, TabPropertySet.DEFAULT_WIDTH * 3)]: indent = TabPropertySet.DEFAULT_WIDTH ps = ParagraphStyle('List %s' % idx, TextStyle(TextPropertySet(result.Fonts.Arial, 22)), ParagraphPropertySet( space_before=60, space_after=60, first_line_indent=-indent, left_indent=indent)) result.ParagraphStyles.append(ps) return result PAGE_NUMBER = RawCode(r'{\field{\fldinst page}}') TOTAL_PAGES = RawCode(r'{\field{\fldinst numpages}}') SECTION_PAGES = RawCode(r'{\field{\fldinst sectionpages}}') ARIAL_BULLET = RawCode(r'{\f2\'95}') class Document: def __init__(self, style_sheet=None, default_language=None, view_kind=None, view_zoom_kind=None, view_scale=None): self.StyleSheet = style_sheet or MakeDefaultStyleSheet() self.Sections = AttributedList(Section)