Below is a sample code base to convert PDF files to HTML5 template making use of well known tool Crocdoc :
$_product = $observer->getProduct();
$productid=$_product->getId();
$read = Mage::getSingleton('core/resource')->getConnection('core_read');
$query = 'SELECT link_file,link_url from downloadable_link where product_id='.$productid;
$results = $read->fetchAll($query);
if($results[0]['link_file']||$results[0]['link_url']){
if($results[0]['link_file']) {
$l1=$results[0]['link_file'];
$link=Mage::getBaseUrl(Mage_Core_Model_Store::URL_TYPE_MEDIA).'downloadable/files/links'.$l1;
} else {
$l1=end(explode('/',$results[0]['link_url']));
$link=Mage::getBaseUrl(Mage_Core_Model_Store::URL_TYPE_MEDIA).'downloadable/files/'.$l1;
}
Mage::log($link);
error_reporting(E_ALL);
$exampleApiToken = 'AXa5RgV6MDQzm9tbKZJYepqI';
if (php_sapi_name() != 'cli') {
header('Content-Type: text/plain');
}
$ExternalLibPath=Mage::getModuleDir('', 'Pack_Book') . DS . 'lib' . DS .'Crocodoc.php';
require_once ($ExternalLibPath);
$que = 'SELECT * from catalog_product_response where product_id='.$productid;
$results1 = $read->fetchAll($que);
$update=0;
if($results1[0]['product_id'])
$update=1;
//Mage::log($results1[0]['uuid']);
Crocodoc::setApiToken($exampleApiToken);
$uuid = null;
try {
$uuid = CrocodocDocument::upload($link);
$write = Mage::getSingleton("core/resource")->getConnection("core_write");
if($update==0)
$query1 = 'INSERT INTO catalog_product_response VALUES ('.$productid.',"'.$uuid.'")';
else
$query1 = 'update catalog_product_response set uuid = "'.$uuid.'" where product_id='.$productid;
$write->query($query1);
return ;
} catch (CrocodocException $e) {
return ;
}
return ;
0 Comment(s)