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.