almost 9 years ago
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:
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;
}
}
}
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.
Can you help out the community by solving one of the following Illustrator problems?
Do activity (Answer, Blog) > Earn Rep Points > Improve Rank > Get more opportunities to work and get paid!
For more topics, questions and answers, please visit the Tech Q&A page.
0 Comment(s)