pdf417-code.php 2.6KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. <?php
  2. /* Demonstration of available options on the pdf417Code() command */
  3. require __DIR__ . '/../vendor/autoload.php';
  4. use Mike42\Escpos\Printer;
  5. use Mike42\Escpos\PrintConnectors\FilePrintConnector;
  6. $connector = new FilePrintConnector("php://stdout");
  7. $printer = new Printer($connector);
  8. // Most simple example
  9. title($printer, "PDF417 code demo\n");
  10. $testStr = "Testing 123";
  11. $printer -> pdf417Code($testStr);
  12. $printer -> text("Most simple example\n");
  13. $printer -> feed();
  14. // Demo that alignment is the same as text
  15. $printer -> setJustification(Printer::JUSTIFY_CENTER);
  16. $printer -> pdf417Code($testStr, 3, 3, 2);
  17. $printer -> text("Same content, narrow and centred\n");
  18. $printer -> setJustification();
  19. $printer -> feed();
  20. // Demo of error correction
  21. title($printer, "Error correction\n");
  22. $ec = array(0.1, 0.5, 1.0, 2.0, 4.0);
  23. foreach ($ec as $level) {
  24. $printer -> pdf417Code($testStr, 3, 3, 0, $level);
  25. $printer -> text("Error correction ratio $level\n");
  26. $printer -> feed();
  27. }
  28. // Change size
  29. title($printer, "Pixel size\n");
  30. $sizes = array(
  31. 2 => "(minimum)",
  32. 3 => "(default)",
  33. 4 => "",
  34. 8 => "(maximum)");
  35. foreach ($sizes as $size => $label) {
  36. $printer -> pdf417Code($testStr, $size);
  37. $printer -> text("Module width $size dots $label\n");
  38. $printer -> feed();
  39. }
  40. // Change height
  41. title($printer, "Height multiplier\n");
  42. $sizes = array(
  43. 2 => "(minimum)",
  44. 3 => "(default)",
  45. 4 => "",
  46. 8 => "(maximum)");
  47. foreach ($sizes as $size => $label) {
  48. $printer -> pdf417Code($testStr, 3, $size);
  49. $printer -> text("Height multiplier $size $label\n");
  50. $printer -> feed();
  51. }
  52. // Chage data column count
  53. title($printer, "Data column count\n");
  54. $columnCounts = array(
  55. 0 => "(auto, default)",
  56. 1 => "",
  57. 2 => "",
  58. 3 => "",
  59. 4 => "",
  60. 5 => "",
  61. 30 => "(maximum, doesnt fit!)");
  62. foreach ($columnCounts as $columnCount => $label) {
  63. $printer -> pdf417Code($testStr, 3, 3, $columnCount);
  64. $printer -> text("Column count $columnCount $label\n");
  65. $printer -> feed();
  66. }
  67. // Change options
  68. title($printer, "Options\n");
  69. $models = array(
  70. Printer::PDF417_STANDARD => "Standard",
  71. Printer::PDF417_TRUNCATED => "Truncated");
  72. foreach ($models as $model => $name) {
  73. $printer -> pdf417Code($testStr, 3, 3, 0, 0.10, $model);
  74. $printer -> text("$name\n");
  75. $printer -> feed();
  76. }
  77. // Cut & close
  78. $printer -> cut();
  79. $printer -> close();
  80. function title(Printer $printer, $str)
  81. {
  82. $printer -> selectPrintMode(Printer::MODE_DOUBLE_HEIGHT | Printer::MODE_DOUBLE_WIDTH);
  83. $printer -> text($str);
  84. $printer -> selectPrintMode();
  85. }