5 from unohelper import Base, systemPathToFileUrl, absolutize
 
   7 from os.path import splitext
 
   8 from com.sun.star.beans import PropertyValue
 
  10 def establish_connection(port):
 
  11   local_ctx = uno.getComponentContext()
 
  12   local_smgr = local_ctx.ServiceManager
 
  14   resolver = local_smgr.createInstanceWithContext("com.sun.star.bridge.UnoUrlResolver", local_ctx)
 
  15   ctx = resolver.resolve("uno:socket,host=localhost,port=%s;urp;StarOffice.ComponentContext" % port)
 
  16   smgr = ctx.ServiceManager
 
  18   desktop = smgr.createInstanceWithContext("com.sun.star.frame.Desktop", ctx)
 
  22 def load_file(desktop, path):
 
  23   cwd = systemPathToFileUrl(getcwd())
 
  24   file_url = absolutize(cwd, systemPathToFileUrl(path))
 
  25   sys.stderr.write(file_url + "\n")
 
  28     #   PropertyValue("Hidden", 0 , True, 0),
 
  30   return desktop.loadComponentFromURL(file_url, "_blank", 0, in_props)
 
  33 def write_pdf(doc, path):
 
  35     PropertyValue("FilterName", 0, "writer_pdf_Export", 0),
 
  36     PropertyValue("Overwrite", 0, True, 0),
 
  39   (dest, ext) = splitext(path)
 
  41   dest_url = absolutize(systemPathToFileUrl(getcwd()), systemPathToFileUrl(dest))
 
  42   sys.stderr.write(dest_url + "\n")
 
  43   doc.storeToURL(dest_url, out_props)
 
  47   if len(sys.argv) <= 2:
 
  51     desktop = establish_connection(sys.argv[1])
 
  56     doc = load_file(desktop, sys.argv[2])
 
  63     write_pdf(doc, sys.argv[2])