| View previous topic :: View next topic |
| Author |
Message |
cameroon Newbie

Joined: 03 Feb 2004 Posts: 1
|
Posted: Tue Feb 03, 2004 5:32 pm Post subject: .doc to .pdf, all command-line? |
|
|
Hey all,
I am looking for a way to create .pdf's from MS Office .doc's, , all through the command line. Doesn't matter which platform I am on-- just looking for a way to make OO a .pdf creator.
Thoughts?
Thanks, /c |
|
| Back to top |
|
 |
Guest
|
Posted: Wed Feb 04, 2004 7:31 pm Post subject: |
|
|
Looking at the command line options in the help index, it doesn't look like you can do much with the command line, except:
If you want to learn the API, you might be able to do what you want. I haven't tried this but the API forum seems busy.
Joel |
|
| Back to top |
|
 |
Guest
|
Posted: Wed Feb 04, 2004 8:39 pm Post subject: Re: .doc to .pdf, all command-line? |
|
|
| cameroon wrote: | Hey all,
I am looking for a way to create .pdf's from MS Office .doc's, , all through the command line. Doesn't matter which platform I am on-- just looking for a way to make OO a .pdf creator.
Thoughts?
Thanks, /c |
Check out www.fineprint.com for their PDF Factory. I use it constantly. Their flagship program "Fineprint" isn't too shabby either.
David. |
|
| Back to top |
|
 |
dungmai General User

Joined: 03 Dec 2003 Posts: 8
|
Posted: Thu Feb 05, 2004 8:59 am Post subject: |
|
|
cameron,
download the openoffice sd. Look into examples--> java-->....
find DocumentConverter.java file
run the documentconverter first to convert all the *.doc -->*.sxw
example (running in DOS prompt)
start openoffice at port 8100
then run the following bat file
replace DocumentSaver with DocumentConverter and the argument is the directory
containing the *.doc. I will recursively go through the directory and convert all
the *.doc to *.sxw. Once it is done, do the run another bat file to convert all the *.sxw
--> pdf
All you have to do is to copy and paste DocumentConverter to PdfConverter and
make some minor changes to the program as described briefly
make sure change extension from .sxw to .pdf
good luck
/PdfCconverter example
| Code: |
static String stringConvertType = "writer_pdf_Export";
static String stringExtension = "pdf";
..............
propertyvalue[ 0 ] = new PropertyValue();
propertyvalue[ 0 ].Name = "FilterName";
propertyvalue[0].Value = "writer_pdf_Export";
//new modification here
propertyvalue[1] = new PropertyValue();
propertyvalue[1].Name = "CompressionMode";
propertyvalue[1].Value = "1";
|
//bat file example
| Code: |
java -classpath .;./bin;"C:/Program Files/OpenOffice.org1.1.0/program/classes/jurt.jar;C:/Program Files/OpenOffice.org1.1.0/program/classes/ridl.jar;C:/Program Files/OpenOffice.org1.1.0/program/classes/sandbox.jar;C:/Program Files/OpenOffice.org1.1.0/program/classes/unoil.jar;C:/Program Files/OpenOffice.org1.1.0/program/classes/juh.jar" DocumentSaver uno:socket,host=localhost,port=8100;urp;StarOffice.ServiceManager file:///C:/java_apps/testopenoffice/test/BPI-1.sxw file:///C:/java_apps/testopenoffice/BPI-1.doc
|
----------
| Code: |
import com.sun.star.bridge.XUnoUrlResolver;
import com.sun.star.lang.XMultiServiceFactory;
import com.sun.star.lang.XComponent;
import com.sun.star.lang.XMultiComponentFactory;
import com.sun.star.uno.XComponentContext;
import com.sun.star.uno.UnoRuntime;
import com.sun.star.frame.XComponentLoader;
import com.sun.star.frame.XStorable;
import com.sun.star.beans.PropertyValue;
import com.sun.star.beans.XPropertySet;
import java.io.File;
import java.io.FileFilter;
import java.io.FilenameFilter;
/** The class <CODE>DocumentConverter</CODE> allows you to convert all documents in
* a given directory and in its subdirectories to a given type. A converted
* document will be created in the same directory as the origin document.
*
*/
public class PDFConverter {
/** Containing the loaded documents
*/
static XComponentLoader xcomponentloader = null;
/** Containing the given type to convert to
*/
// static String stringConvertType = "PDF - Portable Document Format";
static String stringConvertType = "writer_pdf_Export";
/** Containing the given extension
*/
static String stringExtension = "pdf";
/** Containing the current file or directory
*/
static String indent = "";
/** Traversing the given directory recursively and converting their files to the
* favoured type if possible
* @param fileDirectory Containing the directory
*/
static void traverse( File fileDirectory ) {
// Testing, if the file is a directory, and if so, it throws an exception
if ( !fileDirectory.isDirectory() ) {
throw new IllegalArgumentException(
"not a directory: " + fileDirectory.getName()
);
}
System.out.println(indent + "[" + fileDirectory.getName() + "]");
indent += " ";
// Getting all files and directories in the current directory
File[] entries = fileDirectory.listFiles(
new FileFilter() {
public boolean accept( File pathname ) {
return pathname.getName().endsWith("sxw");
}
}
);
// Iterating for each file and directory
for ( int i = 0; i < entries.length; ++i ) {
// Testing, if the entry in the list is a directory
if ( entries[ i ].isDirectory() ) {
// Recursive call for the new directory
traverse( entries[ i ] );
} else {
// Converting the document to the favoured type
try {
// Composing the URL by replacing all backslashs
String stringUrl = "file:///"
+ entries[ i ].getAbsolutePath().replace( '\\', '/' );
System.out.println(entries[i] + ":" + stringUrl);
// Loading the wanted document
Object objectDocumentToStore =
PDFConverter.xcomponentloader.loadComponentFromURL(
stringUrl, "_blank", 0, new PropertyValue[0] );
// Getting an object that will offer a simple way to store a document to a URL.
XStorable xstorable =
( XStorable ) UnoRuntime.queryInterface( XStorable.class,
objectDocumentToStore );
// Preparing properties for converting the document
PropertyValue propertyvalue[] = new PropertyValue[ 2 ];
// Setting the flag for overwriting
propertyvalue[ 0 ] = new PropertyValue();
propertyvalue[ 0 ].Name = "FilterName";
propertyvalue[0].Value = "writer_pdf_Export";
// Setting the filter name
// propertyvalue[ 1 ] = new PropertyValue();
// propertyvalue[ 1 ].Name = "FilterName";
// propertyvalue[ 1 ].Value = PDFConverter.stringConvertType;
//new modification here
propertyvalue[1] = new PropertyValue();
propertyvalue[1].Name = "CompressionMode";
propertyvalue[1].Value = "1";
// Appending the favoured extension to the origin document name
int index = stringUrl.lastIndexOf(".");
stringUrl = stringUrl.substring(0, index + 1) + PDFConverter.stringExtension;
// Storing and converting the document
System.out.println(stringUrl + ":" + propertyvalue);
xstorable.storeToURL( stringUrl, propertyvalue );
// Getting the method dispose() for closing the document
XComponent xcomponent =
( XComponent ) UnoRuntime.queryInterface( XComponent.class,
xstorable );
// Closing the converted document
xcomponent.dispose();
}
catch( Exception exception ) {
exception.printStackTrace();
}
System.out.println(indent + entries[ i ].getName());
}
}
indent = indent.substring(2);
}
/** Connecting to the office with the component UnoUrlResolver and calling the
* static method traverse
* @param args The array of the type String contains the directory, in which all files should be
* converted, the favoured converting type and the wanted extension
*/
public static void main( String args[] ) {
try {
// if ( args.length < 4 ) {
// System.out.println(
// "usage: java -classpath .;<Office path>/program/classes/jurt.jar;" +
// "<Office path>/program/classes/ridl.jar;" +
// "<Office path>/program/classes/sandbox.jar;" +
// "<Office path>/program/classes/unoil.jar;" +
// "<Office path>/program/classes/juh.jar " +
// "DocumentConverter \"<connection>\" \"<directory to convert>\"" +
// " \"<type to convert to>\" \"<extension>\"" );
// System.out.println( "\ne.g.:" );
// System.out.println(
// "java -classpath .;d:/office60/program/classes/jurt.jar;" +
// "d:/office60/program/classes/ridl.jar;" +
// "d:/office60/program/classes/sandbox.jar;" +
// "d:/office60/program/classes/unoil.jar; " +
// "d:/office60/program/classes/juh.jar " +
// "DocumentConverter \"uno:socket,host=localhost,port=8100;urp;" +
// "StarOffice.ServiceManager\"" +
// " \"c:/myoffice\" \"swriter: MS Word 97\" \"doc\"" );
// System.exit(1);
// }
/* Bootstraps a component context with the jurt base components
registered. Component context to be granted to a component for running.
Arbitrary values can be retrieved from the context. */
XComponentContext xComponentContext =
com.sun.star.comp.helper.Bootstrap.createInitialComponentContext( null );
/* Gets the service manager instance to be used (or null). This method has
been added for convenience, because the service manager is a often used
object. */
XMultiComponentFactory xMultiComponentFactory =
xComponentContext.getServiceManager();
/* Creates an instance of the component UnoUrlResolver which
supports the services specified by the factory. */
Object objectUrlResolver = xMultiComponentFactory.createInstanceWithContext(
"com.sun.star.bridge.UnoUrlResolver", xComponentContext );
// Create a new url resolver
XUnoUrlResolver xurlresolver = ( XUnoUrlResolver )
UnoRuntime.queryInterface( XUnoUrlResolver.class,
objectUrlResolver );
// Resolves an object that is specified as follow:
// uno:<connection description>;<protocol description>;<initial object name>
Object objectInitial = xurlresolver.resolve( "uno:socket,host=localhost,port=8100;urp;StarOffice.ServiceManager" );
// Create a service manager from the initial object
xMultiComponentFactory = ( XMultiComponentFactory )
UnoRuntime.queryInterface( XMultiComponentFactory.class, objectInitial );
// Query for the XPropertySet interface.
XPropertySet xpropertysetMultiComponentFactory = ( XPropertySet )
UnoRuntime.queryInterface( XPropertySet.class, xMultiComponentFactory );
// Get the default context from the office server.
Object objectDefaultContext =
xpropertysetMultiComponentFactory.getPropertyValue( "DefaultContext" );
// Query for the interface XComponentContext.
xComponentContext = ( XComponentContext ) UnoRuntime.queryInterface(
XComponentContext.class, objectDefaultContext );
/* A desktop environment contains tasks with one or more
frames in which components can be loaded. Desktop is the
environment for components which can instanciate within
frames. */
xcomponentloader = ( XComponentLoader )
UnoRuntime.queryInterface( XComponentLoader.class,
xMultiComponentFactory.createInstanceWithContext(
"com.sun.star.frame.Desktop", xComponentContext ) );
// Getting the given starting directory
File file = new File("C:\\java_apps\\testopenoffice\\test");
// Getting the given type to convert to
// stringConvertType = "MS Word 97";
stringConvertType = "writer_pdf_Export";
// Getting the given extension that should be appended to the origin document
// stringExtension = "doc";
stringExtension = "pdf";
// Starting the conversion of documents in the given directory and subdirectories
traverse( file );
System.exit(0);
}
catch( Exception e ) {
e.printStackTrace();
}
}
}
|
|
|
| Back to top |
|
 |
DannyB Moderator


Joined: 02 Apr 2003 Posts: 3991 Location: Lawrence, Kansas, USA
|
Posted: Thu Feb 05, 2004 9:28 am Post subject: Re: .doc to .pdf, all command-line? |
|
|
| cameroon wrote: | I am looking for a way to create .pdf's from MS Office .doc's, , all through the command line. Doesn't matter which platform I am on-- just looking for a way to make OO a .pdf creator.
|
This question has been answered....
http://www.oooforum.org/forum/viewtopic.php?t=3772
Solution in a nutshell...
Put a small macro into the soffice.
Call soffice.exe from command line, passing a specially formed URL that activates the macro.
The URL contains a parameter, which is the name of the document to convert.
The macro gets the parameter, opens it, saves it in the new format. _________________ Want to make OOo Drawings like the colored flower design to the left? |
|
| Back to top |
|
 |
guestaa Guest
|
Posted: Sun Apr 11, 2004 9:11 pm Post subject: how to use -accept |
|
|
| how to use -accept parameter to start openoffice in win2k for listening in special port? |
|
| Back to top |
|
 |
ehegagoka Newbie

Joined: 15 Jan 2006 Posts: 1 Location: Makati
|
Posted: Sun Jan 15, 2006 5:20 pm Post subject: |
|
|
hi!
thanks a lot for ur post, it runs fine on me, but is there other way of running the class with just the jar files included? i mean without running openoffice? doesn't the code runs using those library jar files? Im just thinking if I could load the jar files on our dtabase, thank you so much!
Ryan |
|
| Back to top |
|
 |
anytopdf Newbie

Joined: 16 Apr 2009 Posts: 1
|
Posted: Thu Apr 16, 2009 7:47 pm Post subject: anytopdf |
|
|
I packaged a working set of macros, install routines, and a command line frontend for anything to PDF in to anytopdf.
Hopefully this will make things easier
It uses macros instead of the '-p' print option and a PDF printer, since I was unable to get the latter to work with calc (needed for excel files). |
|
| Back to top |
|
 |
williamkenworthy Newbie

Joined: 06 Sep 2010 Posts: 1
|
Posted: Tue Sep 07, 2010 5:32 am Post subject: |
|
|
ive also used this free online ocr converter and found it very useful so ill recommend it.
Last edited by williamkenworthy on Thu Sep 09, 2010 9:04 am; edited 1 time in total |
|
| Back to top |
|
 |
shades49 General User

Joined: 24 Nov 2008 Posts: 29
|
Posted: Wed Sep 08, 2010 9:01 am Post subject: |
|
|
If you also meant, "any platform" then on Mac OS X, you can make PDFs within any application, without any other software or macros. _________________ OO.org 3.3/Symphony 3/NeoOffice 3.1.2
Mac OS X 10.6.5 |
|
| Back to top |
|
 |
|
|
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
|