Closed ellipee closed 8 years ago
Hi @ellipee, do you've added the configuration on the config/autoload?
Please take a look at: https://github.com/mvlabs/MvlabsSnappy#configuration
I recommend to install the module via composer. The module has dependencies, and manually could only work by installing the dependencies manually too.
I hope this helps to clarify.
Regards, Diego Drigani
Thank you @drigani for you quick response. i did install everything using composer and i copied the configuration on the config/autoload with the settings as follows.
<?php
return array(
'mvlabs-snappy' => array(
'pdf' => array(
'binary' => 'websites/ice/vendor/google/wkhtmltopdf-amd64/wkhtmltopdf-amd64',
'options' => array(),
),
'image' => array(
'binary' => '/usr/local/bin/wkhtmltoimage',
'options' => array(),
)
)
);
and inside my controller
public function generatepdfAction() { $entityManager = $this->getServiceLocator()->get('doctrine.entitymanager.orm_default');
$id = (int) $this->params()->fromRoute('id', 0);
// var_dump($id)
if (!$id) {
return $this->redirect()->toRoute('staff', array('controller'=>'staff','action' => 'view'));
}
$staff = $entityManager->getRepository('Admin\Entity\Staff')->findOneBy(array('id' => $id));
if (!$staff) {
return $this->redirect()->toRoute('staff', array('controller'=>'staff', 'action'=>'view'));
}
$viewRenderer = $this->serviceLocator->get('view_manager')->getRenderer();
$view = new ViewModel(array('staff'=>$staff));
$view->setTemplate('Admin/Staff/viewfull');
// path to phtml file under view folder
$view->setTerminal(true);
$htmlOutput = $viewRenderer->render($view);
$output = $this->serviceLocator->get('mvlabssnappy.pdf.service')->getOutputFromHtml($htmlOutput);
$response = $this->getResponse();
$headers = $response->getHeaders();
$headers->addHeaderLine('Content-Type', 'application/pdf');
$headers->addHeaderLine('Content-Disposition', "attachment; filename=\"export-" . $now->format('d-m-Y H:i:s') . ".pdf\"");
$response->setContent($output);
return $response;
}
i got this error
The file 'C:\Windows\TEMP\knp_snappy55a80b65a18d25.83605966.pdf' was not created (command: websites/ice/vendor/google/wkhtmltopdf-amd64/wkhtmltopdf-amd64 --lowquality "C:\Windows\TEMP\knp_snappy55a80b65a15be5.55916267.html" "C:\Windows\TEMP\knp_snappy55a80b65a18d25.83605966.pdf")
hi @ellipee, first of all make sure that running the command from terminal works. You can try in the command line:
websites/ice/vendor/google/wkhtmltopdf-amd64/wkhtmltopdf-amd64 --lowquality http://google.com google.pdf
Regards, Diego Drigani
hi @drigani I'm with the same issue, and for me, running the command from terminal, it works. I have tried to show direct to browser like in example and also get output and save to a file, but nothing worked.
please help me i install module via composer and it download fine. but when i activate the module in my application config, it displays this error.
Fatal error: Uncaught exception 'Zend\ModuleManager\Exception\RuntimeException' with message 'Module (MvlabsSnappy) could not be initialized.' in C:\websites\ice\vendor\zendframework\zend-modulemanager\src\ModuleManager.php on line 195
i did downloaded the module and put it in my module folder manually the errors stop. but when i want to generate pdf in my controller this error message appears
Fatal error: Class 'Knp\Snappy\Pdf' not found in C:\websites\ice\vendor\MvlabsSnappy\src\MvlabsSnappy\Services\MvlabsSnappyPdfServiceFactory.php on line 16
please help me