Jacob converts word to a PDF file (a plug-in to have Word Save as a PDF file)

Source: Internet
Author: User
The public class Dispatch_msword {static final int wddonotsavechanges = 0;//does not save pending changes. static final int wdformatpdf = 17;//PDF format public void ofseventopdf (String sfilename,string tofilename) {//strin  
	    G filename = "d:\\ Supplemental confidentiality agreement. Doc";  
	    
	    String tofilename = sFileName + ". pdf";  
	    System.out.println ("Start Word ...");  
	    Long start = System.currenttimemillis ();  
	    Activexcomponent app = null;  
	        try {app = new activexcomponent ("Word.Application");  
	  
	        App.setproperty ("Visible", false);  
	        Dispatch docs = app.getproperty ("Documents"). Todispatch ();  
	        SYSTEM.OUT.PRINTLN ("Open Document ..." + sfilename);  
						                 Dispatch doc = Dispatch.call (docs,//"Open",//sfilename,//FileName false,//confirmconversions True//ReadOnly). To  
	  
	        Dispatch ();  
	   SYSTEM.OUT.PRINTLN ("Convert Document to PDF ..." + tofilename);     File ToFile = new file (tofilename);  
	        if (tofile.exists ()) {tofile.delete ();  
		                  } dispatch.call (doc,//"SaveAs",//Tofilename,//FileName  
	  
	        Wdformatpdf);  
	        
	        Dispatch.call (Doc, "Close", false);  
	        Long end = System.currenttimemillis (); SYSTEM.OUT.PRINTLN ("conversion complete.")  
	        
	    Spents: "+ (End-start) +" Ms. ");  
	    catch (Exception e) {System.out.println ("========error: Document conversion failed:" + e.getmessage ());  
	    Finally {if (app!= null) app.invoke ("Quit", wdDoNotSaveChanges); }  
		
	}


To run this code, you need to have a plug-in in Word on the machine that contains the Save as PDF

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.