VirtueMart Forum

VirtueMart 2 + 3 + 4 => General Questions => Topic started by: Adwans on March 23, 2018, 16:24:49 PM

Title: Re: How Joomla 3.8 generates PDF now? Lack of pdf.php, new libraries structure
Post by: Adwans on March 23, 2018, 16:24:49 PM
Hello Guys,
I finally got everything updated up to VM. 3.2.12 and J! 3.8.6
Since J! 3.8 many things changed  - you know - e.g. before  I had PDFs generated just using format=pdf in Urls.
Now, with me trying to use this, new joomla gives an error:
QuoteCall to undefined method Joomla\CMS\Document\RawDocument::setName()
Looks like redirecting me to RawDocument instead of PdfDocument.
Is there any other location with PdfDocument class since J! 3.8 ? How it works now?
maybe my question is funny,  but I'm new to Joomla 3.8 changes.
Title: Re: How Joomla 3.18 generates PDF now?
Post by: jenkinhill on March 23, 2018, 16:52:30 PM
Obviously really a question for the Joomla forum, but pdf generation was removed from Joomla some versions ago.  There are extensions to generate pdfs, though in the JED (https://extensions.joomla.org/extensions/extension/?searchall=pdf&filter%5Btags%5D%5B%5D=&filter%5Bcore_catid%5D=&filter%5Bincludes%5D=&filter%5Bversions%5D=&filter%5Btype%5D=&filter%5Bhasdemo%5D=&filter%5Bnewupdated%5D=&filter%5Bscore%5D=&dir=DESC&limitstart=&controller=filter&view=extension&layout=list&Itemid=145&clearorders=0&clearfilters=1)
Title: Re: How Joomla 3.8 generates PDF now?
Post by: Adwans on March 23, 2018, 17:56:50 PM
You are absolutely right, I will ask on J Forum, but VM also generates PDF using TCPDF and something changed with Joomla 3.18.
I know that native Joomla generation was removed years ago.
Maybe any hint?
Title: Re: How Joomla 3.18 generates PDF now?
Post by: Studio 42 on March 24, 2018, 00:07:52 AM
Here native PDF https://github.com/studio42/joomla-pdf-document-view, i dont use it anymore, but should work as you need.
It use any PDF libraries, you can donwload packages from here http://studio42.github.io/joomla-pdf-document-view/index.html or use any you want.
If you can install wkhtmltopdf(need a dedicated server) you can render wysiwyg print quality.
Title: Re: How Joomla 3.8 generates PDF now?
Post by: Adwans on March 24, 2018, 23:31:26 PM
Ok, but it is impossibile  to use - AFAIK - libraries/joomla/document/pdf/pdf.php coz newest Joomla does not use libraries/joomla/document -
we have libraries/src/Document
Phoca gallery faced same problem recently. Do we have any equivalent of pdf.php
@jenkinhill, this is not a sole J! problem, since pdf.php belongs to VM stuff.  ;)
Title: Re: How Joomla 3.18 generates PDF now?
Post by: Studio 42 on March 25, 2018, 01:13:16 AM
Hum, i dont have see it, you are right, they changed all, path, filename, classname ....
I perhaps update it, but not for now, i dont know how long it take to do all changes.
Title: Re: How Joomla 3.18 generates PDF now?
Post by: jenkinhill on March 25, 2018, 13:10:13 PM
VirtueMart uses its own version of tcpdf for generating invoices & delivery notes, com_tcpdf_1.0.4.zip in the VM installation package puts the files in  /libraries/tcpdf
Title: Re: How Joomla 3.8 generates PDF now? Lack of pdf.php, new libraries structure
Post by: Adwans on March 26, 2018, 18:58:50 PM
QuoteVersion: 1.0.4 of February 2015
TCPDF 6.2.12 by Nicola Asuni. Joomla Installer by the VirtueMart Team
Already on board...
It makes nothing. 
Lack of pdf.php is a problem. Do you really have :
/libraries/tcpdf
in Joomla 3.8.+ ?
EDIT: Joomla 3.8 of course... :D
Title: Re: Re: How Joomla 3.8 generates PDF now? Lack of pdf.php, new libraries structure
Post by: Studio 42 on March 26, 2018, 21:31:42 PM
Quote from: jenkinhill on March 25, 2018, 13:10:13 PM
VirtueMart uses its own version of tcpdf for generating invoices & delivery notes, com_tcpdf_1.0.4.zip in the VM installation package puts the files in  /libraries/tcpdf
You have the answer : Virtuemart do not support anymore the creation of PDF excluding invoices & delivery notes.
Joomla 3 never supported PDF in core.
Title: Re: Re: How Joomla 3.8 generates PDF now? Lack of pdf.php, new libraries structure
Post by: Adwans on March 27, 2018, 09:29:04 AM
Quote from: Studio 42 on March 26, 2018, 21:31:42 PM
Quote from: jenkinhill on March 25, 2018, 13:10:13 PM
VirtueMart uses its own version of tcpdf for generating invoices & delivery notes, com_tcpdf_1.0.4.zip in the VM installation package puts the files in  /libraries/tcpdf
You have the answer : Virtuemart do not support anymore the creation of PDF excluding invoices & delivery notes.
Joomla 3 never supported PDF in core.
1. We dont have /libraries/tcpdf , so VM cannot put here anything anymore. Sorry, its nonsense. Although, thank You for information. As you told - everything has changed
QuoteHum, i dont have see it, you are right, they changed all, path, filename, classname ....
2. I need  to create pdf from some "orders" before an invoice number is set. Before J 3.8 I did it with a little help from "details_pdf.php" file and "pdf.php" . 
3. Tell me please - 
Quotei dont use it anymore, but should work as you need.
- do You use different PDF library /solution?
3. Getting closer to quit Joomla - considering updates of this sort.  After 8 years. Thank you for help though.
Title: Re: Re: How Joomla 3.8 generates PDF now? Lack of pdf.php, new libraries structure
Post by: jenkinhill on March 27, 2018, 11:49:23 AM
Quote from: Adwans on March 27, 2018, 09:29:04 AM

1. We dont have /libraries/tcpdf , so VM cannot put here anything anymore. Sorry, its nonsense. Although, thank You for information. As you told - everything has changed


The VM tcpdf component (com_tcpdf_1.0.4.zip) creates library/tcpdf in Joomla on installation.
Title: Re: Re: How Joomla 3.8 generates PDF now? Lack of pdf.php, new libraries structure
Post by: Studio 42 on March 27, 2018, 18:01:53 PM
Quote from: Adwans on March 27, 2018, 09:29:04 AM
3. Getting closer to quit Joomla - considering updates of this sort.  After 8 years. Thank you for help though.
No framework support PDF anymore, and Joomla removed PDF core support since more then 2 or 3 years.
If you need it you can use plugins to add PDF support.
I explained that if you modify my plugin https://github.com/studio42/joomla-pdf-document-view, you can use it with all Joomla extentions and all view on adding a PDF button.
Here someexplain http://studio42.github.io/joomla-pdf-document-view/developper.html
Note that i simplified the task,
Before the view.pdf.php was madatory.
In my plugin it fallback to view.html.php, so it have chance to work in many case.
Title: Re: How Joomla 3.8 generates PDF now? Lack of pdf.php, new libraries structure
Post by: Adwans on March 27, 2018, 19:20:56 PM
@Kelvyn  You're right, i meant \document.
@Studio 42, thank you, I had created PdfDocument using Document, still no effect but "error" .  And now - your posts inspired me i will try more. Till (positive) effect.   
Title: Re: How Joomla 3.8 generates PDF now? Lack of pdf.php, new libraries structure
Post by: Adwans on April 07, 2018, 18:57:51 PM
Hello again, Im still working on adapting PdfDocument file to work along with new Document class.
And now i got:
QuoteError: Class 'Joomla\CMS\Document\TCPDF' not found: Class 'Joomla\CMS\Document\TCPDF' not found
Where it could be - what I cannot find?
Regards!
EDIT:
Backslash repaired this issue:
$this->_engine = new \TCPDF();
It works now  - my PdfDocument.php file - with Document class!  8) :D
Title: Re: Re: How Joomla 3.8 generates PDF now? Lack of pdf.php, new libraries structure
Post by: Studio 42 on April 07, 2018, 22:09:35 PM
Can you send the code? perhaps i update github, so you are not restricted to only one  PDF renderer Class.
Title: Re: How Joomla 3.8 generates PDF now? Lack of pdf.php, new libraries structure
Post by: Adwans on April 07, 2018, 22:59:42 PM
Of course, here you are. My Unicode dejavusans font is added, I commented some points useless for me. You can make it refined or better coded. Regards :)

<?php

namespace Joomla\CMS\Document;

defined('JPATH_PLATFORM') or die;

use 
Joomla\Filesystem\File// phoca
use Joomla\CMS\Factory;



class 
PdfDocument extends Document
{

public $_charset  'utf-8';
public $_mime  'application/pdf';
public $_type  'pdf';

 //
public $_engine null;

protected $_name 'joomla';

public $_header null;
public $_header_font 'dejavusans';
public $_footer_font 'dejavusans';

public $_margin_header 5;
public $_margin_footer 10;
public $_margin_top 27;
public $_margin_bottom 25;
public $_margin_left 15;
public $_margin_right 15;

// Scale ratio for images [number of points in user unit]
public $_image_scale 4;

/**
 * Class constructore
 *
 * @access protected
 * @param array $options Associative array of options
 */
function __construct($options = array())
{
parent::__construct($options);


if(!file_exists(JPATH_LIBRARIES.'/tcpdf/tcpdf.php')){
\JError::raiseError(500\JText::sprintf('JLIB_APPLICATION_ERROR_APPLICATION_LOAD','TCPDF'));
} else {
if(!class_exists('TCPDF')) \JLoader::register('TCPDF'JPATH_LIBRARIES '/tcpdf/tcpdf.php');
}

/**** 7 4 wyłączam

if (isset($options['margin-header'])) { $this->_margin_header = $options['margin-header']; }

if (isset($options['margin-footer'])) { $this->_margin_footer = $options['margin-footer']; }

if (isset($options['margin-top'])) { $this->_margin_top = $options['margin-top']; }

if (isset($options['margin-bottom'])) { $this->_margin_bottom = $options['margin-bottom']; }

if (isset($options['margin-left'])) { $this->_margin_left = $options['margin-left']; }

if (isset($options['margin-right'])) { $this->_margin_right = $options['margin-right']; }

if (isset($options['image-scale'])) { $this->_image_scale = $options['image-scale']; }
7 4 ****/


$this->_mime 'application/pdf';
$this->_type 'pdf';


/*
 * Create the pdf document
 */
// Default settings are a portrait layout with an A4 configuration using millimeters as units


if(class_exists('TCPDF'))
        {

    
}else {
throw new Exception('Juz zaladowany tcpdf'500);
return false;
}
 
$this->_engine = new \TCPDF();

//set margins
$this->_engine->SetMargins($this->_margin_left$this->_margin_top$this->_margin_right);
//set auto page breaks
$this->_engine->SetAutoPageBreak(TRUE$this->_margin_bottom);
$this->_engine->SetHeaderMargin($this->_margin_header);
$this->_engine->SetFooterMargin($this->_margin_footer);
$this->_engine->setImageScale($this->_image_scale);



}

 /**
 * Sets the document name
 *
 * @param   string   $name Document name
 * @access  public
 * @return  void
 */
function setName($name 'joomla') {
$this->_name $name;
}

/**
 * Returns the document name
 *
 * @access public
 * @return string
 */
function getName() {
return $this->_name;
}

 /**
 * Sets the document header string
 *
 * @param   string   $text Document header string
 * @access  public
 * @return  void
 */
function setHeader($text) {
$this->_header $text;
}

/**
 * Returns the document header string
 *
 * @access public
 * @return string
 */
function getHeader() {
return $this->_header;
}

/**
 * Render the document.
 *
 * @access public
 * @param boolean  $cache If true, cache the output
 * @param array $params Associative array of attributes
 * @return  The rendered data
 */
   
function render$cache false$params = array())
{

if(class_exists('TCPDF'))
        {   
}else {
throw new Exception('Brak zaladowanego tcpdf'500);
return false;
}
#end


$pdf = &$this->_engine


// Set PDF Metadata
$pdf->SetCreator($this->getGenerator());
$pdf->SetTitle($this->getTitle());
$pdf->SetSubject($this->getDescription());
//$pdf->SetKeywords($this->getMetaData('keywords')); 7 4

// Set PDF Header data
$pdf->setHeaderData('',0,$this->getTitle(), $this->getHeader());

// Set PDF Header and Footer fonts
$lang \JFactory::getLanguage();

$pdf->setRTL($lang->isRTL());
                
//$pdf->SetFont('helvetica', '', 8, '', 'false');
$pdf->SetFont('dejavusans'''8'''false');

$pdf->setHeaderFont(array($this->_header_font''10));
$pdf->setFooterFont(array($this->_footer_font''8));



// Initialize PDF Document
//debug 7 4 
$pdf->getAliasNbPages();
$pdf->AddPage();

// Build the PDF Document string from the document buffer
// niepotrzebne:
//$this->fixLinks();
$pdf->WriteHTML($this->getBuffer(), true);
$data $pdf->Output('''S');
// Set document type headers
parent::render();

//JResponse::setHeader('Content-Length', strlen($data), true); komentarz był
//\JResponse::setHeader('Content-type', 'application/pdf', true);
//\JResponse::setHeader('Content-disposition', 'inline; filename="'.$this->getName().'.pdf"', true);
#zibi
# deprecated  1.5 Use JApplicationWeb instead
# phoca uzywa:
\JFactory::getApplication()->setHeader('Content-type''application/pdf'true);// cache
\JFactory::getApplication()->setHeader('Content-disposition''inline; filename="'.$this->getName().'.pdf"'true);

//Close and output PDF document
return $data;
}

}

Title: Re: How Joomla 3.8 generates PDF now? Lack of pdf.php, new libraries structure
Post by: Robert_ITMan on September 26, 2019, 21:49:13 PM
With recent upgrades (now on Joomla 3.9.11 and VM 3.6.2) I found I needed to update all my code that directly uses tcpdf as it was moved
from /libraries/tcpdf
to /libraries/vendor/tecnickcom/tcpdf

Notice also /config/lang is no longer included - not required anymore, I commented out the require_once to the /config/lang/eng.php and my PDFs continue to work fine again, mind you I'm not using multiple languages presently. My code:
//load the pdf creator as already installed in libraries
ob_start(); // clear the php buffer needed to stop warning for 'headers already sent'
//require_once( JPATH_BASE . '/libraries/vendor/tecnickcom/tcpdf/config/lang/eng.php' );
require_once( JPATH_BASE . '/libraries/vendor/tecnickcom/tcpdf/tcpdf.php' );