472,331 Members | 1,781 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,331 software developers and data experts.

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 4220
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

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

Similar topics

1
by: Ryan | last post by:
PowerPoint.Application cannot open PPT file I am trying to use the following code using to open a PPT file using VS.NET 2003 and PowerPoint 2003 ...
9
by: Tom Weston | last post by:
Help I have 4 databases containing different data relating to safety, not written by me. It is not possible to merge the databases into one large...
3
by: M Fisher | last post by:
I have an Access XP Database. On one of the forms I have a button that opens and Excel Spreadsheet as follows: Dim xl As Excel.Application ...
5
by: Java script Dude | last post by:
For those who are missing the feature on how to import into Open Office dBase app from text files and spreadsheets in OOO Base 2.0: A wizard...
8
by: sudha | last post by:
Hi, To open a word doc from c#, i use the following code : Word.ApplicationClass WordApp = new Word.ApplicationClass (); // give any file...
3
by: Richard Cleaveland | last post by:
A client has just successfully upgraded from Access 97 to 2000. I don't have Access 2000, but I do have Office XP. Can I successfully use my...
7
by: bkdraper via AccessMonster.com | last post by:
I currently have a handful of Access 2000 tools I've written for my office. Here in the next few weeks, the office is getting upgraded to Office...
0
by: TBass | last post by:
Hi, For years, I've been using visual basic and the Excel Object library version 9 and 10 to pass data back and forth between Visual Basic and...
2
by: saketmayur | last post by:
Hi , I have write the following code to open word document on server using Microsoft.Office.Interop.Word; string DocPath =...
0
by: tammygombez | last post by:
Hey fellow JavaFX developers, I'm currently working on a project that involves using a ComboBox in JavaFX, and I've run into a bit of an issue....
0
by: concettolabs | last post by:
In today's business world, businesses are increasingly turning to PowerApps to develop custom business applications. PowerApps is a powerful tool...
0
better678
by: better678 | last post by:
Question: Discuss your understanding of the Java platform. Is the statement "Java is interpreted" correct? Answer: Java is an object-oriented...
0
by: Kemmylinns12 | last post by:
Blockchain technology has emerged as a transformative force in the business world, offering unprecedented opportunities for innovation and...
0
by: CD Tom | last post by:
This only shows up in access runtime. When a user select a report from my report menu when they close the report they get a menu I've called Add-ins...
0
jalbright99669
by: jalbright99669 | last post by:
Am having a bit of a time with URL Rewrite. I need to incorporate http to https redirect with a reverse proxy. I have the URL Rewrite rules made...
0
by: Matthew3360 | last post by:
Hi there. I have been struggling to find out how to use a variable as my location in my header redirect function. Here is my code. ...
2
by: Matthew3360 | last post by:
Hi, I have a python app that i want to be able to get variables from a php page on my webserver. My python app is on my computer. How would I make it...
0
by: AndyPSV | last post by:
HOW CAN I CREATE AN AI with an .executable file that would suck all files in the folder and on my computerHOW CAN I CREATE AN AI with an .executable...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.