Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
  • CONVERTING DOC FILE TO PDF IN CAKE PHP

    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 351
    Comment on it

    In order to convert .doc file to .pdf file in cake PHP I have used ZEND library here. Following steps are needed to be done:

    1. You need to make sure SOAP extension is enable on your server.
    2. Use ZEND library as third party. Put ZEND library inside the vendor folder in app folder.
    3. Create an account here which will be used in controller
      https://www.livedocx.com/user/account_registration.aspx
    4. Inside app/Vendor folder create a file named zend_include_path.php. Now open this file and write the following code inside it:
      <?php ini_set('include_path',ini_get('include_path').PATH_SEPARATOR . dirname(__FILE__));?>

       

    In the controller write the following code:

    YourController:

    class UsersController extends AppController {
         var $name = 'Users';
         function convertDocToPdf(){
            // set the document path
            $docPath = 'path to test.docx';
            // set the pdf path
            $PdfPath = 'path to pdf';
            // import library
            App::import('Vendor', 'zend_include_path');
            App::import('Vendor', 'Zend_Service_LiveDocx_MailMerge', true, false, 'Zend/Service/LiveDocx/MailMerge.php');
            App::import('Vendor', 'Zend_Service_LiveDocx_Exception', true, false, 'Zend/Service/LiveDocx/Exception.php');
            // call the class mailmerge
            $mailMerge = new Zend_Service_LiveDocx_MailMerge();
            // sets the login username & password here to access services      
            $mailMerge->setUsername('username')->setPassword('*****');
            $mailMerge->setLocalTemplate($docPath); // sets the docx file.
            $mailMerge->createDocument();
            $document = $mailMerge->retrieveDocument('pdf');
            if(file_put_contents($PdfPath, $document)){
                return true;
            }else{
                return false;
            }
        }
    }

    Now call the function convertDocToPdf().

    Please remember to provide the doc file path to be converted and put the credentials you got after registering in the link provided above.

 0 Comment(s)

Sign In
                           OR                           
                           OR                           
Register

Sign up using

                           OR                           
Forgot Password
Fill out the form below and instructions to reset your password will be emailed to you:
Reset Password
Fill out the form below and reset your password: