In an OA system project, the fax module is developed, and the fax data is sent and received through aofax. Now, you need to display the received tif document to the browser. The best way is to convert the tif document to the pdf format. Step 1: run the following five code sudoaptitudeupdatesudoaptitudeinstallmakephp5-cliphp5-gdphp5-devphp-peargs-commonghosts
In an OA system project, the fax module is developed, and the fax data is sent and received through aofax. Now, you need to display the received tif document to the browser. The best way is to convert the tif document to the pdf format.
The procedure is as follows:
1. Run the following five codes:
Sudo aptitude update
Sudo aptitude install make php5-cli php5-gd php5-dev php-pear gs-common ghostscript
Sudo aptitude remove php5-imagick
Sudo apt-get install libmagick9-dev
Sudo pecl install imagick // If only this is installed, the above four will be installed in case of a problem.
2. Add extension = imagick. so extension to/etc/php5/apache/php. ini.
3. restart apache,/etc/init. d/apache restart.
Test the configuration
Call this function
- Private FunctionTif_to_pdf ($ File_tif,$ File_pdf){
- $ Errors=Array();
- $ Pai_ps2pdf="/Usr/bin/ps2jwwr";
- // $ File_tif = escapeshellarg ($ file_tif); // The escapeshellarg function is used to filter shell parameters.
- // $ File_pdf = escapeshellarg ($ file_pdf );
- If(!File_exists($ File_tif))$ Errors[] ="Original TIFF file :".$ File_tif."Does not exist";
- If(!File_exists($ Pai_ps2pdf))$ Errors[] ="Ghostscript PostScript to PDF converter not found :".$ Pai_ps2pdf;
- If(!Extension_loaded("Imagick"))$ Errors[] ="Imagick extension not installed or not loaded";
- If(!Count($ Errors)){
- // Confirm the basic path of the file
- $ Base=$ File_pdf;
- If(($ Ext=Strrchr($ File_pdf,'.'))! = False)$ Base=Substr($ File_pdf, 0 ,-Strlen($ Ext));
- // Determine the temporary. ps filepath
- $ File_ps=$ Base.". Ps";
- // Open the original. tiff File
- $ Document=NewImagick ($ File_tif);
- // Use Imagick to write multiple pages to 1. ps file
- If(!$ Document-> WriteImages ($ File_ps, True )){
- $ Errors[] ="Unable to use Imagick to write multiple pages to 1. ps file :".$ File_ps;
- }Else{
- $ Document-> Clear ();
- // Use ghostscript to convert. ps->. pdf
- Exec($ Pai_ps2pdf."-SPAPERSIZE = a4".$ File_ps."".$ File_pdf,$ O,$ R);
- If($ R){
- $ Errors[] ="Unable to use ghostscript to convert. ps (".$ File_ps.")->. Pdf (".$ File_pdf."). Check rights .";
- }
- }
- }
- // Return array with errors, or true with success.
- If(!Count($ Errors)){
- ReturnTrue;
- }Else{
- Return $ Errors;
- }
- }