BUG 9898 PDF limit 6 pages SOLVED

- When we generate a pdf in process, it can be created and download, but it can't over 6 pages.
- Was added new report generator pdf.
This commit is contained in:
Hector Cortez
2012-11-09 16:40:48 -04:00
parent 507dce7552
commit aecf461295
277 changed files with 82551 additions and 9161 deletions

View File

@@ -704,208 +704,24 @@ class OutputDocument extends BaseOutputDocument
/* End - Create .doc */
if ($sTypeDocToGener == 'BOTH' || $sTypeDocToGener == 'PDF') {
/* Start - Create .pdf */
$oFile = fopen($sPath . $sFilename . '.html', 'wb');
fwrite($oFile, $sContent);
fclose($oFile);
define("MAX_FREE_FRACTION", 1);
define('PATH_OUTPUT_FILE_DIRECTORY', PATH_HTML . 'files/' . $_SESSION['APPLICATION'] . '/outdocs/');
G::verifyPath(PATH_OUTPUT_FILE_DIRECTORY, true);
require_once (PATH_THIRDPARTY . 'html2ps_pdf/config.inc.php');
require_once (PATH_THIRDPARTY . 'html2ps_pdf/pipeline.factory.class.php');
parse_config_file(PATH_THIRDPARTY . 'html2ps_pdf/html2ps.config');
$GLOBALS['g_config'] = array(
'cssmedia' => 'screen',
'media' => 'Letter',
'scalepoints' => false,
'renderimages' => true,
'renderfields' => true,
'renderforms' => false,
'pslevel' => 3,
'renderlinks' => true,
'pagewidth' => 800,
'landscape' => $sLandscape,
'method' => 'fpdf',
'margins' => array('left' => 15, 'right' => 15, 'top' => 15, 'bottom' => 15,),
'encoding' => '',
'ps2pdf' => false,
'compress' => false,
'output' => 2,
'pdfversion' => '1.3',
'transparency_workaround' => false,
'imagequality_workaround' => false,
'draw_page_border' => isset($_REQUEST['pageborder']),
'debugbox' => false,
'html2xhtml' => true,
'mode' => 'html',
'smartpagebreak' => true
);
$GLOBALS['g_config']= array_merge($GLOBALS['g_config'],$aProperties);
$g_media = Media::predefined($GLOBALS['g_config']['media']);
$g_media->set_landscape($GLOBALS['g_config']['landscape']);
$g_media->set_margins($GLOBALS['g_config']['margins']);
$g_media->set_pixels($GLOBALS['g_config']['pagewidth']);
if (isset($GLOBALS['g_config']['pdfSecurity'])) {
if (isset($GLOBALS['g_config']['pdfSecurity']['openPassword']) &&
$GLOBALS['g_config']['pdfSecurity']['openPassword'] != ""
) {
$GLOBALS['g_config']['pdfSecurity']['openPassword'] = G::decrypt(
$GLOBALS['g_config']['pdfSecurity']['openPassword'],
$sUID
);
}
if (isset($GLOBALS['g_config']['pdfSecurity']['ownerPassword']) &&
$GLOBALS['g_config']['pdfSecurity']['ownerPassword'] != ""
) {
$GLOBALS['g_config']['pdfSecurity']['ownerPassword'] = G::decrypt(
$GLOBALS['g_config']['pdfSecurity']['ownerPassword'],
$sUID
);
}
$g_media->set_security($GLOBALS['g_config']['pdfSecurity']);
require_once (HTML2PS_DIR . 'pdf.fpdf.encryption.php');
}
$pipeline = new Pipeline();
if (extension_loaded('curl')) {
require_once (HTML2PS_DIR . 'fetcher.url.curl.class.php');
$pipeline->fetchers = array(new FetcherURLCurl());
if (isset($proxy)) {
if ($proxy != '') {
$pipeline->fetchers[0]->set_proxy($proxy);
}
/* Start - Create .pdf */
if (isset($aProperties['report_generator'])) {
switch ($aProperties['report_generator']) {
case 'TCPDF':
$this->generateTcpdf($sUID, $aFields, $sPath, $sFilename, $sContent, $sLandscape, $aProperties);
break;
case 'HTML2PDF':
default:
$this->generateHtml2ps_pdf($sUID, $aFields, $sPath, $sFilename, $sContent, $sLandscape, $aProperties);
break;
}
} else {
require_once (HTML2PS_DIR . 'fetcher.url.class.php');
$pipeline->fetchers[] = new FetcherURL();
$this->generateHtml2ps_pdf($sUID, $aFields, $sPath, $sFilename, $sContent, $sLandscape, $aProperties);
}
$pipeline->data_filters[] = new DataFilterDoctype();
$pipeline->data_filters[] = new DataFilterUTF8($GLOBALS['g_config']['encoding']);
if ($GLOBALS['g_config']['html2xhtml']) {
$pipeline->data_filters[] = new DataFilterHTML2XHTML();
} else {
$pipeline->data_filters[] = new DataFilterXHTML2XHTML();
}
$pipeline->parser = new ParserXHTML();
$pipeline->pre_tree_filters = array();
$header_html = '';
$footer_html = '';
$filter = new PreTreeFilterHeaderFooter($header_html, $footer_html);
$pipeline->pre_tree_filters[] = $filter;
if ($GLOBALS['g_config']['renderfields']) {
$pipeline->pre_tree_filters[] = new PreTreeFilterHTML2PSFields();
}
if ($GLOBALS['g_config']['method'] === 'ps') {
$pipeline->layout_engine = new LayoutEnginePS();
} else {
$pipeline->layout_engine = new LayoutEngineDefault();
}
$pipeline->post_tree_filters = array();
if ($GLOBALS['g_config']['pslevel'] == 3) {
$image_encoder = new PSL3ImageEncoderStream();
} else {
$image_encoder = new PSL2ImageEncoderStream();
}
switch ($GLOBALS['g_config']['method']) {
case 'fastps':
if ($GLOBALS['g_config']['pslevel'] == 3) {
$pipeline->output_driver = new OutputDriverFastPS($image_encoder);
} else {
$pipeline->output_driver = new OutputDriverFastPSLevel2($image_encoder);
}
break;
case 'pdflib':
$pipeline->output_driver = new OutputDriverPDFLIB16($GLOBALS['g_config']['pdfversion']);
break;
case 'fpdf':
$pipeline->output_driver = new OutputDriverFPDF();
break;
case 'png':
$pipeline->output_driver = new OutputDriverPNG();
break;
case 'pcl':
$pipeline->output_driver = new OutputDriverPCL();
break;
default:
die('Unknown output method');
}
if (isset($GLOBALS['g_config']['watermarkhtml'])) {
$watermark_text = $GLOBALS['g_config']['watermarkhtml'];
} else {
$watermark_text = '';
}
$pipeline->output_driver->set_watermark($watermark_text);
if ($watermark_text != '') {
$dispatcher =& $pipeline->getDispatcher();
}
if ($GLOBALS['g_config']['debugbox']) {
$pipeline->output_driver->set_debug_boxes(true);
}
if ($GLOBALS['g_config']['draw_page_border']) {
$pipeline->output_driver->set_show_page_border(true);
}
if ($GLOBALS['g_config']['ps2pdf']) {
$pipeline->output_filters[] = new OutputFilterPS2PDF($GLOBALS['g_config']['pdfversion']);
}
if ($GLOBALS['g_config']['compress'] && $GLOBALS['g_config']['method'] == 'fastps') {
$pipeline->output_filters[] = new OutputFilterGZip();
}
if (!isset($GLOBALS['g_config']['process_mode'])) {
$GLOBALS['g_config']['process_mode'] = '';
}
if ($GLOBALS['g_config']['process_mode'] == 'batch') {
$filename = 'batch';
} else {
$filename = $sFilename;
}
switch ($GLOBALS['g_config']['output']) {
case 0:
$pipeline->destination = new DestinationBrowser($filename);
break;
case 1:
$pipeline->destination = new DestinationDownload($filename);
break;
case 2:
$pipeline->destination = new DestinationFile($filename);
break;
}
copy($sPath . $sFilename . '.html', PATH_OUTPUT_FILE_DIRECTORY . $sFilename . '.html');
$status = $pipeline->process(((isset($_SERVER['HTTPS']))&&($_SERVER['HTTPS']=='on') ? 'https://' : 'http://') . $_SERVER['HTTP_HOST'] . '/files/' . $_SESSION['APPLICATION'] . '/outdocs/' . $sFilename . '.html', $g_media);
copy(PATH_OUTPUT_FILE_DIRECTORY . $sFilename . '.pdf', $sPath . $sFilename . '.pdf');
unlink(PATH_OUTPUT_FILE_DIRECTORY . $sFilename . '.pdf');
unlink(PATH_OUTPUT_FILE_DIRECTORY . $sFilename . '.html');
}
//end if $sTypeDocToGener
/* End - Create .pdf */
@@ -922,6 +738,371 @@ class OutputDocument extends BaseOutputDocument
}
}
public function generateHtml2pdf($sUID, $aFields, $sPath, $sFilename, $sContent, $sLandscape = false, $aProperties = array() )
{
// define("MAX_FREE_FRACTION", 1);
define('PATH_OUTPUT_FILE_DIRECTORY', PATH_HTML . 'files/' . $_SESSION['APPLICATION'] . '/outdocs/');
G::verifyPath(PATH_OUTPUT_FILE_DIRECTORY, true);
require_once(PATH_THIRDPARTY . 'html2pdf/html2pdf.class.php');
// define Save file
$sOutput = 2;
$sOrientation = ($sLandscape == false)? 'P' : 'L';
$sLang = (defined('SYS_LANG'))? SYS_LANG : 'en';
$sMedia = $aProperties['media'];
// margin define
define("MINIMAL_MARGIN", 15);
$marges = array(MINIMAL_MARGIN, MINIMAL_MARGIN, MINIMAL_MARGIN, MINIMAL_MARGIN);
if (isset($aProperties['margins'])) {
// Default marges (left, top, right, bottom)
$margins = $aProperties['margins'];
$margins['left'] = ($margins['left']>0)? $margins['left']: MINIMAL_MARGIN;
$margins['top'] = ($margins['top']>0)? $margins['top']: MINIMAL_MARGIN;
$margins['right'] = ($margins['right']>0)? $margins['right']: MINIMAL_MARGIN;
$margins['bottom'] = ($margins['bottom']>0)? $margins['bottom']: MINIMAL_MARGIN;
$marges = array($margins['left'], $margins['top'], $margins['right'], $margins['bottom'] );
}
$html2pdf = new HTML2PDF($sOrientation, $sMedia, $sLang, true, 'UTF-8', $marges);
$html2pdf->pdf->SetAuthor($aFields['USR_USERNAME']);
$html2pdf->pdf->SetTitle('Processmaker');
$html2pdf->pdf->SetSubject($sFilename);
//$html2pdf->pdf->SetKeywords('HTML2PDF, TCPDF, processmaker');
if (isset($aProperties['pdfSecurity'])) {
$pdfSecurity = $aProperties['pdfSecurity'];
$userPass = G::decrypt($pdfSecurity['openPassword'], $sUID);
$ownerPass = ($pdfSecurity['ownerPassword'] != '') ? G::decrypt($pdfSecurity['ownerPassword'], $sUID): null;
$permissions = explode("|", $pdfSecurity['permissions']);
$html2pdf->pdf->SetProtection($permissions, $userPass, $ownerPass);
}
$html2pdf->setTestTdInOnePage(false);
$html2pdf->setTestIsImage(false);
$html2pdf->setTestIsDeprecated(false);
$html2pdf->writeHTML($html2pdf->getHtmlFromPage($sContent));
switch ($sOutput) {
case 0:
// Vrew browser
$html2pdf->Output($sPath . $sFilename . '.pdf', 'I');
break;
case 1:
// Donwnload
$html2pdf->Output($sPath . $sFilename . '.pdf', 'D');
break;
case 2:
// Save file
$html2pdf->Output($sPath . $sFilename . '.pdf', 'F');
break;
}
copy($sPath . $sFilename . '.html', PATH_OUTPUT_FILE_DIRECTORY . $sFilename . '.html');
copy(PATH_OUTPUT_FILE_DIRECTORY . $sFilename . '.pdf', $sPath . $sFilename . '.pdf');
unlink(PATH_OUTPUT_FILE_DIRECTORY . $sFilename . '.pdf');
unlink(PATH_OUTPUT_FILE_DIRECTORY . $sFilename . '.html');
}
public function generateTcpdf($sUID, $aFields, $sPath, $sFilename, $sContent, $sLandscape = false, $aProperties = array())
{
require_once(PATH_THIRDPARTY . 'tcpdf/config/lang/eng.php');
require_once(PATH_THIRDPARTY . 'tcpdf/tcpdf.php');
// define Save file
$sOutput = 2;
$sOrientation = ($sLandscape == false)? PDF_PAGE_ORIENTATION : 'L';
$sMedia = (isset($aProperties['media'])) ? $aProperties['media'] : PDF_PAGE_FORMAT;
$sLang = (defined('SYS_LANG'))? SYS_LANG : 'en';
// create new PDF document
$pdf = new TCPDF($sOrientation, PDF_UNIT, $sMedia, true, 'UTF-8', false);
// set document information
$pdf->SetCreator(PDF_CREATOR);
$pdf->SetAuthor($aFields['USR_USERNAME']);
$pdf->SetTitle('Processmaker');
$pdf->SetSubject($sFilename);
$margins = $aProperties['margins'];
$margins['left'] = ($margins['left']>0)? $margins['left']: PDF_MARGIN_LEFT;
$margins['top'] = ($margins['top']>0)? $margins['top']: PDF_MARGIN_TOP;
$margins['right'] = ($margins['right']>0)? $margins['right']: PDF_MARGIN_RIGHT;
$margins['bottom'] = ($margins['bottom']>0)? $margins['bottom']: PDF_MARGIN_BOTTOM;
$pdf->setPrintHeader(false);
$pdf->setPrintFooter(false);
$pdf->SetLeftMargin($margins['left']);
$pdf->SetTopMargin($margins['top']);
$pdf->SetRightMargin($margins['right']);
$pdf->SetAutoPageBreak(true, $margins['bottom']);
$oServerConf =& serverConf::getSingleton();
// set some language dependent data:
$lg = Array();
$lg['a_meta_charset'] = 'UTF-8';
$lg['a_meta_dir'] = ($oServerConf->isRtl($sLang)) ? 'rtl' : 'ltr' ;
$lg['a_meta_language'] = $sLang;
$lg['w_page'] = 'page';
//set some language-dependent strings
$pdf->setLanguageArray($lg);
if (isset($aProperties['pdfSecurity'])) {
$pdfSecurity = $aProperties['pdfSecurity'];
$userPass = G::decrypt($pdfSecurity['openPassword'], $sUID);
$ownerPass = ($pdfSecurity['ownerPassword'] != '') ? G::decrypt($pdfSecurity['ownerPassword'], $sUID): null;
$permissions = explode("|", $pdfSecurity['permissions']);
$pdf->SetProtection($permissions, $userPass, $ownerPass);
}
// ---------------------------------------------------------
// set default font subsetting mode
$pdf->setFontSubsetting(true);
// Set font
// dejavusans is a UTF-8 Unicode font, if you only need to
// print standard ASCII chars, you can use core fonts like
// helvetica or times to reduce file size.
$pdf->SetFont('dejavusans', '', 14, '', true);
// Add a page
// This method has several options, check the source code documentation for more information.
$pdf->AddPage();
// set text shadow effect
//$pdf->setTextShadow(array('enabled'=>true, 'depth_w'=>0.2, 'depth_h'=>0.2, 'color'=>array(196,196,196), 'opacity'=>1, 'blend_mode'=>'Normal'));
// Print text using writeHTMLCell()
// $pdf->writeHTMLCell($w=0, $h=0, $x='', $y='', $html, $border=0, $ln=1, $fill=0, $reseth=true, $align='', $autopadding=true);
$pdf->writeHTML($sContent);
// ---------------------------------------------------------
// Close and output PDF document
// This method has several options, check the source code documentation for more information.
//$pdf->Output('example_00.pdf', 'I');
//$pdf->Output('/home/hector/processmaker/example_00.pdf', 'D');
switch ($sOutput) {
case 0:
// Vrew browser
$pdf->Output($sPath . $sFilename . '.pdf', 'I');
break;
case 1:
// Donwnload
$pdf->Output($sPath . $sFilename . '.pdf', 'D');
break;
case 2:
// Save file
$pdf->Output($sPath . $sFilename . '.pdf', 'F');
break;
}
}
public function generateHtml2ps_pdf($sUID, $aFields, $sPath, $sFilename, $sContent, $sLandscape = false, $aProperties = array() )
{
define("MAX_FREE_FRACTION", 1);
define('PATH_OUTPUT_FILE_DIRECTORY', PATH_HTML . 'files/' . $_SESSION['APPLICATION'] . '/outdocs/');
G::verifyPath(PATH_OUTPUT_FILE_DIRECTORY, true);
require_once (PATH_THIRDPARTY . 'html2ps_pdf/config.inc.php');
require_once (PATH_THIRDPARTY . 'html2ps_pdf/pipeline.factory.class.php');
parse_config_file(PATH_THIRDPARTY . 'html2ps_pdf/html2ps.config');
$GLOBALS['g_config'] = array(
'cssmedia' => 'screen',
'media' => 'Letter',
'scalepoints' => false,
'renderimages' => true,
'renderfields' => true,
'renderforms' => false,
'pslevel' => 3,
'renderlinks' => true,
'pagewidth' => 800,
'landscape' => $sLandscape,
'method' => 'fpdf',
'margins' => array('left' => 15, 'right' => 15, 'top' => 15, 'bottom' => 15,),
'encoding' => '',
'ps2pdf' => false,
'compress' => false,
'output' => 2,
'pdfversion' => '1.3',
'transparency_workaround' => false,
'imagequality_workaround' => false,
'draw_page_border' => isset($_REQUEST['pageborder']),
'debugbox' => false,
'html2xhtml' => true,
'mode' => 'html',
'smartpagebreak' => true
);
$GLOBALS['g_config']= array_merge($GLOBALS['g_config'],$aProperties);
$g_media = Media::predefined($GLOBALS['g_config']['media']);
$g_media->set_landscape($GLOBALS['g_config']['landscape']);
$g_media->set_margins($GLOBALS['g_config']['margins']);
$g_media->set_pixels($GLOBALS['g_config']['pagewidth']);
if (isset($GLOBALS['g_config']['pdfSecurity'])) {
if (isset($GLOBALS['g_config']['pdfSecurity']['openPassword']) &&
$GLOBALS['g_config']['pdfSecurity']['openPassword'] != ""
) {
$GLOBALS['g_config']['pdfSecurity']['openPassword'] = G::decrypt(
$GLOBALS['g_config']['pdfSecurity']['openPassword'],
$sUID
);
}
if (isset($GLOBALS['g_config']['pdfSecurity']['ownerPassword']) &&
$GLOBALS['g_config']['pdfSecurity']['ownerPassword'] != ""
) {
$GLOBALS['g_config']['pdfSecurity']['ownerPassword'] = G::decrypt(
$GLOBALS['g_config']['pdfSecurity']['ownerPassword'],
$sUID
);
}
$g_media->set_security($GLOBALS['g_config']['pdfSecurity']);
require_once (HTML2PS_DIR . 'pdf.fpdf.encryption.php');
}
$pipeline = new Pipeline();
if (extension_loaded('curl')) {
require_once (HTML2PS_DIR . 'fetcher.url.curl.class.php');
$pipeline->fetchers = array(new FetcherURLCurl());
if (isset($proxy)) {
if ($proxy != '') {
$pipeline->fetchers[0]->set_proxy($proxy);
}
}
} else {
require_once (HTML2PS_DIR . 'fetcher.url.class.php');
$pipeline->fetchers[] = new FetcherURL();
}
$pipeline->data_filters[] = new DataFilterDoctype();
$pipeline->data_filters[] = new DataFilterUTF8($GLOBALS['g_config']['encoding']);
if ($GLOBALS['g_config']['html2xhtml']) {
$pipeline->data_filters[] = new DataFilterHTML2XHTML();
} else {
$pipeline->data_filters[] = new DataFilterXHTML2XHTML();
}
$pipeline->parser = new ParserXHTML();
$pipeline->pre_tree_filters = array();
$header_html = '';
$footer_html = '';
$filter = new PreTreeFilterHeaderFooter($header_html, $footer_html);
$pipeline->pre_tree_filters[] = $filter;
if ($GLOBALS['g_config']['renderfields']) {
$pipeline->pre_tree_filters[] = new PreTreeFilterHTML2PSFields();
}
if ($GLOBALS['g_config']['method'] === 'ps') {
$pipeline->layout_engine = new LayoutEnginePS();
} else {
$pipeline->layout_engine = new LayoutEngineDefault();
}
$pipeline->post_tree_filters = array();
if ($GLOBALS['g_config']['pslevel'] == 3) {
$image_encoder = new PSL3ImageEncoderStream();
} else {
$image_encoder = new PSL2ImageEncoderStream();
}
switch ($GLOBALS['g_config']['method']) {
case 'fastps':
if ($GLOBALS['g_config']['pslevel'] == 3) {
$pipeline->output_driver = new OutputDriverFastPS($image_encoder);
} else {
$pipeline->output_driver = new OutputDriverFastPSLevel2($image_encoder);
}
break;
case 'pdflib':
$pipeline->output_driver = new OutputDriverPDFLIB16($GLOBALS['g_config']['pdfversion']);
break;
case 'fpdf':
$pipeline->output_driver = new OutputDriverFPDF();
break;
case 'png':
$pipeline->output_driver = new OutputDriverPNG();
break;
case 'pcl':
$pipeline->output_driver = new OutputDriverPCL();
break;
default:
die('Unknown output method');
}
if (isset($GLOBALS['g_config']['watermarkhtml'])) {
$watermark_text = $GLOBALS['g_config']['watermarkhtml'];
} else {
$watermark_text = '';
}
$pipeline->output_driver->set_watermark($watermark_text);
if ($watermark_text != '') {
$dispatcher =& $pipeline->getDispatcher();
}
if ($GLOBALS['g_config']['debugbox']) {
$pipeline->output_driver->set_debug_boxes(true);
}
if ($GLOBALS['g_config']['draw_page_border']) {
$pipeline->output_driver->set_show_page_border(true);
}
if ($GLOBALS['g_config']['ps2pdf']) {
$pipeline->output_filters[] = new OutputFilterPS2PDF($GLOBALS['g_config']['pdfversion']);
}
if ($GLOBALS['g_config']['compress'] && $GLOBALS['g_config']['method'] == 'fastps') {
$pipeline->output_filters[] = new OutputFilterGZip();
}
if (!isset($GLOBALS['g_config']['process_mode'])) {
$GLOBALS['g_config']['process_mode'] = '';
}
if ($GLOBALS['g_config']['process_mode'] == 'batch') {
$filename = 'batch';
} else {
$filename = $sFilename;
}
switch ($GLOBALS['g_config']['output']) {
case 0:
$pipeline->destination = new DestinationBrowser($filename);
break;
case 1:
$pipeline->destination = new DestinationDownload($filename);
break;
case 2:
$pipeline->destination = new DestinationFile($filename);
break;
}
copy($sPath . $sFilename . '.html', PATH_OUTPUT_FILE_DIRECTORY . $sFilename . '.html');
$status = $pipeline->process(((isset($_SERVER['HTTPS']))&&($_SERVER['HTTPS']=='on') ? 'https://' : 'http://') . $_SERVER['HTTP_HOST'] . '/files/' . $_SESSION['APPLICATION'] . '/outdocs/' . $sFilename . '.html', $g_media);
copy(PATH_OUTPUT_FILE_DIRECTORY . $sFilename . '.pdf', $sPath . $sFilename . '.pdf');
unlink(PATH_OUTPUT_FILE_DIRECTORY . $sFilename . '.pdf');
unlink(PATH_OUTPUT_FILE_DIRECTORY . $sFilename . '.html');
}
/**
* verify if Output row specified in [sUid] exists.