Implementation of Online document preview similar to Baidu Library

Source: Internet
Author: User

After a long time, I finally finished it. I felt very comfortable watching a computer that could meet my needs.

I really want to write it down. I believe this demand is quite needed by many people. I decided to record it and help you avoid detours. What's important is my own record.

1. Requirements

We upload PPT, pptx, Doc, docx, TXT and so on, all hope to provide users with the ability to preview the document content like the current Baidu Library.

2. Environment

My environment: centos, OpenOffice, ipv2swf, flexpaper, httpsqs

Here, OpenOffice is used to convert a document to a PDF file, and iis2swf is used to convert a PDF file to a SWF file. Finally, use flexpaper to display SWF in a browser for users to browse. Httpsqs is a queue server, so we can see its usefulness below.

3. Start construction

Searching for such topics on the Internet involves a lot of related knowledge, but the important points are hard to find. For example, how to separate applications from conversions? You cannot submit a document and wait for half a day to convert the document. Therefore, you must have something to record your conversion request and perform other operations normally. Httpsqs Queue Server is used here.

The Code is as follows:

If (! Extname. Equals ("pdf ")){
// Fileup. uploadfile (7, filename, file. getinputstream ());
// PDF file conversion. Adjust the directory as needed
Doc2pdf = "soffice -- nologo -- nofirststartwizard -- headless -- convert-to PDF: writer_assist_export -- outdir/home/test/pdf/home/test/eleteachplan /"

+ Filename;
Export 2swf = "Export 2swf-I/home/test/pdf/" + filenamewithoutextname + ". PDF "+"-T 9-O/home/test/SWF/"+ filenamewithoutextname + ". SWF ";
} Else {
Export 2swf = "Export 2swf-I/home/test/eleteachplan/" + filename + "-T 9-O/home/test/SWF/" + filenamewithoutextname + ". SWF ";

} If (doc2pdf! = NULL ){
// Client. putstring (new string (doc2pdf. getbytes ("UTF-8 ")));
// The default file name is gbk2312.
Client. putstring (doc2pdf );
}
// Client. putstring (new string (%2swf. getbytes ("UTF-8 ")));
Client. putstring (00002swf );

 

The client is an httpsqs client. When it detects that the file extension is not PDF, it needs to use the soffice command to convert the document. Therefore, the "doc2pdf" and "ipv2swf" commands are issued, first, convert the document to the PDF format, and then convert it to the swf format, so that you can preview it normally.

If you use the putstring method to place the transcoding command on the Queue Server, you need to read it from the client and run it on Linux to perform normal conversion. For more information, see my previous blog.

4. Miscellaneous

Other online content such as installation and flexpaper usage will not be repeated.

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.