def generate_xml(self, stream): from calibre.ebooks.rtf2xml.ParseRtf import ParseRtf ofile = u'dataxml.xml' run_lev, debug_dir, indent_out = 1, None, 0 if getattr(self.opts, 'debug_pipeline', None) is not None: try: os.mkdir(u'rtfdebug') debug_dir = u'rtfdebug' run_lev = 4 indent_out = 1 self.log('Running RTFParser in debug mode') except: self.log.warn('Impossible to run RTFParser in debug mode') parser = ParseRtf( in_file = stream, out_file = ofile, # Convert symbol fonts to unicode equivalents. Default # is 1 convert_symbol = 1, # Convert Zapf fonts to unicode equivalents. Default # is 1. convert_zapf = 1, # Convert Wingding fonts to unicode equivalents. # Default is 1. convert_wingdings = 1, # Convert RTF caps to real caps. # Default is 1. convert_caps = 1, # Indent resulting XML. # Default is 0 (no indent). indent = indent_out, # Form lists from RTF. Default is 1. form_lists = 1, # Convert headings to sections. Default is 0. headings_to_sections = 1, # Group paragraphs with the same style name. Default is 1. group_styles = 1, # Group borders. Default is 1. group_borders = 1, # Write or do not write paragraphs. Default is 0. empty_paragraphs = 1, #debug deb_dir = debug_dir, run_level = run_lev, ) parser.parse_rtf() with open(ofile, 'rb') as f: return f.read()
def generate_xml(self, stream): from calibre.ebooks.rtf2xml.ParseRtf import ParseRtf ofile = u'dataxml.xml' run_lev, debug_dir, indent_out = 1, None, 0 if getattr(self.opts, 'debug_pipeline', None) is not None: try: os.mkdir(u'rtfdebug') debug_dir = u'rtfdebug' run_lev = 4 indent_out = 1 self.log('Running RTFParser in debug mode') except: self.log.warn('Impossible to run RTFParser in debug mode') parser = ParseRtf( in_file=stream, out_file=ofile, # Convert symbol fonts to unicode equivalents. Default # is 1 convert_symbol=1, # Convert Zapf fonts to unicode equivalents. Default # is 1. convert_zapf=1, # Convert Wingding fonts to unicode equivalents. # Default is 1. convert_wingdings=1, # Convert RTF caps to real caps. # Default is 1. convert_caps=1, # Indent resulting XML. # Default is 0 (no indent). indent=indent_out, # Form lists from RTF. Default is 1. form_lists=1, # Convert headings to sections. Default is 0. headings_to_sections=1, # Group paragraphs with the same style name. Default is 1. group_styles=1, # Group borders. Default is 1. group_borders=1, # Write or do not write paragraphs. Default is 0. empty_paragraphs=1, #debug deb_dir=debug_dir, run_level=run_lev, ) parser.parse_rtf() with open(ofile, 'rb') as f: return f.read()