OpenOffice + swftools + flexpaper file conversion failure Solution

Source: Internet
Author: User

I. First, the OpenOffice process is closed for many reasons, most of which are file conversion failures, resulting in service crash.

For example, the file is too large and the character set is not recognized. Two Batch files are used to monitor the soffice.exe process. If no, restart the process,

OpenOffice. bat always starts and monitors the process. If not, run. bat @ echo off: looptasklist | find/I "soffice.exe" If % errorlevel % = 1 (call "run. bat ") Ping-N 6 127.0.0.1> nulgoto looprun. bat starts the OpenOffice service @ echo offc: cd c: \ Program Files (x86) \ OpenOffice 4 \ programsoffice-Headless-accept = "socket, host = 127.0.0.1, Port = 8100; URP; "-nofirststartwizardp:



2. There is no return value for the office PDF conversion method. If the conversion fails in some cases, you cannot determine whether the conversion is successful,


DocumentConverter converter = new OpenOfficeDocumentConverter(  connection);  converter.convert(inputFile, outputFile); 
// This method does not return a value. If the conversion fails, the function becomes stuck. For example, the OpenOffice service fails or is disabled. Other reasons are unknown.

In the above case, the conversion time must be specified and must be returned within the specified time. If no return is returned, the conversion fails.


// Futruetask is required for execution at the specified time
Executorservice executor = executors. newsinglethreadexecutor (); futuretask <string> future = new futuretask <string> (New callable <string> () {// use the callable interface as the construction parameter Public String call () {Boolean c = covertopdf (doccover. tfilename); // The encapsulated conversion method, which can be considered as converter. convert (inputfile, outputfile); If (C = true) {return "1" ;}else {return "0" ;}// call method requires a return string }}); executor.exe cute (future); try {string result = Future. get (15000, timeunit. milliseconds); // sets the timeout execution time to 15 seconds. If (result. equals ("1") {// indicates that the execution is successful. Continue with the Code.} catch (interruptedexception e) {break;} catch (executionexception e) {break ;} catch (timeoutexception e) {system. out. println ("time-out"); // kill the process because you do not know why. The process will be automatically restarted because one or more processes are monitored, the next conversion runtime.getruntime(cmd.exe C ("taskkill/f/IM soffice.exe *"); break;} finally {
    executor.shutdown();    }
 




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.