All Projects → staempfli → magento2-module-pdf

staempfli / magento2-module-pdf

Licence: other
Magento 2 Module for creating PDF's based on wkhtmltopdf

Programming Languages

PHP
23972 projects - #3 most used programming language

Projects that are alternatives of or similar to magento2-module-pdf

enhanced-privacy
Magento 2 Enhanced Privacy extension for easier compliance with GDPR. Allows customers to delete, anonymize, or export their personal data.
Stars: ✭ 45 (-18.18%)
Mutual labels:  magento2, magento2-extension
magento2-link-product
Custom Product Relation for Magento 2.2.x and 2.3.x sample extension
Stars: ✭ 45 (-18.18%)
Mutual labels:  magento2, magento2-extension
module-translation
magefan.com/magento-2-translation-extension
Stars: ✭ 35 (-36.36%)
Mutual labels:  magento2, magento2-extension
magento2-prometheus-exporter
Simple Magento 2 Prometheus Exporter.
Stars: ✭ 40 (-27.27%)
Mutual labels:  magento2, magento2-extension
PagSeguro-Magento-Transparente-M2
Módulo PagSeguro para Magento 2
Stars: ✭ 15 (-72.73%)
Mutual labels:  magento2, magento2-extension
magento-ngrok
Magento 2 module for ngrok.io service support
Stars: ✭ 45 (-18.18%)
Mutual labels:  magento2, magento2-extension
module-lazyload
magefan.com/magento-2-image-lazy-load-extension
Stars: ✭ 47 (-14.55%)
Mutual labels:  magento2, magento2-extension
magento2-image-optimizer
This Magento 2 module is a wrapper based on the package https://github.com/spatie/image-optimizer
Stars: ✭ 39 (-29.09%)
Mutual labels:  magento2, magento2-extension
magento2-sample-imageuploader
A Magento 2 sample module demonstrating how to upload an image file within a grid and form UI Component.
Stars: ✭ 27 (-50.91%)
Mutual labels:  magento2, magento2-extension
magento2
Mollie Payments for Magento 2
Stars: ✭ 70 (+27.27%)
Mutual labels:  magento2, magento2-extension
magento2-alsoviewed
Magento2 product suggestion module, based on customers activities
Stars: ✭ 25 (-54.55%)
Mutual labels:  magento2, magento2-extension
magento2-catalog-lazy-load
Improve the load time of your Magento 2 categories pages by loading your images on demand with our Lazy Load Extension
Stars: ✭ 56 (+1.82%)
Mutual labels:  magento2, magento2-extension
wkhtmltopdf-flask-aas
Wkhtmltopdf Flask As a Service
Stars: ✭ 17 (-69.09%)
Mutual labels:  wkhtmltopdf, pdf-generation
magento-2-ajax-cart
Magento 2 Ajax Cart allows customers to add products to cart right on the current window without having to redirect to another page. Completely reduce redirect wait times and improve the shopping experience.
Stars: ✭ 16 (-70.91%)
Mutual labels:  magento2, magento2-extension
magento-2-security
Magento 2 Security extension FREE. Security extension gives store owners the ability to detect the IP addresses that are intentionally attacking their store at any given time. Therefore, they have timely measures to prevent this issue such as blocking those IP addresses or sending warning emails to store owners.
Stars: ✭ 40 (-27.27%)
Mutual labels:  magento2, magento2-extension
Dev-Tools-Magento-2-Module
A collection of utilities meant to improve the experience of developing modules for Magento without breaking existing functionality.
Stars: ✭ 18 (-67.27%)
Mutual labels:  magento2, magento2-extension
module-geoip
Detect Country by IP in Magento 2
Stars: ✭ 51 (-7.27%)
Mutual labels:  magento2, magento2-extension
magento2-extrafee
This module is used to add extra fee to order. Show added extrafee in order, invoice and creditmemo.
Stars: ✭ 41 (-25.45%)
Mutual labels:  magento2, magento2-extension
magento2-module-cron-schedule
A Magento2 visual cronjob overview for magento2 backend
Stars: ✭ 35 (-36.36%)
Mutual labels:  magento2, magento2-extension
module-config-override
A Magento 2 module that overrides default configuration from file which can be added to version control.
Stars: ✭ 23 (-58.18%)
Mutual labels:  magento2, magento2-extension

Magento 2 PDF generator

Project Status: Abandoned – Initial development has started, but there has not yet been a stable, usable release; the project has been abandoned and the author(s) do not intend on continuing development.

Magento 2 module to ease the pdf generation using wkhtmltopdf features

Installation

composer require "staempfli/magento2-module-pdf":"~1.0"

Setup

Install wkhtmltopdf

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.

Module configuration

Stores > Configuration > Advanced PDF Generation

Admin Configuration

Usage

This module can generate a PDF from any frontControllerAction

  1. 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>
    
  2. 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;
    	}
    }
    

Header and Footer

Header and footer html can be added as follows:

  1. Create your header.html and footer.html files inside your Module template dir

    <!doctype html>
    <!-- app/code/Vendor/Package/view/frontend/templates/pdf/header.html -->
    <html>
    	<body>
    		Header text
        	</body>
    </html>
    
    <!doctype html>
    <!-- app/code/Vendor/Package/view/frontend/templates/pdf/footer.html -->
    <html>
    		<body>
    		Footer text
    		</body>
    </html>
    
  2. Attach those files to the Controller pdf generation

    <?php
    namespace Vendor\Package\Controller\Actions;
    
    use Magento\Framework\App\Action\Action;
    use Magento\Framework\View\Element\Template\File\Resolver as TemplateResolver;
    use Staempfli\Pdf\Model\View\PdfResult;
    use Staempfli\Pdf\Service\PdfOptions;
    
    class GeneratePdf extends Action
    {
        /**
     	     * @var TemplateResolver
    	     */
    	    private $templateResolver;
    
    	    public function __construct(
        	TemplateResolver $templateResolver,
        	Context $context
    	    ) {
       	        parent::__construct($context);
    	$this->templateResolver = $templateResolver;
    	    }
    
            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,
             	       PdfOptions::KEY_PAGE_HEADER_SPACING => "10",
             	   ]
            	)
        	);
        	$result->addPageOptions(
          	  new PdfOptions(
             	   [
             	       PdfOptions::KEY_PAGE_COOKIES => ${'_COOKIE'},
             	       PdfOptions::KEY_PAGE_HEADER_HTML_URL => $this->templateResolver
                        ->getTemplateFileName('Vendor_Package::pdf/header.html'),
                    PdfOptions::KEY_PAGE_FOOTER_HTML_URL => $this->templateResolver
                        ->getTemplateFileName('Vendor_ Package::pdf/footer.html'),
             	   ]
            	)
        	);
        	return $result;
    	    }
    }
    

NOTE: Only the header or only the footer as html is not possible, either both or none. Otherwise top and bottom margins are ignored.

Troubleshooting

The switch --print-media, is not support using unpatched qt:

Tiny or very small output on Mac:

Requirements

  • PHP >= 7.0.*
  • Magento >= 2.1.*

Support

If you have any issues with this extension, open an issue on GitHub.

Contribution

Any contribution is highly appreciated. The best way to contribute code is to open a pull request on GitHub.

Developer

Staempfli Webteam, Fabian Schmengler, integer_net and all other contributors

License

Open Software License ("OSL") v. 3.0

Copyright

(c) 2018, Stämpfli AG

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].