473,563 Members | 2,653 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Open Office 2.4 converting .doc to .pdf

7 New Member
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 4381
setori88
7 New Member
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
6349
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 Option Strict Off Imports System.Runtime.InteropServices Imports Microsoft.Office.Interop Imports Microsoft.Office.Interop.PowerPoint Imports Microsoft.Office.Core Imports...
9
2095
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 data base. I would like to create a user interface with 4 buttons, one for each database. The aim would be for the user to click on a button and the related database opens for use. When the database...
3
17458
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 Set xl = New Excel.Application xl.Application.Workbooks.Add xl.Cells(1,1) = "Some Text From the database" etc.
5
7101
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 exists to import from spreadsheets only at this time but there is no menu pick for `importing` at this time. OOO 2.0 dBase Import SOP: 1) Open the spreadsheet -or- text file as a spreadsheet 2)...
8
3166
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 name of your choice. object fileName = "C:\\test.doc"; object readOnly = false;
3
1641
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 Access on their database? They kind of did this behind my back, and I'm responsible for the application maintenance...! Dick
7
6362
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 2007. My question is, does anybody know how much trouble my Access 2000 tools are going to have running on Access 2007? Am I going to have to rewrite all my code (or half, or 1/3 of my code) or...
0
1800
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 Microsoft Excel. A few months ago, we changed over to Visual Basic .NET 2003. After converting the project, I dropped in my code from from the vb6 days, did a few slight modifications, refereneced...
2
4419
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 = System.Configuration.ConfigurationManager.AppSettings; ApplicationClass wordApp = new ApplicationClass(); string filePath = ""; filePath = DocPath + Session + "/" +...
0
7664
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7583
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
7885
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
0
8106
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
0
6250
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
0
3642
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
0
3626
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2082
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
1198
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.