469,602 Members | 1,793 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,602 developers. It's quick & easy.

Open Office 2.4 converting .doc to .pdf

Hi guys

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
  1. #This script compares two Word documents with OpenOffice via the PyUNO Bridge and shows the differents in PDF file.
  2. #The PDF result is the original Word document with highlighted diffs. This script came from
  3. #http://mithrandr.moria.org/blog/447.html.
  4.  
  5. #Before you run this script in the OpenOffice program directory with the python.bat you should start OpenOffice in server
  6. #mode like:
  7.  
  8. #soffice -headless -invisible '-accept=socket,host=localhost,port=2002;urp;
  9.  
  10. #!/usr/bin/env python
  11.  
  12.  
  13.  
  14. import uno
  15. import socket
  16.  
  17. from com.sun.star.beans import PropertyValue
  18. from com.sun.star.task import ErrorCodeIOException
  19.  
  20. url = uno.systemPathToFileUrl('c:\\OpenOffice_24\\program\\kn2.doc')
  21. url_original = uno.systemPathToFileUrl('c:\\OpenOffice_24\\program\\kn.doc')
  22. url_save = uno.systemPathToFileUrl('c:\\OpenOffice_24\\program\\kn_diff.pdf')
  23.  
  24. ### Get Service Manager
  25. context = uno.getComponentContext()
  26. resolver = context.ServiceManager.createInstanceWithContext("com.sun.star.bridge.UnoUrlResolver", context)
  27. ctx = resolver.resolve("uno:socket,host=localhost,port=2002;urp;StarOffice.ComponentContext")
  28. smgr = ctx.ServiceManager
  29.  
  30. ### Load document
  31. properties = []
  32. p = PropertyValue()
  33. p.Name = "Hidden"
  34. p.Value = True
  35. properties.append(p)
  36. properties = tuple(properties)
  37. desktop = smgr.createInstanceWithContext("com.sun.star.frame.Desktop", ctx)
  38. doc = desktop.loadComponentFromURL(url, "_blank", 0, properties)
  39.  
  40. ### Compare with original document
  41. properties = []
  42. p = PropertyValue()
  43. p.Name = "URL"
  44. p.Value = url_original
  45. properties.append(p)
  46. properties = tuple(properties)
  47. dispatch_helper = smgr.createInstanceWithContext("com.sun.star.frame.DispatchHelper", ctx)
  48. dispatch_helper.executeDispatch(doc.getCurrentController().getFrame(), ".uno:CompareDocuments", "", 0, properties)
  49.  
  50. ### Save File
  51. properties = []
  52. p = PropertyValue()
  53. p.Name = "Overwrite"
  54. p.Value = True
  55. properties.append(p)
  56. p = PropertyValue()
  57. p.Name = "FilterName"
  58. p.Value = 'writer_pdf_Export'
  59. properties.append(p)
  60. properties = tuple(properties)
  61. try:
  62.   doc.storeAsURL(url_save, properties)
  63. except ErrorCodeIOException, e:
  64.   import sys
  65.   import traceback
  66.   import cStringIO
  67.   (exc_type, exc_value, tb) = sys.exc_info()
  68.   error_file = cStringIO.StringIO()
  69.   traceback.print_exception(exc_type, exc_value, tb,
  70.                             file=error_file)
  71.   stacktrace=error_file.getvalue()
  72.   print "Failed while writing: '%s'" % url_save
  73.   print stacktrace
  74. doc.dispose()
  75.  
why does it fail while writing pdf? on :
Expand|Select|Wrap|Line Numbers
  1. doc.storeAsURL(url_save, properties)
Thank you so much
Oct 17 '08 #1
1 3999
okay found out.

This line
Expand|Select|Wrap|Line Numbers
  1.   doc.storeAsURL(url_save, properties)
  2.  
needs to be changed to:
Expand|Select|Wrap|Line Numbers
  1.   doc.storeToURL(url_save, properties)
  2.  
All the best
Oct 17 '08 #2

Post your reply

Sign in to post your reply or Sign up for a free account.

Similar topics

1 post views Thread by Ryan | last post: by
3 posts views Thread by M Fisher | last post: by
8 posts views Thread by sudha | last post: by
7 posts views Thread by bkdraper via AccessMonster.com | last post: by
reply views Thread by TBass | last post: by
4 posts views Thread by guiromero | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.