QRFpdf.md.txt 2.2 KB

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