Linux Online preview PDF file Development ideas

Source: Internet
Author: User

Preparation: Swftools,flexpaper

Basic ideas:

1. Convert pdf file to swf file

2. Preview swf file using Flexpaper

Main code:

1, install Swftools in Linux. Download Swftools installation package, unzip

2,./configure--prefix= Installation path

Make Install

After execution, execute pdf2swf-help if displayed. Indicates successful installation

If the execution pdf2swf-help display Commond not find, you may need to configure Swftools environment variables, specific configuration please Baidu ^_^

3. Call Linux Shell in Java to convert PDF to SWF

String [] cmd={"/bin/sh", "-C", "pdf2swf" + file path/file name to convert. pdf+ "" +  converted file path/= runtime.getruntime (). exec (cmd);  Dealwith (PRO); Pro.waitfor (); // waiting for the end of the child process, the child process is the system called the file transformation of the new process

Dealwith () is a way to print the execution process

    Private voidDealwith (FinalProcess Pro) {            //here's how to handle the blockage.        Try {                NewThread () { Public voidrun () {BufferedReader BR1=NewBufferedReader (NewInputStreamReader (Pro.getinputstream ())); System.out.println ("********************"+BR1);                        String text; Try {                             while(Text = Br1.readline ())! =NULL) {System.out.println ("==================="+text); }                        } Catch(IOException e) {e.printstacktrace ();            }}}.start (); } Catch(Exception e) {e.printstacktrace (); }                        Try {                NewThread () { Public voidrun () {BufferedReader Br2=NewBufferedReader (NewInputStreamReader (Pro.geterrorstream ()));//This must not forget to deal with the information generated when the reason, or it will clog up theSystem.out.println ("#########################" +BR2);                        String text; Try {                             while(Text = Br2.readline ())! =NULL) {System.err.println ("------------------"+text); }                        } Catch(IOException e) {e.printstacktrace ();            }}}.start (); } Catch(Exception e) {e.printstacktrace (); }        } 

In 4.jsp,

Introduction of Flexpaper class and JS

<link rel= "stylesheet" type= "Text/css" href= "${ctx}/pages/flexpaper/css/flexpaper.css"/>

<script src= "${ctx}/pages/flexpaper/js/flexpaper.js" charset= "UTF-8" ></script>
<script src= "${ctx}/pages/flexpaper/js/flexpaper_handlers.js" charset= "UTF-8" ></script>

<div id= "DocumentViewer" class= "Flexpaper_viewer" style= "width:770px;height:500px;" ></div>

$ (' #documentViewer '). Flexpaperviewer ({config: {swffile:fileurl, scale:0.6, Zoomtransition:' EaseOut ', Zoomtime:0.5, Zoominterval:0.2, Fitpageonload:true, Fitwidthonload:false, Fullscreenasmaxwindow:false, progressiveloading:false, Minzoomsize:0.2, Maxzoomsize:5, Searchmatchall:false, Initviewmode:' Portrait ', Renderingorder:' Flash ', Startatpage:‘‘, viewmodetoolsvisible:true, zoomtoolsvisible:true, navtoolsvisible:true, cursortoolsvisible:true, searchtoolsvisible:true, WMode:' Window ', Localechain:' en_US '                }}        );

The above is the main implementation code. The use of Flexpaper can be referred to the official download package, the official download package directly into Tomcat can be run.

--------------------------------------------------------------------------------------------------------------- ----------------------------

First write so much, again thanks to the great community of netizens and it peers, to provide a variety of information to me with the greatest help. Thank you!

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.