Exemplo n.º 1
0
class LibreOfficeContext(object):
    def __init__(self, host, port, input_path):
        self.host = host
        self.port = port
        self.input_path = input_path

    def __enter__(self):
        context = connect(Socket(self.host, self.port))
        self.writer = Writer(context, convert_path_to_url(self.input_path))
        return self

    def __exit__(self, type, value, traceback):
        self.writer.close(True)

    def write(self, path):
        self.writer.store_to_url(convert_path_to_url(path), 'FilterName',
                                 'writer_pdf_Export')
Exemplo n.º 2
0
def get_component(args, context):
    _, ext = splitext(args.file_)
    url = convert_path_to_url(args.file_)
    if ext == '.odt':
        component = Writer(context, url)
    elif ext == '.ods':
        component = Calc(context, url)
    else:
        raise ValueError('Supported file type are [odt|ods]: {}'.format(ext))
    return component
Exemplo n.º 3
0
class LibreOfficeContext(object):
    def __init__(self, host, port, input_path):
        self.host = host
        self.port = port
        self.input_path = input_path

    def __enter__(self):
        context = connect(Socket(self.host, self.port))
        self.writer = Writer(context, convert_path_to_url(self.input_path))
        return self

    def __exit__(self, type, value, traceback):
        self.writer.close(True)

    def write(self, path):
        self.writer.store_to_url(
            convert_path_to_url(path),
            'FilterName',
            'writer_pdf_Export'
        )
Exemplo n.º 4
0
def get_document(file, connection):
    """
    Load the component containing the word document.

    @param connection (ScriptContext) - connection to the headless LibreOffice process

    @param file (str) - path to the Word doc

    @return document (Writer)
    """

    url = convert_path_to_url(file)
    document = Writer(connection, url)
    return document
def get_document(fname, connection):
    """Load the component containing the word document.

    @param connection (ScriptContext) Connection to the headless LibreOffice process

    @param fname (str) Path to the Word doc

    @return document (Writer) UNO object representing the loaded Word
    document.

    """

    url = convert_path_to_url(fname)
    document = Writer(connection, url)
    return document
Exemplo n.º 6
0
def writer_sample(args, context):
    writer = Writer(context)
    writer.set_string_to_end('world\n')
    writer.set_string_to_start('hello\n')

    base_path = convert_path_to_url(pathjoin(args.outputdir, 'sample'))
    writer.store_to_url(base_path + '.odt', 'FilterName', 'writer8')
    writer.store_to_url(base_path + '.doc', 'FilterName', 'MS Word 97')
    writer.store_to_url(base_path + '-writer.pdf', 'FilterName',
                        'writer_pdf_Export')
    writer.store_to_url(base_path + '-writer.html', 'FilterName',
                        'HTML (StarWriter)')

    writer.close(True)
Exemplo n.º 7
0
 def __enter__(self):
     context = connect(Socket(self.host, self.port))
     self.writer = Writer(context, convert_path_to_url(self.input_path))
     return self
Exemplo n.º 8
0
 def __enter__(self):
     context = connect(Socket(self.host, self.port))
     self.writer = Writer(context, convert_path_to_url(self.input_path))
     return self