Home > Back-end >  In Java using Jacob will docx convert PDF error Invoke of: SaveAs, office version for 20077
In Java using Jacob will docx convert PDF error Invoke of: SaveAs, office version for 20077

Time:10-06

//install docx documents into PDF 
Public void wordToPdf (String sfileName, String toFileName) {
//final int wdFormatPDF=17;//PDF format
System. Out.println (" to start the Word... ");
Long start=System. CurrentTimeMillis ();
ActiveXComponent app=null;//word to run the program object
Dispatch doc=null;//all word document collection
Try {
App=new ActiveXComponent (" Word. Application ");
App. SetProperty (" Visible ", new Variant (false));
Dispatch docs=app. GetProperty (" Documents "). ToDispatch ();
Doc=Dispatch. Call (docs, "Open", sfileName). ToDispatch ();
System. Out.println (" open the document... "+ sfileName);
System. Out.println (" convert to PDF document... "+ toFileName);
The File tofile=new File (toFileName);
{if (tofile. The exists ())
Tofile. Delete ();
}
Dispatch. Call (doc, "SaveAs", toFileName,//FileName
17);

//Dispatch. Invoke (doc,
//"SaveAs",
//Dispatch Method,
//the new Object [] {toFileName, new Variant (17)},
//new int [1]);

//Dispatch. Call (doc, "SaveAs", new Variant (toFileName));//save a new document



Long end=System. CurrentTimeMillis ();
System. Out.println (" conversion completed.. Time: "+ (end - start) +" Ms. ");

} the catch (Exception e) {
System. The out. Println ("========Error: document conversion failure: "+ um participant etMessage ());
} the finally {
If (doc!=null) {
Dispatch. Call (doc, "Close", false);
Doc=null;
}
System. The out. Println (" close the document ");
If (app!=null) {
App. Invoke (" Quit ", new Variant [] {});
App=null;
}
//without the words, winword. Exe process will not shut down
ComThread. Release ();
}
}


Error:
Start the Word...
Open the document... F:/images/youlike_upload/a6b56b9eda104ae285bd14dc422de86d docx
Convert documents to PDF... F:/images/youlike_upload a6b56b9eda104ae285bd14dc422de86d. PDF
========Error: document conversion failure: Invoke of: SaveAs
Source: Microsoft Word
Description: command failed

Close the document


//////////////////////////////
Project starts correctly performed only once, after an error, please leaders guidance
  • Related