Built-In-Output-QRFpdf.md.txt 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. # QRFpdf
  2. [Class `QRFpdf`](https://github.com/chillerlan/php-qrcode/blob/main/src/Output/QRFpdf.php): [Portable Document Format](https://en.wikipedia.org/wiki/PDF) (PDF) output via [FPDF](https://github.com/setasign/fpdf)
  3. ## Example
  4. See: [FPDF example](https://github.com/chillerlan/php-qrcode/blob/main/examples/fpdf.php)
  5. Set the options:
  6. ```php
  7. $options = new QROptions;
  8. $options->outputType = QROutputInterface::FPDF;
  9. $options->scale = 5;
  10. $options->fpdfMeasureUnit = 'mm'; // pt, mm, cm, in
  11. $options->bgColor = [222, 222, 222]; // [R, G, B]
  12. $options->drawLightModules = false;
  13. $options->moduleValues = [
  14. QRMatrix::M_FINDER_DARK => [0, 63, 255], // dark (true)
  15. QRMatrix::M_FINDER_DOT => [0, 63, 255], // finder dot, dark (true)
  16. QRMatrix::M_FINDER => [255, 255, 255], // light (false)
  17. QRMatrix::M_ALIGNMENT_DARK => [255, 0, 255],
  18. QRMatrix::M_ALIGNMENT => [255, 255, 255],
  19. QRMatrix::M_DATA_DARK => [0, 0, 0],
  20. QRMatrix::M_DATA => [255, 255, 255],
  21. ];
  22. ```
  23. Render the output:
  24. ```php
  25. $data = 'https://www.youtube.com/watch?v=dQw4w9WgXcQ';
  26. $out = (new QRCode($options))->render($data); // -> data:application/pdf;base64,...
  27. echo $out;
  28. ```
  29. Return the `FPDF` instance (will ignore other output options):
  30. ```php
  31. $options->returnResource = true;
  32. /** @var \FPDF $fpdf */
  33. $fpdf = (new QRCode($options))->render($data);
  34. // do stuff with the FPDF instance...
  35. // ...dump output
  36. header('application/pdf');
  37. echo $fpdf->Output('S');
  38. ```
  39. ## Additional methods
  40. | method | return | description |
  41. |---------------------------------------------------|--------|------------------------------|
  42. | (protected) `initFPDF()` | `FPDF` | Initializes an FPDF instance |
  43. | (protected) `module(int $x, int $y, int $M_TYPE)` | `void` | Renders a single module |
  44. ## Options that affect this module
  45. | property | type |
  46. |---------------------|----------|
  47. | `$bgColor` | `array` |
  48. | `$drawLightModules` | `bool` |
  49. | `$fpdfMeasureUnit` | `string` |
  50. | `$outputBase64` | `bool` |
  51. | `$returnResource` | `bool` |
  52. | `$scale` | `ìnt` |
  53. ### Options that have no effect
  54. | property | reason |
  55. |------------------------|--------|
  56. | `$circleRadius` | N/A |
  57. | `$connectPaths` | N/A |
  58. | `$drawCircularModules` | N/A |
  59. | `$excludeFromConnect` | N/A |
  60. | `$imageTransparent` | N/A |
  61. | `$keepAsSquare` | N/A |