I am using one custom php library in magento 2 to convert html to pdf. Here is the code that i am using.
<?php
namespace Company\Module\Controller\Adminhtml\Quote;
use Magento\Framework\App\Action\Action;
use Magento\Framework\App\Action\Context;
use Magento\Framework\App\Filesystem\DirectoryList as DirectoryList;
use Company\Module\Helper\PdfCrowd;
class QuotePdf extends Action
{
/**
* @var \Magento\Framework\App\Response\Http\FileFactory
*/
protected $fileFactory;
protected $_mediaDirectory;
protected $directory_list;
protected $dompdfFactory;
protected $layoutFactory;
protected $authSession;
//protected $quote_info;
protected $userFactory;
public function __construct(
Context $context,
\Magento\Framework\App\Response\Http\FileFactory $fileFactory,
\Magento\Framework\Filesystem $filesystem,
\Magento\Backend\Model\Auth\Session $authSession,
DirectoryList $directory_list,
\Magento\User\Model\UserFactory $userFactory
) {
parent::__construct($context);
$this->fileFactory = $fileFactory;
$this->authSession = $authSession;
$this->_mediaDirectory = $filesystem->getDirectoryWrite(DirectoryList::MEDIA);
$this->directory_list = $directory_list;
$this->userFactory = $userFactory;
}
public function execute()
{
if($this->authSession->isLoggedIn()){
$id = $this->getRequest()->getParam('id');
$client = new Pdfcrowd("MYUSERNAME", "xxxxxxx-KEY");
// set HTTP response headers
$pdf = $client->convertHtml($this->getHtmlForPdf($id));
header("Content-Type: application/pdf");
header("Cache-Control: no-cache");
header("Accept-Ranges: none");
header("Content-Disposition: attachment; filename=commercialsale-".$id.".pdf");
echo $pdf;
}
}
}
Here is my Helpler file
<?php
namespace Company\Module\Helper;
class PdfCrowd {
//
// Pdfcrowd constructor.
//
// $username - your username at Pdfcrowd
// $apikey - your API key
// $hostname - API hostname, defaults to pdfcrowd.com
//
function __construct($username, $apikey, $hostname=null){
if ($hostname)
$this->hostname = $hostname;
else
$this->hostname = self::$api_host;
$this->useSSL(false);
$this->fields = array(
'username' => $username,
'key' => $apikey,
'pdf_scaling_factor' => 1,
'html_zoom' => 200);
$this->proxy_name = null;
$this->proxy_port = null;
$this->proxy_username = "";
$this->proxy_password = "";
$this->user_agent = "pdfcrowd_php_client_".self::$client_version."_(http://pdfcrowd.com)";
}
}
?>
And here is the error that i am getting...
Fatal error: Uncaught Error: Class 'Company\Module\Helper\PdfCrowd' not found in /home/patios/public_html/app/code/Company/Module/Controller/Adminhtml/Quote/QuotePdf.php:49 Stack trace: #0 /home/patios/public_html/vendor/magento/framework/App/Action/Action.php(107): Company\Module\Controller\Adminhtml\Quote\QuotePdf->execute() #1 /home/patios/public_html/vendor/magento/framework/Interception/Interceptor.php(58): Magento\Framework\App\Action\Action->dispatch(Object(Magento\Framework\App\Request\Http)) 2 /home/patios/public_html/vendor/magento/framework/Interception/Interceptor.php(138): Company\Module\Controller\Adminhtml\Quote\QuotePdf\Interceptor->___callParent('dispatch', Array) 3 /home/patios/public_html/vendor/magento/framework/Interception/Interceptor.php(153): Company\Module\Controller\Adminhtml\Quote\QuotePdf\Interceptor->Magento\Framework\Interception{closure}(Object(Magento\Framework\App\Request\Http)) 4 /home/patios/public_html/generated/code/Company/Module/Controller/Adminhtml in /home/patios/public_html/app/code/Company/Module/Controller/Adminhtml/Quote/QuotePdf.php on line 49
Note: This code is working on my local but not on live server.