Convert word to swf and read implementation ideas and code like Baidu Library

Source: Internet
Author: User
The general process is to convert word to pdf format, and then convert pdf to swf format. The content displayed on the webpage is actually in the swf format. the specific implementation is as follows. if you need this content, please refer to it and hope to help you. The code is as follows:
Similar functions like Baidu Library require a series of conversions. the general process is to convert word to pdf format, and then convert pdf to swf format. The content displayed on the webpage is actually in swf format.

First, convert word to swf. you need to call the com component to convert it through office or wps. However, I have not tried it successfully. Finally, the conversion is successful through OpenOffice 4.0.0, openOffice 4.0.0 supports windows and linux operating systems, so you need to download openOffice first, which should be available on the official website. Converting word to pdf is just a document that supports English titles. if you do not support Chinese document names, you can rename the document to English and convert it to Chinese, you may need to start the openoffice service,

Verify whether the service is enabled,

The code is as follows:
The code is as follows:
 Class RunTime // page execution time class
{
Private $ starttime; // execution time of the page
Private $ stoptime; // page end execution time
Private $ spendtime; // time taken for page execution
Function getmicrotime () // gets the floating point number of the current microsecond.
{
List ($ usec, $ sec) = explode ("", microtime ());
Return (float) $ usec + (float) $ sec );
}
Function start () // start the execution of the function on the page, and return the execution time of the start page.
{
$ This-> starttime = $ this-> getmicrotime ();
}
Function end () // display the page execution time
{
$ This-> stoptime = $ this-> getmicrotime ();
$ This-> spendtime = $ this-> stoptime-$ this-> starttime;
// Return round ($ this-> spendtime, 10 );
}
Function display ()
{
// $ This-> end ();
Echo"

Run time: ". round ($ this-> spendtime, 10)." seconds

";
}
}
/* Call method */
$ Timer = new Runtime ();
$ Timer-> start ();


Function MakePropertyValue ($ name, $ value, $ osm ){
$ OStruct = $ osm-> Bridge_GetStruct
("Com. sun. star. beans. PropertyValue ");
$ OStruct-> Name = $ name;
$ OStruct-> Value = $ value;
Return $ oStruct;
}
Function word2pdf ($ doc_url, $ output_url ){
$ Osm = new COM ("com. sun. star. ServiceManager") or die ("Please be sure that OpenOffice.org is installed. \ n ");
$ Args = array (MakePropertyValue ("Hidden", true, $ osm ));
$ ODesktop = $ osm-> createInstance ("com. sun. star. frame. Desktop ");
$ OWriterDoc = $ oDesktop-> loadComponentFromURL
($ Doc_url, "_ blank", 0, $ args );
$ Export_args = array (MakePropertyValue
("FilterName", "writer_assist_export", $ osm ));
$ OWriterDoc-> storeToURL ($ output_url, $ export_args );
$ OWriterDoc-> close (true );
}
$ Output_dir = "C :/";
$ Doc_file = "C:/t.doc ";
$ Pai_file = "9.20 ";
$ Output_file = $ output_dir. $ pai_file;
$ Doc_file = "file: //". $ doc_file;
$ Output_file = "file: //". $ output_file;
Word2pdf ($ doc_file, $ output_file );


$ Timer-> end ();
$ Timer-> display ();

?>



 





Analyze the time:

To convert a M Word document to a pdf fileRunning time: 1.3652579784 secondsThis is the time on your computer. test it on your own.





Second, to convert a pdf file to swf, you need to use another software. swftools calls the cmd command through code and directly uploads the code


 Class RunTime // page execution time class
{
Private $ starttime; // execution time of the page
Private $ stoptime; // page end execution time
Private $ spendtime; // time taken for page execution
Function getmicrotime () // gets the floating point number of the current microsecond.
{
List ($ usec, $ sec) = explode ("", microtime ());
Return (float) $ usec + (float) $ sec );
}
Function start () // start the execution of the function on the page, and return the execution time of the start page.
{
$ This-> starttime = $ this-> getmicrotime ();
}
Function end () // display the page execution time
{
$ This-> stoptime = $ this-> getmicrotime ();
$ This-> spendtime = $ this-> stoptime-$ this-> starttime;
// Return round ($ this-> spendtime, 10 );
}
Function display ()
{
// $ This-> end ();
Echo"

Run time: ". round ($ this-> spendtime, 10)." seconds

";
}
}
/* Call method */
$ Timer = new Runtime ();
$ Timer-> start ();


// Call system software
$ Command = "\" C: \ Program Files \ SWFTools \ 20.2swf.exe \ "-t C: \ 8.pdf-s flashversion = 9-o C: \ m.swf ";
Echo $ command;
Exec ($ command );
Echo 'OK ';


$ Timer-> end ();
$ Timer-> display ();

?>


To convert a pdf file to a swf file, use Running time: 1.3119211197 seconds


Finally, the swf file is displayed on the webpage. This step requires multiple js files and other files to be introduced, and the code will not be written. download them directly. in my uploaded documents












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.