def _import_styles(self, book): from django.conf import settings options = {} if hasattr(self.dfile.document, 'base_font_size') and \ self.dfile.document.base_font_size != -1: options['scale_to_size'] = self.dfile.document.base_font_size elif len(self.dfile.document.possible_text) > 0: options['scale_to_size'] = self.dfile.document.possible_text[-1] editor_style = serialize.serialize_styles( self.dfile.document, prefix='#contenteditor', options=options) epub_style = serialize.serialize_styles( self.dfile.document, prefix='', options=options) dir_name = '{}/styles/{}/'.format(settings.DATA_ROOT, book.url_title) if not os.path.exists(dir_name): os.makedirs(dir_name) f = open('{}/editor_style.css'.format(dir_name), 'wt') f.write(STYLE_EDITOR) f.write(editor_style) f.close() f = open('{}/epub_style.css'.format(dir_name), 'wt') f.write(STYLE_EPUB) f.write(epub_style) f.close()
def _import_styles(self, book): from django.conf import settings options = {} if hasattr(self.dfile.document, 'base_font_size') and \ self.dfile.document.base_font_size != -1: options['scale_to_size'] = self.dfile.document.base_font_size elif len(self.dfile.document.possible_text) > 0: options['scale_to_size'] = self.dfile.document.possible_text[-1] editor_style = serialize.serialize_styles(self.dfile.document, prefix='#contenteditor', options=options) epub_style = serialize.serialize_styles(self.dfile.document, prefix='', options=options) dir_name = '{}/styles/{}/'.format(settings.DATA_ROOT, book.url_title) if not os.path.exists(dir_name): os.makedirs(dir_name) f = open('{}/editor_style.css'.format(dir_name), 'wt') f.write(STYLE_EDITOR) f.write(editor_style) f.close() f = open('{}/epub_style.css'.format(dir_name), 'wt') f.write(STYLE_EPUB) f.write(epub_style) f.close()
import sys import six import logging import ooxml from ooxml import parse, serialize, importer logging.basicConfig(filename='ooxml.log', level=logging.INFO) if len(sys.argv) > 1: file_name = sys.argv[1] dfile = ooxml.read_from_file(file_name) six.print_("\n-[HTML]-----------------------------\n") six.print_(serialize.serialize(dfile.document)) six.print_("\n-[CSS STYLE]------------------------\n") six.print_(serialize.serialize_styles(dfile.document)) six.print_("\n-[USED STYLES]----------------------\n") six.print_(dfile.document.used_styles) six.print_("\n-[USED FONT SIZES]------------------\n") six.print_(dfile.document.used_font_size)
import sys import logging from lxml import etree import ooxml from ooxml import parse, serialize, importer logging.basicConfig(filename='ooxml.log', level=logging.INFO) if len(sys.argv) > 1: file_name = sys.argv[1] dfile = ooxml.read_from_file(file_name) print("serialize : ", serialize.serialize(dfile.document)) print("serialize style : ", serialize.serialize_styles(dfile.document))