Git Product home page Git Product logo

qrcode's Introduction

mPDF is a PHP library which generates PDF files from UTF-8 encoded HTML.

It is based on FPDF and HTML2FPDF (see CREDITS), with a number of enhancements. mPDF was written by Ian Back and is released under the GNU GPL v2 licence.

Latest Stable Version Total Downloads License

⚠ If you are viewing this file on mPDF GitHub repository homepage or on Packagist, please note that the default repository branch is development which can differ from the last stable release.

Requirements

PHP versions and extensions

  • PHP >=5.6 <7.3.0 is supported for mPDF >= 7.0
  • PHP 7.3 is supported since mPDF v7.1.7
  • PHP 7.4 is supported since mPDF v8.0.4
  • PHP 8.0 is supported since mPDF v8.0.10
  • PHP 8.1 is supported as of mPDF v8.0.13
  • PHP 8.2 is supported as of mPDF v8.1.3
  • PHP 8.3 is supported as of mPDF v8.2.1

PHP mbstring and gd extensions have to be loaded.

Additional extensions may be required for some advanced features such as zlib for compression of output and embedded resources such as fonts, bcmath for generating barcodes or xml for character set conversion and SVG handling.

Known server caveats

mPDF has some problems with fetching external HTTP resources with single threaded servers such as php -S. A proper server such as nginx (php-fpm) or Apache is recommended.

Support us

Consider supporting development of mPDF with a donation of any value. Donation button can be found on the main page of the documentation.

Installation

Official installation method is via composer and its packagist package mpdf/mpdf.

$ composer require mpdf/mpdf

Usage

The simplest usage (since version 7.0) of the library would be as follows:

<?php

require_once __DIR__ . '/vendor/autoload.php';

$mpdf = new \Mpdf\Mpdf();
$mpdf->WriteHTML('<h1>Hello world!</h1>');
$mpdf->Output();

This will output the PDF inline to the browser as application/pdf Content-type.

Setup & Configuration

All configuration directives can be set by the $config parameter of the constructor.

It is recommended to set one's own temporary directory via tempDir configuration variable. The directory must have write permissions (mode 775 is recommended) for users using mPDF (typically cli, webserver, fpm).

Warning: mPDF will clean up old temporary files in the temporary directory. Choose a path dedicated to mPDF only.

<?php

$mpdf = new \Mpdf\Mpdf(['tempDir' => __DIR__ . '/tmp']);

By default, the temporary directory will be inside vendor directory and will have write permissions from post_install composer script.

For more information about custom temporary directory see the note on Folder for temporary files in the section on Installation & Setup in the manual.

If you have problems, please read the section on troubleshooting in the manual.

About CSS support and development state

mPDF as a whole is a quite dated software. Nowadays, better alternatives are available, albeit not written in PHP.

Use mPDF if you cannot use non-PHP approach to generate PDF files or if you want to leverage some of the benefits of mPDF over browser approach – color handling, pre-print, barcodes support, headers and footers, page numbering, TOCs, etc. But beware that a HTML/CSS template tailored for mPDF might be necessary.

If you are looking for state of the art CSS support, mirroring existing HTML pages to PDF, use headless Chrome.

mPDF will still be updated to enhance some internal capabilities and to support newer versions of PHP, but better and/or newer CSS support will most likely not be implemented.

Online manual

Online manual is available at https://mpdf.github.io/.

General troubleshooting

For general questions or troubleshooting please use Discussions.

You can also use the mpdf tag at Stack Overflow as the StackOverflow user base is more likely to answer you in a timely manner.

Contributing

Before submitting issues and pull requests please read the CONTRIBUTING.md file.

Unit Testing

Unit testing for mPDF is done using PHPUnit.

To get started, run composer install from the command line while in the mPDF root directory (you'll need composer installed first).

To execute tests, run composer test from the command line while in the mPDF root directory.

Any assistance writing unit tests for mPDF is greatly appreciated. If you'd like to help, please note that any PHP file located in the /tests/ directory will be autoloaded when unit testing.

qrcode's People

Contributors

finwe avatar fulldecent avatar kacercz avatar matthiaskuehneellerhold avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

qrcode's Issues

How to save to filename.png?

The example will not work

// Save black on white PNG image 100px wide to filename.png
$output->output($qrCode, 100, [255, 255, 255], [0, 0, 0], 'filename.png');

The position for filename is in reality for int $compression

QR Code stripping multiple consecutive spaces from the entered code

I found this bug

Attempting to create a QR code with the value ETEX14 0001 (where there are 6 consecutive spaces) - the extra spaces are getting stripped and the resulting code is ETEX14 0001 - I have searched for where this is happening and not been able to find it or find any work-around. I have checked that I am able to read a QR code with the spaces correctly encoded by using a different tool to generate the QR code so I am reasonably sure the code is being "minified" somewhere in mPDF and excess spaces stripped out. I have not been able to find any option or configuration change that will stop this happening despite searching for several hours and attempting many configuration changes. I apologize if this is a configuration issue and not a bug, but I have not been able to get this working.

This is mPDF and PHP version and environment (server/fpm/cli etc) I am using

Using mpdf/mpdf V8.0.10, mpdf/qrcode V1.2.0 running under PHP 7.4 on Apache V2.4.41

This is the PHP code snippet I use

<?php

    // Require composer autoload - create $mpdf object
    require_once $_SERVER['DOCUMENT_ROOT'].'/vendor/autoload.php';
    $mpdf = new \Mpdf\Mpdf([
        'format' => 'A4-P',
        'mode' => 'utf-8',
        'margin_left' => 0,
        'margin_right' => 0,
        'margin_top' => 0,
        'margin_bottom' => 0,
        'margin_header' => 0,
        'margin_footer' => 0,
        'nonPrintMargin' => 4
    ]);  //MPDF8

//Create HTML page in variable $html...(not shown)

$Location = 'EX14';
$BarcodeLocation = 'ET' . str_pad($Location, 10, " ", STR_PAD_RIGHT) . '0001';
$html .= "<barcode code=\"$BarcodeLocation\" type=\"QR\" class=\"barcode\" size=\"0.3\" error=\"M\" disableborder=\"1\" />\n";

//much later...
$mpdf->WriteHTML(trim($html),\Mpdf\HTMLParserMode::DEFAULT_MODE);
$mpdf->Output("Int_Doc_A4_Labels.pdf", "I");

This is the HTML/CSS code snippet I use

All is above...

Can't install

When I try to install this package, in Apache+PHP-FPM 7.4, I get the following error (BTW, I am using AWS SDK PHP inside my project):

Your requirements could not be resolved to an installable set of packages.

  Problem 1
    - Installation request for mpdf/qrcode ^1.1 -> satisfiable by mpdf/qrcode[v1.1.0].
    - Conclusion: remove paragonie/random_compat v9.99.100
    - Conclusion: don't install paragonie/random_compat v9.99.100
    - mpdf/qrcode v1.1.0 requires paragonie/random_compat ^1.4|^2.0|9.99.99 -> satisfiable by paragonie/random_compat[v1.4.0, v1.4.1, v1.4.2, v1.4.3, v2.0.0, v2.0.1, v2.0.10, v2.0.11, v2.0.12, v2.0.13, v2.0.14, v2.0.15, v2.0.16, v2.0.17, v2.0.18, v2.0.19, v2.0.2, v2.0.3, v2.0.4, v2.0.5, v2.0.6, v2.0.7, v2.0.8, v2.0.9, v9.99.99].
    - Can only install one of: paragonie/random_compat[v1.4.0, v9.99.100].
    - Can only install one of: paragonie/random_compat[v1.4.1, v9.99.100].
    - Can only install one of: paragonie/random_compat[v1.4.2, v9.99.100].
    - Can only install one of: paragonie/random_compat[v1.4.3, v9.99.100].
    - Can only install one of: paragonie/random_compat[v2.0.0, v9.99.100].
    - Can only install one of: paragonie/random_compat[v2.0.1, v9.99.100].
    - Can only install one of: paragonie/random_compat[v2.0.10, v9.99.100].
    - Can only install one of: paragonie/random_compat[v2.0.11, v9.99.100].
    - Can only install one of: paragonie/random_compat[v2.0.12, v9.99.100].
    - Can only install one of: paragonie/random_compat[v2.0.13, v9.99.100].
    - Can only install one of: paragonie/random_compat[v2.0.14, v9.99.100].
    - Can only install one of: paragonie/random_compat[v2.0.15, v9.99.100].
    - Can only install one of: paragonie/random_compat[v2.0.16, v9.99.100].
    - Can only install one of: paragonie/random_compat[v2.0.17, v9.99.100].
    - Can only install one of: paragonie/random_compat[v2.0.18, v9.99.100].
    - Can only install one of: paragonie/random_compat[v2.0.19, v9.99.100].
    - Can only install one of: paragonie/random_compat[v2.0.2, v9.99.100].
    - Can only install one of: paragonie/random_compat[v2.0.3, v9.99.100].
    - Can only install one of: paragonie/random_compat[v2.0.4, v9.99.100].
    - Can only install one of: paragonie/random_compat[v2.0.5, v9.99.100].
    - Can only install one of: paragonie/random_compat[v2.0.6, v9.99.100].
    - Can only install one of: paragonie/random_compat[v2.0.7, v9.99.100].
    - Can only install one of: paragonie/random_compat[v2.0.8, v9.99.100].
    - Can only install one of: paragonie/random_compat[v2.0.9, v9.99.100].
    - Can only install one of: paragonie/random_compat[v9.99.99, v9.99.100].
    - Installation request for paragonie/random_compat (locked at v9.99.100) -> satisfiable by paragonie/random_compat[v9.99.100].


Installation failed, reverting ./composer.json to its original content.

Incorrect usage example in README.md file

This project seems unmaintained so I am posting bug report instead of PR for those who want still to use this library.


Example usage shown in project README.md is incorrect. The last argument passed to output() is NOT target file name but image compression level. It can be omitted for default value (or you can pass whatever imagepng() allows). The output() method returns PNG image so if you want to save it to the file, proper code looks like this (I also made it less compact or readability):

<?php

use Mpdf\QrCode\QrCode;
use Mpdf\QrCode\Output;

$qrCode = new QrCode('Lorem ipsum sit dolor');
$output = new Output\Png();

// Save black on white PNG image 100px wide to filename.png
$qrWidth = 100;
$bgColor = [255, 255, 255];
$fgColor = [0, 0, 0];
$qrImg = $output->output($qrCode, $qrWidth, $bgColor, $fgColor);
file_put_contents('filename.png', $qrImg);

why when u generate qrcode xml tag utf-8

I found this bug

This is mPDF and PHP version and environment (server/fpm/cli etc) I am using

This is the PHP code snippet I use

<?php


This is the HTML/CSS code snippet I use


Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.