OpenOffice.org Forum at OOoForum.orgThe OpenOffice.org Forum
 
 [Home]   [FAQ]   [Search]   [Memberlist]   [Usergroups]   [Register
 [Profile]   [Log in to check your private messages]   [Log in

Converting DOCs to SXWs

 
Post new topic   Reply to topic    OOoForum.org Forum Index -> OpenOffice.org Writer
View previous topic :: View next topic  
Author Message
Guest






PostPosted: Wed Mar 10, 2004 9:53 pm    Post subject: Converting DOCs to SXWs Reply with quote

Is there a utility to convert MS Word's .doc documents to OO's .sxw document from Linux command line?

BTW, I know about File/Autopilot/Document Converter, which is nice. I just want to do the same in a shell script.

Thanks!
Back to top
DannyB
Moderator
Moderator


Joined: 02 Apr 2003
Posts: 3991
Location: Lawrence, Kansas, USA

PostPosted: Thu Mar 11, 2004 8:14 am    Post subject: Reply with quote

The subject of document conversion does come up over and over again here on OOoForum. We probably need a FAQ. I need to write up a general "Document Conversion" HOWTO.

These are the most relevant past topics....

Converting Word -> PDF from the command line
http://www.oooforum.org/forum/viewtopic.php?t=3772
http://www.oooforum.org/forum/viewtopic.php?t=5513

Convert Excel -> PDF from the command line
http://www.oooforum.org/forum/viewtopic.php?t=5596

Convert PPT to HTML from command line...
http://www.oooforum.org/forum/viewtopic.php?t=5137

The example for converting Wort to PDF from the command line would be the most suitable. Since you've converting from Word (recognized format) you don't need any improt filter. Since you're saving to SXW (default format) you don't need any export filter either. So these above examples should be very easy to adapt.



Here are other past discussions.....

Document Conversion
===================

List of many past conversion examples
http://www.oooforum.org/forum/viewtopic.php?t=4998

Filter list
http://www.oooforum.org/forum/viewtopic.php?t=3549

Xcel to Calc conversion using the API
http://www.oooforum.org/forum/viewtopic.php?t=2668

A very similar one, converting Xcel to Text
http://www.oooforum.org/forum/viewtopic.php?t=2819

Batch mode conversion
http://www.oooforum.org/forum/viewtopic.php?p=16056#16056

Document conversion
http://www.oooforum.org/forum/viewtopic.php?t=4163

VB: converting Excel files to txt files
http://www.oooforum.org/forum/viewtopic.php?t=3194
General Visual Basic document conversion of Text...
http://www.oooforum.org/forum/viewtopic.php?p=22034#22034

Converting Word -> PDF from the command line
http://www.oooforum.org/forum/viewtopic.php?t=3772
http://www.oooforum.org/forum/viewtopic.php?t=5513

Convert Excel -> PDF from the command line
http://www.oooforum.org/forum/viewtopic.php?t=5596

Convert PPT to HTML from command line...
http://www.oooforum.org/forum/viewtopic.php?t=5137

see tail end of thread...
http://www.oooforum.org/forum/viewtopic.php?t=3772

Converting SXW -> PDF
http://www.oooforum.org/forum/viewtopic.php?t=3017

In Python...
http://www.oooforum.org/forum/viewtopic.php?t=3451

Thread about converting document to PDF in Java
http://www.oooforum.org/forum/viewtopic.php?t=1480

I wrote a batch document converter
http://www.oooforum.org/forum/viewtopic.php?t=3525
http://www.oooforum.org/forum/viewtopic.php?t=2810
http://www.oooforum.org/forum/viewtopic.php?p=10311#10311
you can get it here
http://www.ooomacros.org/files.php?type=macro#DocumentConverter
more discussion of it here...
http://www.oooforum.org/forum/viewtopic.php?t=5708

Macro to save in three formats
http://www.oooforum.org/forum/viewtopic.php?t=3612
http://www.oooforum.org/forum/viewtopic.php?t=5308
http://www.oooforum.org/forum/viewtopic.php?t=3973
http://www.oooforum.org/forum/viewtopic.php?t=3768
http://www.oooforum.org/forum/viewtopic.php?t=3620
http://www.oooforum.org/forum/viewtopic.php?t=3545
http://www.oooforum.org/forum/viewtopic.php?t=3476
http://www.oooforum.org/forum/viewtopic.php?t=3017

Discussion that ends in DocConverter utility.
http://www.oooforum.org/forum/viewtopic.php?t=2668

Convert DBF into XLS, SXC, PDF and HTML
http://www.oooforum.org/forum/viewtopic.php?t=5728



Using OOo's source code to read / convert / write documents
in the formats supported by its filters.
http://www.oooforum.org/forum/viewtopic.php?t=5785




Command line arguments
======================
http://www.oooforum.org/forum/viewtopic.php?t=4899
http://fr.openoffice.org/Documentation/How-to/Basic/command%20parameters.htm
http://www.oooforum.org/forum/viewtopic.php?p=11058#11058
http://www.oooforum.org/forum/viewtopic.php?p=10972#10972
http://www.oooforum.org/forum/viewtopic.php?t=3548

See "The Office Headless Mode" at this site...
http://framework.openoffice.org/servlets/ProjectDocumentList

Passing array of arguments to macro
http://www.oooforum.org/forum/viewtopic.php?t=3745

Use .uno:Open to display open dialog
http://www.oooforum.org/forum/viewtopic.php?t=4224

Command-line options of StarOffice
http://www.oooforum.org/forum/viewtopic.php?t=1789

http://framework.openoffice.org/files/documents/25/806/Command_line_arguments_in_OpenOffice.html

Run Impress presentation from command line
http://www.oooforum.org/forum/viewtopic.php?t=1051



Executing Macros via. URL or command line
or via. dispatcher
=========================================

Use a macro:/// url via. the Dispatcher
http://www.oooforum.org/forum/viewtopic.php?t=6079


http://www.oooforum.org/forum/viewtopic.php?t=4071
http://www.oooforum.org/forum/viewtopic.php?p=15589#15589
http://www.oooforum.org/forum/viewtopic.php?p=9861#9861
http://www.oooforum.org/forum/viewtopic.php?p=17377#17377
http://www.oooforum.org/forum/viewtopic.php?t=3196
http://www.oooforum.org/forum/viewtopic.php?t=2619
http://www.oooforum.org/forum/viewtopic.php?p=11794#11794

http://www.oooforum.org/forum/viewtopic.php?p=13053#13053

http://www.oooforum.org/forum/viewtopic.php?t=4285

http://www.oooforum.org/forum/viewtopic.php?t=3772

http://www.oooforum.org/forum/viewtopic.php?t=4163

http://www.oooforum.org/forum/viewtopic.php?t=2688

Calling macro in different document, and pass parameter...
http://www.oooforum.org/forum/viewtopic.php?t=5564

Call macro in different document from VB and pass parameter...
http://www.oooforum.org/forum/viewtopic.php?t=6221
_________________
Want to make OOo Drawings like the colored flower design to the left?
Back to top
View user's profile Send private message
DannyB
Moderator
Moderator


Joined: 02 Apr 2003
Posts: 3991
Location: Lawrence, Kansas, USA

PostPosted: Thu Mar 11, 2004 8:20 am    Post subject: Reply with quote

Since you didn't ask this in the Macros and API section, I'm going to custom taylor one of the past examples. Here is the text of the first link I gave you above, but with minor editing.....


You need a Macro to do the work. That part is written in OOo's dialect of Basic.

Get into OpenOffice.org.

Tools -> Macros -> Macro....

Now click the button Organizer.....

Click the Libraries tab.

Set Application/Document to "soffice".

Click the button New...

Give the library the name "DannysLibrary".

Now click the Modules tab.

Unfold the tree of items under soffice. Find DannysLibrary and hilight it. Click the button New Module...

Name the module "Conversion".

The Basic IDE window should appear. Paste in the following code. Be sure to watch out for trailing spaces on lines copied from this web site. Especially on lines ending with an underscore, there cannot be any trailing spaces.

Code:
Sub ConvertWordToWriter( cFile )
   cURL = ConvertToURL( cFile )
   
   ' Open the document.
   ' Just blindly assume that the document is of a type that OOo will
   '  correctly recognize and open -- without specifying an import filter.
   oDoc = StarDesktop.loadComponentFromURL( cURL, "_blank", 0, Array(_
            MakePropertyValue( "Hidden", True ),_
            ) )


   cFile = Left( cFile, Len( cFile ) - 4 ) + ".pdf"
   cURL = ConvertToURL( cFile )
   
   ' Save the document using no filter.  Thus saves a native Writer document.
   oDoc.storeToURL( cURL, Array() )
   
   oDoc.close( True )
End Sub


Function MakePropertyValue( Optional cName As String, Optional uValue ) As com.sun.star.beans.PropertyValue
   Dim oPropertyValue As New com.sun.star.beans.PropertyValue
   If Not IsMissing( cName ) Then
      oPropertyValue.Name = cName
   EndIf
   If Not IsMissing( uValue ) Then
      oPropertyValue.Value = uValue
   EndIf
   MakePropertyValue() = oPropertyValue
End Function


This macro code is now part of OpenOffice.org and not specific to any document. That is, the macro is available at all times. Even if no documents are currently open.

Now write a Windows batch file. (Or a Linux shell script, let me know if I need to do this on Linux and post a followup.)

Code:
@ECHO OFF

"c:\program files\OpenOffice.org1.1.0\program\soffice" -invisible "macro:///DannysLibrary.Conversion.ConvertWordToWriter(%1)"


Be sure that you do not have any spaces between the parenthesis and the %1.

Now from the command line, run your BAT file like this...

Code:
convert  c:\test.doc


A new file c:\test.sxw should appear.

If you want to convert bunches of documents, I have written a document converter utility that you can get over on the web site OOoMacros.org.
_________________
Want to make OOo Drawings like the colored flower design to the left?
Back to top
View user's profile Send private message
Guest






PostPosted: Fri Mar 12, 2004 7:17 am    Post subject: Reply with quote

Thank you, DannyB. You are a great help. Very Happy
Back to top
reagle
Newbie
Newbie


Joined: 06 May 2005
Posts: 1

PostPosted: Fri May 06, 2005 8:01 am    Post subject: Sorry, this doesn work Reply with quote

The "ConvertWordToWriter" simply creates a copy of the Word file with a '.pdf' extension. If I change:
cFile = Left( cFile, Len( cFile ) - 4 ) + ".pdf"
to:
cFile = Left( cFile, Len( cFile ) - 4 ) + ".sxw"
same thing, just with a sxw extension.

Using OO.org 1.1.3 on Ubuntu Hoary.
Back to top
View user's profile Send private message
god_is_good478
Newbie
Newbie


Joined: 08 Sep 2005
Posts: 2

PostPosted: Thu Sep 08, 2005 8:19 pm    Post subject: tested it a bit Reply with quote

Oki I made some changes so that it works with OO beta 2 1.9.125

I have also tested it with 1.9.79, but it had problems if the test.doc is placed on the desktop, placing the file in C:\temp solved it though...




edited from original post::::::---

Get into OpenOffice.org.

Any application would do.

Tools -> Macros -> Organise macros -> VB Basic

A dialog will appear.

Now click the button Organizer.....

Click the Libraries tab.

Set location to "My Macros and Dialogs".

Click the button New...

Give the library the name "DannysLibrary".

Now click the Modules tab.

Unfold the tree of items under "My Macros". Find DannysLibrary and highlight it. Click the button New Module...

Name the module "Conversion". Click Ok. Close the organiser. You should still have the macros dialog box.

Under "Macro from"

My Macros -> DannysLibrary -> Conversion (click on it)

click on the "edit" button
The Basic IDE window should appear.

Paste in the following code. Be sure to watch out for trailing spaces on lines copied from this web site. Especially on lines

ending with an underscore, there cannot be any trailing spaces.

Code:
Sub ConvertWordToWriter( cFile )
cURL = ConvertToURL( cFile )

' Open the document.
' Just blindly assume that the document is of a type that OOo will
' correctly recognize and open -- without specifying an import filter.
oDoc = StarDesktop.loadComponentFromURL( cURL, "_blank", 0, Array(_
MakePropertyValue( "Hidden", True ),_
) )


cFile = Left( cFile, Len( cFile ) - 4 ) + ".odt"
cURL = ConvertToURL( cFile )

' Save the document using no filter. Thus saves a native Writer document.
oDoc.storeToURL( cURL, Array() )

oDoc.close( True )
End Sub


Function MakePropertyValue( Optional cName As String, Optional uValue ) As com.sun.star.beans.PropertyValue
Dim oPropertyValue As New com.sun.star.beans.PropertyValue
If Not IsMissing( cName ) Then
oPropertyValue.Name = cName
EndIf
If Not IsMissing( uValue ) Then
oPropertyValue.Value = uValue
EndIf
MakePropertyValue() = oPropertyValue
End Function


This macro code is now part of OpenOffice.org and not specific to any document. That is, the macro is available at all times.

Even if no documents are currently open.

Now write a Windows batch file. (Or a Linux shell script, let me know if I need to do this on Linux and post a followup.)

Code:
@ECHO OFF

@ECHO OFF

"C:\Program Files\OpenOffice.org 1.9.125\program\soffice" -invisible "macro:///edmundsLibrary.Conversion.ConvertWordToWriter

(%1)"


Be sure that you do not have any spaces between the parenthesis and the %1.

Now from the command line, run your BAT file like this...

Code:
convert c:\test.doc


A new file c:\test.odt should appear.
Back to top
View user's profile Send private message
god_is_good478
Newbie
Newbie


Joined: 08 Sep 2005
Posts: 2

PostPosted: Thu Sep 08, 2005 8:32 pm    Post subject: Reply with quote

and many many thanks to the original poster, DannyB! =)
Back to top
View user's profile Send private message
ramparte
Newbie
Newbie


Joined: 16 Nov 2005
Posts: 1

PostPosted: Wed Nov 16, 2005 9:51 pm    Post subject: HTML with images? Reply with quote

I understand how to convert from HTML to Doc or swx and have this working. My question has to do with images - is there some property I can set to tell the export filter to import images instead of leaving them with external urls? E.g. I want to have the image data itself in the swx or odt (or doc) file, not externally referenced. I can't seem to figure out how to do this.
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    OOoForum.org Forum Index -> OpenOffice.org Writer All times are GMT - 8 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group