You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Printer spec seems to support raster, but it doesnt work. Any pointers?
`<?php
require_once 'modules/POS/libraries/vendor/autoload.php';
use Mike42\Escpos\PrintConnectors\NetworkPrintConnector;
use Mike42\Escpos\Printer;
use Mike42\Escpos\EscposImage;
class POS_GenerateInvoicePDF_View extends Vtiger_Index_View {
public function process(App\Request $request)
{
$filePath = $this->generatePDFFile($request);
$currentUser = Users_Record_Model::getCurrentUserModel();
$printer_ip = $currentUser->kitchen_printer;
if (empty($printer_ip)) {
echo json_encode(["print_status" => false, "message" => "Please finish your printer configuration first."]);
die;
}
$position = strpos($printer_ip, ":");
$printerIP = trim(substr($printer_ip, 0, $position));
$printerPort = trim(substr($printer_ip, $position + 1));
try {
// Create a network connector to the printer
$connector = new NetworkPrintConnector($printerIP, $printerPort);
// Create a new Printer object
$printer = new Printer($connector);
// Convert PDF to PNG using Imagick
$imagick = new Imagick();
$imagick->setResolution(203, 203); // Set resolution suitable for receipt printers
$imagick->readImage($filePath);
$imagick->setImageFormat('png');
// Trim and resize the image to fit within the printer width (576 pixels)
$imagick->trimImage(0);
$imagick->resizeImage(576, 0, Imagick::FILTER_LANCZOS, 1);
// Save the processed image to a temporary file
$pngFilePath = 'storage/invoice.png';
$imagick->writeImage($pngFilePath);
$imagick->clear();
$imagick->destroy();
// Load the PNG image using EscposImage
$image = EscposImage::load($pngFilePath);
// Print the image using bitImage
$printer->raster($image, Printer::IMG_DEFAULT);
$printer->cut();
$printer->close();
} catch (Exception $e) {
echo json_encode(["print_status" => false, "message" => $e->getMessage()]);
die;
}
echo json_encode(["print_status" => true]);
die;
}
/** Align with PDF template ID */
public function getTemplateId($templates)
{
$template_id = "38";
foreach ($templates as $key => $template) {
$template_id = $template->has('pdfid') ? $template->get('pdfid') : "";
}
return $template_id;
}
/**
* Generate PDF File
*/
public function generatePDFFile($request)
{
$pdfModuleName = 'FInvoice';
$recordId = $request->isEmpty('record', true) ? null : $request->getInteger('record');
if (empty($recordId)) {
return false;
}
$handlerClass = Vtiger_Loader::getComponentClassName('Model', 'PDF', $pdfModuleName);
$pdfModel = new $handlerClass();
$templates = $pdfModel->getActiveTemplatesForRecord($recordId, 'Detail', $pdfModuleName);
$template_id = $this->getTemplateId($templates);
$eventHandler = new App\EventHandler();
$eventHandler->setModuleName($pdfModuleName);
$eventHandler->setParams([
'records' => $recordId,
'templates' => $template_id,
'viewInstance' => $this,
'pdfModel' => $pdfModel,
]);
$eventHandler->trigger('PdfGenerateInit');
$recordId = $eventHandler->getParam('records');
$pdfFiles = [];
$pdf = \App\Pdf\Pdf::getInstanceByTemplateId($template_id);
$template = $pdf->getTemplate();
$filePath = 'storage/invoice.pdf';
$template->setVariable('recordId', $recordId);
$pdf->loadTemplateData();
$eventHandler->addParams('pdf', $pdf);
$eventHandler->trigger('PdfGenerate');
$pdf->output($filePath, 'S');
return $filePath;
}
}
?>
`
The text was updated successfully, but these errors were encountered:
Printer spec seems to support raster, but it doesnt work. Any pointers?
`<?php
require_once 'modules/POS/libraries/vendor/autoload.php';
use Mike42\Escpos\PrintConnectors\NetworkPrintConnector;
use Mike42\Escpos\Printer;
use Mike42\Escpos\EscposImage;
class POS_GenerateInvoicePDF_View extends Vtiger_Index_View {
}
?>
`
The text was updated successfully, but these errors were encountered: