Enable Word online preview and print with Flexpaper

Source: Internet
Author: User
Tags maven central

In order for Word to appear on the web as much as possible in the original layout style, choosing an ActiveX-based control is too dependent on a browser, and there may be a need to spend money to purchase the appropriate control product , so the flash presentation method with Flexpaper became the preferred solution. The implementation of this scheme is primarily to convert Word documents into PDF documents, then convert PDF documents into SWF files using the Swftools tool, and then flexpaper load the SWF files for presentation.

Visit Flexpaper's website address: http://flexpaper.devaldi.com/download/Download the web version of the Flexpaper, while the need to use the 3 software also downloaded. The latest version I currently download is version flexpaper_2.3.6.

Install the downloaded 3 packages first:

Then unzip the flexpaper_2.3.6.

You can see the extracted files directory is available in the ASP. NET version, Java version and PHP version, where I choose to deploy a Java version, open the Java directory, you can see a war package, deploy it into Tomcat, Then start tomcat access to the root path of the deployed Flexpaper. The initial visit will jump to a configured page to set the Administrator account password, configure the installation path of the 3 software mentioned above, and then the directory where the PDF is to be converted and the directory where the converted SWF file will be stored, both of which need to be created beforehand. There is another important configuration is the SWF generation mode, Flexpaper provides a single file mode and multi-file mode, if you choose Single file mode, then a PDF document converted to SWF, only one SWF file, if you choose Multi-file mode, If there are several pages of content in a PDF document, then multiple SWF files will be generated.

The corresponding URL of the newly deployed Flexpaper is accessed based on the file mode you have configured, and the PDF file name in the PDF directory that you configured is passed in the doc parameter on the URL for direct online preview to PDF files.

Single-file mode when accessing Url:http://127.0.0.1:8080/flexpaper/common/simple_document.jsp?doc=660521783206862.pdf

Url:http://127.0.0.1:8080/flexpaper/common/split_document.jsp?doc=660521783206862.pdf when multi-file mode is accessed

The next step is to convert the Word document into a PDF document in the program and save it in the PDF directory mentioned above in order to enable the online browsing of Word documents.

Here I use the Java language, using the artofsolving Jodconverter package for the doc-to-pdf conversion, the conversion requires OpenOffice, so you also need to download the installation OpenOffice.

The OpenOffice version of my current download installation is 4.1.2 version.

Jodconverter used a lot of the main two versions, one is the 2.2.1 version, the other is the 3.0-BETA4 version.

Version 2.2.1

2.2.1 does not support docx format and requires the OpenOffice service to be opened in advance via the command line.

The command line code to open the OpenOffice service is as follows:

CD Files (x86) \openoffice 4\programsoffice-headless-accept= "SOCKET,HOST=127.0.0.1,PORT=8100;URP;"- Nofirststartwizard

Java Key Code:

// Connect to a OpenOffice.org instance running on port 8100              New socketopenofficeconnection (                      "127.0.0.1", 8100);              Connection.connect ();                 // Convert              New Openofficedocumentconverter (                      connection);              Converter.convert (Inputfile, outputFile);                 // Close the connection              Connection.disconnect ();  

If you are using MAVEN for management, then the 2.2.1 version of the dependency configuration is as follows:

<Dependency>    <groupId>Com.artofsolving</groupId>    <Artifactid>Jodconverter</Artifactid>    <version>2.2.1</version></Dependency>

Version 3.0-beta4

3.0-BETA4 supports the docx version and does not require the OpenOffice service to be opened in advance via the command line, but can be turned on and off via Java code.

Java Key Code:

Private  StaticOfficemanager Officemanager; Public Static voidconvert (File originfile,file destfile) {LongStartTime =System.currenttimemillis ();                 StartService (); Officedocumentconverter Converter=NewOfficedocumentconverter (Officemanager);         Converter.convert (Originfile,destfile); Log.info ("Conversion complete. Time Consuming" + ((System.currenttimemillis ()-StartTime)/1000) + "seconds");    StopService (); }    Private Static voidStartService () {defaultofficemanagerconfiguration configuration=Newdefaultofficemanagerconfiguration (); Log.info ("Ready to start Office Transformation Services ..."); Configuration.setofficehome ("D:/program Files (x86)/openoffice 4"); Configuration.setportnumber (8100); Configuration.settaskexecutiontimeout (1000*60);//Task timeout time 1 minutes        Try{Officemanager=Configuration.buildofficemanager (); Officemanager.start ();//Start the serviceLog.info ("Office conversion service started successfully!")); } Catch(officeexception e) {log.error ("Office conversion service failed to start!"); } Catch(IllegalStateException e) {log.error ("Office conversion service failed to start!"); }    }        Private Static voidStopService () {if(officemanager!=NULL) {officemanager.stop (); Log.info ("Office conversion service turned off successfully!"); }Else{log.info ("The Office conversion service is not started!"); }    }

If you use MAVEN for management, the 3.0-BETA4 version is not available through the MAVEN Central Library, and you need to download the jar from your artofsolving website and register it with your local maven repository.

Jodconverter-core-3.0-beta-4.bat:

Install:install-file -dgroupid=com.artofsolving-dartifactid=jodconverter-dversion= 3.0-beta-4 -dpackaging=jar-dfile=%cd%\jodconverter-core-3.0-beta-4. jar

POM Configuration:

<Dependency>            <groupId>Com.artofsolving</groupId>            <Artifactid>Jodconverter</Artifactid>            <version>3.0-beta-4</version>        </Dependency>        <Dependency>            <groupId>Org.openoffice</groupId>            <Artifactid>Juh</Artifactid>            <version>3.2.1</version>        </Dependency>        <Dependency>            <groupId>Org.openoffice</groupId>            <Artifactid>Unoil</Artifactid>            <version>3.2.1</version>        </Dependency>        <Dependency>            <groupId>Commons-cli</groupId>            <Artifactid>Commons-cli</Artifactid>            <version>1.1</version>        </Dependency>        <Dependency>            <groupId>Org.json</groupId>            <Artifactid>Json</Artifactid>            <version>20090211</version>        </Dependency>

Since the 3.0-BETA4 jar package is registered to the local MAVEN repository by its own command line, it does not have a dependency on the package, so it is necessary to manually configure the other jar packages it relies on to the pom file.

Enable Word online preview and print with Flexpaper

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.