PHP implementation of Baidu Library construction

Source: Internet
Author: User

First step: Install the Jodconverter, after the installation can implement the doc document into PDF.

File is Http://www.artofsolving.com/opensource/jodconverter
After downloading the direct decompression, extracted to the/OPT directory/opt/jodconverter-2.2.2/, the use of the file is installed in the package Lib/jodconverter-cli-2.2.2.jar.
Test whether you can use

  1. java -jar / opt/jodconverter-2.2 2/lib/jodconverter< Span class= "pun" >-cli-2.2. 2.jar /home/php/1.doc /home /php/1.pdf

The Java package is missing and prompts several installation packages. Select I install openjdk-6-jre-headless, the command is as follows:

    1. sudo apt_get openjdk-6-JRE-headless

After installation, the name of the above doc to PDF will be run, prompting the OpenOffice process not to start,

Because the Jodconverter is converted by OpenOffice, it is necessary to install the OpenOffice before use, and to start the OpenOffice service before it can be used. Start command

sudo/usr/bin/soffice-headless-accept= "Socket,host=127.0.0.1,port=8100;urp" –nofirststartwizard

The command to run the above doc to PDF has been successful.

If the system does not follow OpenOffice or has been installed Liboffice

Refer to the steps below

If the system has LibreOffice installed

Refer to the steps below

If LibreOffice is installed, execute sudo apt-get purge libreoffice*

One, download the "OpenOffice.org" of the Deb installation package
Download the Deb installer package on the Chinese official website: Http://download.openoffice.org/other.html#en-US, now (June 1, 2011) The latest version is 3.3.0, the file I downloaded is "ooo_3.3.0_ Linux_x86_install-deb_zh-cn.tar.gz ". and copy the downloaded file to the home directory (that is, the current logged in user's home directory, so that the folder name without the Chinese characters, can prevent accidents).
Second, uninstall "LibreOffice"
Uninstall "LibreOffice" with "New Get" or "Software Center". With the new Rieter Uninstall, in the new state search "LibreOffice", the results of "LibreOffice" installed files are uninstalled.
Third, install "OpenOffice.org":
1. Unzip the file
Open terminal, enter command:
sudo tar-zxvf ooo_3.3.0_linux_x86_install-deb_zh-cn.tar.gz, get the folder "ooo330_m20_native_packed-1_zh-cn.9567".

2. Enter the "Debs" folder in the extracted folder
Command: CD./ooo330_m20_native_packed-1_zh-cn.9567/debs.
3. Install the main file
Command: sudo dpkg-i *.deb installs all the ". Deb" Files in the "Debs" package. After all the files in this package have been installed, you cannot find the "OpenOffice.org" shortcut under the "Office" menu of the system menu and continue with the installation.
4. Go to "desktop-integration" folder in "Debs" package
Command: CD desktop-integration.
5. Install "OpenOffice.org" shortcut
To install the ". Deb" file in the "desktop-integration" folder, command:
sudo dpkg-i *.deb, after this command finishes, if there are no error prompts, OK. You can then find the "OpenOffice.org" shortcut in the "Office" menu in the System menu.

Second step: Install Swftools, after installation can realize PDF file to SwF

    1. wget http://www.swftools.org/swftools-0.9.1.tar.gz
    2. Tar xzf swftools-0.9. 1.tar. GZ
    3. CD Swftools-0.9. 1
    4. ./Configure
    5. Make
    6. Make install

Test whether you can use

pdf2swf -o /home/php/1.swf -z -t -F / Home/php/1.pdf -s flashversion=9

The third step: using Flexpaper to achieve online preview, there is a detailed demo.

Fourth step: Use the PHP test document Conversion command:
Document to PDF

  1. <? PHP
  2. $doc = './docs/test.txt ';
  3. $formatName = './pdf/test.pdf ';
  4. $command = ' Java-jar/opt/jodconverter-2.2.2/lib/jodconverter-cli-2.2.2.jar '. $doc.' '. $formatName;
  5. EXEC($command);
  6. echo ' OK ';

PDF to SWF

  1. <? PHP
  2. $pdf = './pdf/test.pdf ';
  3. $swf = './swf/test.swf ';
  4. $command = '/usr/local/wenku/swftools-0.9.1/src/pdf2swf-o '. $swf.'-t-z-t-f '. $pdf.'-S flashversion=9 ';
  5. EXEC($command);
  6. echo ' OK ';

PHP script to run the above command may have permissions problem cannot be executed
One of the PHP scripts I used to test called pdf2swf to convert the file, not generated. This allows you to configure Apache user rights to ensure that the configured user has permission to run the pdf2swf command
The default installation of the PHP environment under Ubuntu Config file is/etc/apache2/apache2.conf modify these two lines,
User ${apache_run_user}
Group ${apache_run_user}

After the configuration is complete, restart Apache.
/etc/init.d/apache2 restart

The installation configuration under this Linux is over.

Window under test

Download the pdf2swf tool and Flexpaper, which are used under window, and manually turn the PDF file into SWF for online viewing.

The steps are organized as follows:

1. After installing the PDF2SWF tool, proceed to convert the PDF to SWF. CMD command line:
Pdf2swf.exe-t D:\wamp5.3\www\test\pdf\c.pdf-s Flashversion=9-o D:\wamp5.3\www\test\swf\c.swf
-T: Source file path, which is the path of the PDF file to be converted.
-S: Set the parameters, here we set to flashversion=9, that can be converted to 9 version.
-O: The path to the output file, where I output to D: Disk

Results of the operation:

2. Use the Flexpaper plugin to display the browse SWF file. The version used here is 1.5.8 Flash version (Release Notes). In the package there is already an HTML version of the demo, slightly change the next sentence can be achieved.

The code is as follows:

  1. <script src= "js/flexpaper_flash.js" type= "text/javascript" ></SCRIPT>
  2. <a id="Viewerplaceholder" style="width:680px; Height:480px; Display:block;" /></a>
  3. <script Type="Text/javascript">
  4. var fp = new flexpaperviewer(
  5. ' Flexpaperviewer ',
  6. ' Viewerplaceholder ', { config : {
  7. swffile : escape(' c.swf '),
  8. scale : 0.1,
  9. zoomtransition : ' EaseOut ',
  10. zoomtime : 0.5,
  11. zoominterval : 0.2,
  12. fitpageonload : true,
  13. fitwidthonload : false,
  14. Fullscreenasmaxwindow : false,
  15. progressiveloading : false,
  16. minzoomsize : 0.2,
  17. maxzoomsize : 5,
  18. searchmatchall : false,
  19. initviewmode : ' Portrait ',
  20. printpaperasbitmap : false,
  21. viewmodetoolsvisible : true,
  22. zoomtoolsvisible : true,
  23. navtoolsvisible : true,
  24. cursortoolsvisible : true,
  25. searchtoolsvisible : true,
  26. Localechain: ' en_US '
  27. }})
  28. </script>

This is the end, to see the effect achieved:

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.