How to convert tif format to pdf or other formats in Ubuntu

Source: Internet
Author: User
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

  1. Private FunctionTif_to_pdf ($ File_tif,$ File_pdf){
  2. $ Errors=Array();
  3. $ Pai_ps2pdf="/Usr/bin/ps2jwwr";
  4. // $ File_tif = escapeshellarg ($ file_tif); // The escapeshellarg function is used to filter shell parameters.
  5. // $ File_pdf = escapeshellarg ($ file_pdf );
  6. If(!File_exists($ File_tif))$ Errors[] ="Original TIFF file :".$ File_tif."Does not exist";
  7. If(!File_exists($ Pai_ps2pdf))$ Errors[] ="Ghostscript PostScript to PDF converter not found :".$ Pai_ps2pdf;
  8. If(!Extension_loaded("Imagick"))$ Errors[] ="Imagick extension not installed or not loaded";
  9. If(!Count($ Errors)){
  10. // Confirm the basic path of the file
  11. $ Base=$ File_pdf;
  12. If(($ Ext=Strrchr($ File_pdf,'.'))! = False)$ Base=Substr($ File_pdf, 0 ,-Strlen($ Ext));
  13. // Determine the temporary. ps filepath
  14. $ File_ps=$ Base.". Ps";
  15. // Open the original. tiff File
  16. $ Document=NewImagick ($ File_tif);
  17. // Use Imagick to write multiple pages to 1. ps file
  18. If(!$ Document-> WriteImages ($ File_ps, True )){
  19. $ Errors[] ="Unable to use Imagick to write multiple pages to 1. ps file :".$ File_ps;
  20. }Else{
  21. $ Document-> Clear ();
  22. // Use ghostscript to convert. ps->. pdf
  23. Exec($ Pai_ps2pdf."-SPAPERSIZE = a4".$ File_ps."".$ File_pdf,$ O,$ R);
  24. If($ R){
  25. $ Errors[] ="Unable to use ghostscript to convert. ps (".$ File_ps.")->. Pdf (".$ File_pdf."). Check rights .";
  26. }
  27. }
  28. }
  29. // Return array with errors, or true with success.
  30. If(!Count($ Errors)){
  31. ReturnTrue;
  32. }Else{
  33. Return $ Errors;
  34. }
  35. }

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.