<?php
function _pdf_menu() {
$items = array();
$items['view_pdf/%'] = array(
'title' => 'PDF',
'page callback' => '_download_pdf',
'page arguments' => array(1),
'access arguments' => array('access content'),
'type' => MENU_CALLBACK,
);
return $items;
}
function _download_pdf($nid){
drupal_goto("sites/default/files/PDFs/test_".$nid.".pdf");
}
function _pdf_nodeapi(&$node, $op, $a3 = NULL, $a4 = NULL){
$type = $node->type;
switch ($op) {
case 'insert':
case 'update':
if($type=="cocktail"){
_pdf_conversion($node->nid);
}
break;
}
}
function _pdf_conversion($nid){
$url = url('node/'.$nid.'/pdfversion',array('absolute' => TRUE));
//print_r($_SERVER);
//$module_folder = dirname(__FILE__);
$module_folder = realpath(drupal_get_path('module', 'module_pdf'));
$wkhtmltopdf = $module_folder . '/wkhtmltopdf.exe';
$destination = realpath(file_directory_path()) . '/PDFs/';
if(!is_dir($destination)){
mkdir($destination);
}
$sentence = $wkhtmltopdf.' ' . $url . ' ' . $destination . 'test_'.$nid.'.pdf';
$output = shell_exec($sentence);
//return "<pre>$output</pre>";
}
No hay comentarios:
Publicar un comentario