How to use command-line arguments to print ms office files? - java

We are doing an app to manage and print Word, Excel, PowerPoint, and PDF files...
No application can be shown to the user when printing.
To do that, we find some command-line arguments that work well:
(using openoffice.org)
"C:\Program Files\OpenOffice.org 3\program\soffice.exe" -norestore -nofirsts tartwizard -nologo -headless -pt MicrosoftXPSDocumentWriter doc1.doc
(using ms word)
"C:\Program Files\Microsoft Office\Office\WINWORD.EXE" doc1.doc /q /n /mFilePrintDefault /mFileExit
But we just can't find any option to set the page range to print...
Is this possible? Another option to print those documents without showing anything to the user?
Thanks for reading.
any ideas would be appreciated

I would really rethink doing this app in Java. If the application is to manage word documents, and your interaction with word consists of assumptions that word is installed on the local machine, then java isn't adding anything to the party. .NET is likely the right way to go here (where you could easily interact with the office com objects to get what you need).
That being said, for open office, look at the open office SDK which you would have to make as part of your installer for this app.
For Microsoft Office, I would look at a Java-COM bridge (such as Jacob) to call the COM objects. If that is not an option, you could as part of your install process install a Macro into Word that you could call with the /m parameter and pass in the range values you need - but that would get very ugly very fast.

Related

what files from the JRE7 directory are actually needed to run Lucene?

This is about running Lucene (actually Elasticsearch) in a website which is actually otherwise pure PHP... Clearly I need to have the "JVM" and a handful of Lucene jar files... But what does the "JVM" actually mean? Which of all these 125 MB of files under \jre7, if any, can just not be uploaded?
I presume I need "java.exe", but presumably not "javaw.exe", and "fontmanager.dll" doesn't seem that essential (for example).
I have tried googling about this but come up with nothing.
Supposing you wanted to install some Lucene-search-based app on your Android phone (which could be used offline to search through your stuff...)... how can you find what would actually be essential file-wise?

Create Windows Symbolic Link with Java (equivalent to MKLINK)

Could anyone please tell me how to make a symbolic link (in the same way MKLINK does) and/or remove a symbolic link with Java. I have found solutions that use Java as a wrapper and use a Windows native program to accomplish this, but I really want a pure Java solution. Thank you in advance!
Since Java 7 you can do this easily using the NIO package.
Path target = Paths.get("target");
Path link = Paths.get("link");
Files.createDirectory(target);
Files.createSymbolicLink(link, target);
Do remember that you do need the correct privileges for this. In my unit test I had to run eclipse as an administrator to make it work (same as that I couldn't create a link from a normal cmd.exe)
As far as I know window does not have real symbolic links like Unix-like system do.
However Windows has the following relevant tools:
You can map network drive, i.e. attach drive letter to specified network path. You can definitely do this using WMI. To access WMI from java take a look on tools like JaWin, Jinterop, Jintegra or write WMI script in JScript o VBScript and execute is from Java.
You can use command subst that assigns letter to local file system path. This is the closest approach to Unix soft link.
You can create desktop shortcut. Create one manually and take a look on it. Shortcut is actually regular text file (as far as I remember in INI format). You can easily create one using any language you want including java. This is not soft link but it is clickable.

Searching for a particular string in 5000+ text files.

I solve bugs for a product. The customer has sent a bundle of log files. I am required to search for a particular string in these log files. The number of log files is more than five thousand.
I cannot use grep because I am working on a windows machine.
What are my options here ? I was thinking about writing a program in java where I open every text file in a directory and search for a particular pattern. But I could not find a api where i can open every file one after the other.
Can you please suggest me a solution. I can also code in C++ or C# is somehow a solution can be built there.
I would suggest installing Cygwin and using grep
If you need to do this only manually, then just install any decent editor (my suggestion would be http://notepad-plus-plus.org/), and use its find-in-files function.
How about using findstr command from command prompt.
Perl. It takes about three lines of code to search every file in a directory for a string. You can learn enough Perl to do that in half an hour.
This works in Windows XP. I don't know about the more current versions.
Click on the Windows Start Button
Click on Search
A new window will open. On the bottom left, click on "Click here to use Windows Search Companion"
Another window will open.
In the text box labeled "A word or phrase in the file" type in what you're looking for.
In the combobox labeled "Look in", at the very bottom, select "browse..." and select the folder with all the log files.
Click "Search"
Wait for the results...
Note: there are 2 search programs. The first one only finds things that have been indexed, which is why you should use the second search program instead.
Good luck!
Consider VIM editor which is awesome when working with huge files. You can use it under Cygwin, and you can use on Windows. Use cheat sheets to learn it quickly.

Open With... a java program

I want to know how to make a java program that can be used to open stuff up. Ex: notepad++, win zip.... Do I have convert the jar to .exe first? Also, does the file chosen get passed in to String[] args?
By the way, I know that it works with cmd but thats not what I'm asking.
Depends on the OS. Under windows, you need to attach some details into the registry.
Have a look at the 3rd answer in Utilising a file association in a Java application for an example?
You could also have a look at http://www.rgagnon.com/javadetails/java-0592.html
UPDATE
Also, when the OS executes the program, you should receive the file as a command line parameter through the main method
I don't know if this will work suit your needs or not, but you could also take a look at File association in Mac
There's many choices on how to make a Java program runnable. Like you mention, the simplest choice is to use the command line. If you want to make it work with most OS's GUI interfaces (and the Open With dialog) the easiest choice is to make an executable jar. IDEs can make this very easy for you, in Eclipse just right-click on the project and select Export > Java > Runnable JAR file.
Another excellent option is to turn your application into a Java Web Start application, which lets users easily run Java programs being served up online.
Alternatively, like you mention, you could convert it into an .exe file:
Compiling a java program into an executable
How do I create an .exe for a Java program?
How can I convert my Java program to an .exe file?
Deploy the app. using Java Web Start.
JWS provides many appealing features including, but not limited to, splash screens, desktop integration, file associations, automatic update (including lazy downloads and programmatic control of updates), partitioning of natives & other resource downloads by platform, architecture or Java version, configuration of run-time environment (minimum J2SE version, run-time options, RAM etc.), easy management of common resources using extensions..
Here is a demo. of the file services in which the app. is associated with the file type .zzz.
..does it get passed via the windows file chooser?
No. It gets passed to the main as either -open filename or -print filename. What the app. does with those strings is up to it. The demo. linked above will prompt the user in the sand-boxed version, simply because it is sand-boxed. The other one should work without showing prompt or dialog.

Convert DGN to PDF

How can I convert MicroStation (DGN) files to PDF via command line?
The OpenDesign Alliance has libraries for dgn and dwg with pdf capabilities.
You could could use them to create the command line utility.
Decision Graphics http://www.dgnlink.com/ has a number of products that convert DGN to DWG, all of which can be run from a command line.
Once you have the DWG files, you can use one of the command line DWG to PDF converters (I can't recommend a specific one but a quick Google will find loads), or if you have a copy of AutoCAD or AutoCAD LT, you could write a script for that to convert the DWGs by using the DWG To PDF plotter.
From command line parameters, you can not do it. But you can create a Visual Basic or VB.NET application that will lunch microstation to do it for you.
I have been struggling with this one for a long time. All of the existing tools out there require expensive per-user licenses, which was a no-go for my implementation.
I solved the issue with a combination of three things:
Downloaded Bentley Viewer. This is their 100% free viewing/printing application.
Set up a virtual Windows postscript printer using GhostScript and RedMon. There are various guides online for this, and it can be a bit tricky to track down all of the prerequisites, but it is quite stable once set up correctly. Here is one guide: GhostScript/RedMon Guide
Use a "Key-In" script to pass print commands to Bentley View. This involves simply creating a text file with the required commands (List of Commands) and passing it AND the file you want to convert on the command line as such:
BentleyView.exe -M [Filename.dgn] -S[KeyIn FileName]
Please note that you need a space between the -M and the DGN filename but NOT between the -S and the Key-In script filename.
The script I used to simply print the document and then quit the GUI was:
PRINT PRINTERNAME PDFWriter
PRINT EXECUTE
QUIT
This is not a perfect solution at all, especially since it requires the installation of Bentley View and it also opens a UI when called (although it does close it immediately after printing).

Categories

Resources