Convert Word to SWF like Baidu Library reading implementation ideas and code _php skills

Source: Internet
Author: User
Tags explode
Copy Code code as follows:

<span style= "font-family:arial, Helvetica, Sans-serif" > implementation like Baidu Library similar functions require a series of transformations, the general process to convert Word to PDF format, Then convert the PDF format to SWF format. displayed on the Web page is actually the SWF format content. </SPAN>

First convert Word to SWF, you need to invoke COM components, can be converted through office or WPS, but I tried unsuccessfully, finally through the OpenOffice 4.0.0 conversion to succeed, OpenOffice 4.0.0 support windows and Linux operating system, it is necessary to download OpenOffice, the official network should have. Convert Word to PDF, as if only supporting the English title of the document, do not support the Chinese name document, you can first rename the file to English, convert the file into Chinese can be, may also need to start OpenOffice services, above

Verify that the service is open, above

The code is as follows:
Copy Code code as follows:

<pre class=php name= "code" ><?php
Class runtime//page Execution time classes
{
private $starttime;//page Start execution time
private $stoptime;//page End Execution time
Private $spendtime//page execution takes time
function Getmicrotime ()//Gets the floating-point number that returns the current microsecond
{
List ($usec, $sec) =explode ("", Microtime ());
Return ((float) $usec + (float) $sec);
}
The function start ()//page begins execution functions, returning the start Page execution time
{
$this->starttime= $this->getmicrotime ();
}
function end ()//Display time of page execution
{
$this->stoptime= $this->getmicrotime ();
$this->spendtime= $this->stoptime-$this->starttime;
Return round ($this->spendtime,10);
}
function display ()
{
$this->end ();
echo "<p> Run Time:". Round ($this->spendtime,10). " SEC </p> ";
}
}
/* 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 this 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_pdf_export", $OSM));
$oWriterDoc->storetourl ($output _url, $export _args);
$oWriterDoc->close (TRUE);
}
$output _dir = "c:/";
$doc _file = "C:/t.doc";
$pdf _file = "9.pdf";
$output _file = $output _dir. $pdf _file;
$doc _file = "file:///". $doc _file;
$output _file = "file:///". $output _file;
Word2pdf ($doc _file, $output _file);


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

?></pre><br>
<P></P>
<PRE></PRE>
<P></P>
<P><BR>
</P>
Take time to analyze:
<P> Converting a Word document of 1.48M size to PDF requires <span style= "Font-family:simsun; Font-size:14px "> Running time: 1.3652579784 sec </SPAN> own computer is this time, own test </P>
<P><BR>
</P>
<P> Second, the PDF into SWF, need to use another software, swftools through the code call CMD command, directly on the code </P>
<p><pre class=php name= "code" ><?php
Class runtime//page Execution time classes
{
private $starttime;//page Start execution time
private $stoptime;//page End Execution time
Private $spendtime//page execution takes time
function Getmicrotime ()//Gets the floating-point number that returns the current microsecond
{
List ($usec, $sec) =explode ("", Microtime ());
Return ((float) $usec + (float) $sec);
}
The function start ()//page begins execution functions, returning the start Page execution time
{
$this->starttime= $this->getmicrotime ();
}
function end ()//Display time of page execution
{
$this->stoptime= $this->getmicrotime ();
$this->spendtime= $this->stoptime-$this->starttime;
Return round ($this->spendtime,10);
}
function display ()
{
$this->end ();
echo "<p> Run Time:". Round ($this->spendtime,10). " SEC </p> ";
}
}
/* Call Method * *
$timer =new Runtime ();
$timer->start ();


Calling system software
$command = "\" C:\Program files\swftools\pdf2swf.exe\ "-t C:\8.pdf-s flashversion=9-o C:\m.swf";
Echo $command;
EXEC ($command);
echo ' OK ';


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

?></pre><br>
Converting the PDF that you just converted into a SWF file requires <span style= "Font-family:simsun; Font-size:14px "> Run Time: 1.3119211197 sec time </SPAN><P></P>
<p><span style= "Font-family:simsun; Font-size:14px "> The last is to display the SWF file in the Web page, this step needs to introduce a number of JS files and other files, the code does not write, direct download, in my upload information </SPAN></P>
<P><BR>
</P>
<P><BR>
<BR>
</P>
<P><BR>
</P>

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.