Type
magento2-module
Staempfli PDF generator.
magento2-module
OSL-3.0
None
None
None
None
None
Magento 2 module to ease the pdf generation using wkhtmltopdf features
composer require "staempfli/magento2-module-pdf":"~1.0"
This module needs wkhtmltopdf installed on your computer. You can download and install it from here:
NOTE: Do not install it using apt-get
on Linux systems. See troubleshooting section for more info.
Stores > Configuration > Advanced PDF Generation
This module can generate a PDF from any frontControllerAction
Create you Controller path with the correspinding Blocks and .phtml
templates
<!-- route_actions_generatePdf.xml -->
<layout xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/layout_generic.xsd">
<container name="root">
<block class="Vendor\Package\Block\YourBlock" name="vendor.package.somename">
</container>
</layout>
Return pdf instance on Controller
<?php
namespace Vendor\Package\Controller\Actions;
use Magento\Framework\App\Action\Action;
use Staempfli\Pdf\Model\View\PdfResult;
use Staempfli\Pdf\Service\PdfOptions;
class GeneratePdf extends Action
{
public function execute()
{
return $this->renderPdfResult();
}
protected function renderPdfResult()
{
/** @var PdfResult $result */
$result = $this->resultFactory->create(PdfResult::TYPE);
$result->addGlobalOptions(
new PdfOptions(
[
PdfOptions::KEY_GLOBAL_TITLE => __('Return PDF'),
PdfOptions::KEY_PAGE_ENCODING => PdfOptions::ENCODING_UTF_8,
PdfOptions::KEY_GLOBAL_ORIENTATION => PdfOptions::ORIENTATION_PORTRAIT,
PdfOptions::FLAG_PAGE_PRINT_MEDIA_TYPE,
]
)
);
$result->addPageOptions(
new PdfOptions(
[
PdfOptions::KEY_PAGE_COOKIES => ${'_COOKIE'},
]
)
);
return $result;
}
}
wkhtmltopdf
should not be installed via apt-get. See:
wkhtmltopdf
version 0.12.4. It can be fixed by installing 0.12.3
If you have any issues with this extension, open an issue on GitHub.
Any contribution is highly appreciated. The best way to contribute code is to open a pull request on GitHub.
Staempfli Webteam, Fabian Schmengler, integer_net and all other contributors
Open Software License ("OSL") v. 3.0
(c) 2018, Stämpfli AG