this script i downloaded from here, http://win32com.goermezer.de/index.p...193&Itemid=274
I copied this script and setup and instance of open office writer.
created a .doc file and a copied it making a change to that file.
here is the code
Expand|Select|Wrap|Line Numbers
- #This script compares two Word documents with OpenOffice via the PyUNO Bridge and shows the differents in PDF file.
- #The PDF result is the original Word document with highlighted diffs. This script came from
- #http://mithrandr.moria.org/blog/447.html.
- #Before you run this script in the OpenOffice program directory with the python.bat you should start OpenOffice in server
- #mode like:
- #soffice -headless -invisible '-accept=socket,host=localhost,port=2002;urp;
- #!/usr/bin/env python
- import uno
- import socket
- from com.sun.star.beans import PropertyValue
- from com.sun.star.task import ErrorCodeIOException
- url = uno.systemPathToFileUrl('c:\\OpenOffice_24\\program\\kn2.doc')
- url_original = uno.systemPathToFileUrl('c:\\OpenOffice_24\\program\\kn.doc')
- url_save = uno.systemPathToFileUrl('c:\\OpenOffice_24\\program\\kn_diff.pdf')
- ### Get Service Manager
- context = uno.getComponentContext()
- resolver = context.ServiceManager.createInstanceWithContext("com.sun.star.bridge.UnoUrlResolver", context)
- ctx = resolver.resolve("uno:socket,host=localhost,port=2002;urp;StarOffice.ComponentContext")
- smgr = ctx.ServiceManager
- ### Load document
- properties = []
- p = PropertyValue()
- p.Name = "Hidden"
- p.Value = True
- properties.append(p)
- properties = tuple(properties)
- desktop = smgr.createInstanceWithContext("com.sun.star.frame.Desktop", ctx)
- doc = desktop.loadComponentFromURL(url, "_blank", 0, properties)
- ### Compare with original document
- properties = []
- p = PropertyValue()
- p.Name = "URL"
- p.Value = url_original
- properties.append(p)
- properties = tuple(properties)
- dispatch_helper = smgr.createInstanceWithContext("com.sun.star.frame.DispatchHelper", ctx)
- dispatch_helper.executeDispatch(doc.getCurrentController().getFrame(), ".uno:CompareDocuments", "", 0, properties)
- ### Save File
- properties = []
- p = PropertyValue()
- p.Name = "Overwrite"
- p.Value = True
- properties.append(p)
- p = PropertyValue()
- p.Name = "FilterName"
- p.Value = 'writer_pdf_Export'
- properties.append(p)
- properties = tuple(properties)
- try:
- doc.storeAsURL(url_save, properties)
- except ErrorCodeIOException, e:
- import sys
- import traceback
- import cStringIO
- (exc_type, exc_value, tb) = sys.exc_info()
- error_file = cStringIO.StringIO()
- traceback.print_exception(exc_type, exc_value, tb,
- file=error_file)
- stacktrace=error_file.getvalue()
- print "Failed while writing: '%s'" % url_save
- print stacktrace
- doc.dispose()
Expand|Select|Wrap|Line Numbers
- doc.storeAsURL(url_save, properties)