44300

How to get print out of a ms word file from java application [closed]

Question:

Print ms word file (myfile.doc) to get printed from java application....

Answer1:

<a href="http://wiki.services.openoffice.org/wiki/API/Samples/Java/Office/DocumentHandling#DocumentPrinter" rel="nofollow">This example</a> from the <a href="http://api.openoffice.org/" rel="nofollow">OpenOffice API</a> might be useful.

Answer2:

The Apache POI system ( <a href="http://poi.apache.org/" rel="nofollow">http://poi.apache.org/</a> ) is explicitly designed to interface with MS documents.

Answer3:

The <a href="http://sourceforge.net/projects/jacob-project/" rel="nofollow">Jacob</a> library can be used to obtain a COM interface to a Word automation container, and you can print from there (we do this quite a bit in one of our apps). But you have to have Word installed on the machine for this to work - if you are looking for something that can work without having Word installed, you'll have to look elsewhere.

Answer4:

This is probably not the most efficient method, but it works if you have MS Word. You can use this command to get Word print the file:

start /min winword <filename> /q /n /f /mFilePrint /mFileExit

Replace <filename> with the filename. It must be enclosed in double-quotation marks if it contains spaces. (e.g. file.rtf, "A File.docx")

Here is a Java method and C++ function that takes the filename as an argument and prints the file:

Java

public void printWordFile(String filename){ System.getRuntime().exec("start /min winword \"" + filename + "\" /q /n /f /mFilePrint /mFileExit"); }

C++

//Be sure to #include <string.h> void wordprint(char* filename){ char* command = new char[64 + strlen(filename)]; strcpy(command, "start /min winword \""); strcat(command, filename); strcat(command, "\" /q /n /f /mFilePrint /mFileExit"); system(command); delete command; }

Explanation of switches used

start /min says to run the program that follows minimized. You must do this or Word will stay open after the file is opened.

winword tells the start program to run Microsoft Word.

/q tells Word not to display the splash screen.

/n says to open a new instance of Word so we don't interfere with other files the user has open.

/f says to open a copy of the file to prevent modification.

/mFilePrint tells Word to diplay its print dialog so the user can choose which printer they want to use and how many copies, etc.

/mFileExit says to close as soon as everything else is done. This will not work unless Word is minimized.

Recommend

  • Unable to start Selenium Safari WebDriver via python3
  • Is it possible to set breakpoints automatically (e.g. by regular expression) in VS2008?
  • Is there an advantage in using SOAP UI over REST-assured to automate REST Services for CI
  • GRPC and types import error in App Engine Datastore
  • How to use SBT with multiple sub project web applications?
  • Autohotkey script running program with command line arguments
  • MySQL: Difference between `… ADD INDEX(a); … ADD INDEX(b);` and `… ADD INDEX(a,b);`?
  • Is there a way to call library thread-local init/cleanup on thread creation/destruction?
  • Zend Framework bassed projects
  • Accessing Rows In A LINQ Result Without A Foreach Loop?
  • C#: Import/Export Settings into/from a File
  • Syntax error on tokens, AnnotationName expected instead - error on query
  • JSR-330 support in Picocontainer : @Inject … @Named(\"xxx)
  • jQuery: How to AJAXify WordPress Search?
  • How can I display the parent menu item's description using Wordpress walkers?
  • Graphics.CopyFromScreen [Web application] + The handle is invalid
  • How do I configure context broker accept post requests from my remote sensor?
  • Mysql - How to search for 26 records that each begins with the letter of the alphabet?
  • ADO and msqli connections very slow
  • Declaring variable dynamically in VB.net
  • The plugin 'org.apache.maven.plugins:maven-jboss-as-plugin' does not exist or no valid ver
  • javaw.exe and eclipse startup problems
  • How to recover from a Spring Social ExpiredAuthorizationException
  • ILMerge & Keep Assembly Name
  • Join two tables and save into third-sql
  • Can I make an Android app that runs a web view in Chrome 39?
  • Javascript convert timezone issue
  • Trying to switch camera back to front but getting exception
  • Updated Ionic CLI but shows previous version (Windows)
  • Large data - storage and query
  • Function pointer “assignment from incompatible pointer type” only when using vararg ellipsis
  • WOWZA + RTMP + HTML5 Playback?
  • R: gsub and capture
  • jqPlot EnhancedLegendRenderer plugin does not toggle series for Pie charts
  • Comma separated Values
  • Free memory of cv::Mat loaded using FileStorage API
  • Angular 2 constructor injection vs direct access
  • How can I remove ASP.NET Designer.cs files?
  • Programmatically clearing map cache
  • How to load view controller without button in storyboard?