diff --git a/resources/js/electron-plugin/dist/server/api/system.js b/resources/js/electron-plugin/dist/server/api/system.js index 6cb9594a..73042e27 100644 --- a/resources/js/electron-plugin/dist/server/api/system.js +++ b/resources/js/electron-plugin/dist/server/api/system.js @@ -62,15 +62,17 @@ router.get('/printers', (req, res) => __awaiter(void 0, void 0, void 0, function }); })); router.post('/print', (req, res) => __awaiter(void 0, void 0, void 0, function* () { - const { printer, html } = req.body; + const { printer, html, settings } = req.body; let printWindow = new BrowserWindow({ show: false, }); + const defaultSettings = { + silent: true, + deviceName: printer, + }; + const mergedSettings = Object.assign(Object.assign({}, defaultSettings), (settings && typeof settings === 'object' ? settings : {})); printWindow.webContents.on('did-finish-load', () => { - printWindow.webContents.print({ - silent: true, - deviceName: printer, - }, (success, errorType) => { + printWindow.webContents.print(mergedSettings, (success, errorType) => { if (success) { console.log('Print job completed successfully.'); res.sendStatus(200); @@ -88,12 +90,12 @@ router.post('/print', (req, res) => __awaiter(void 0, void 0, void 0, function* yield printWindow.loadURL(`data:text/html;charset=UTF-8,${html}`); })); router.post('/print-to-pdf', (req, res) => __awaiter(void 0, void 0, void 0, function* () { - const { html } = req.body; + const { html, settings } = req.body; let printWindow = new BrowserWindow({ show: false, }); printWindow.webContents.on('did-finish-load', () => { - printWindow.webContents.printToPDF({}).then(data => { + printWindow.webContents.printToPDF(settings !== null && settings !== void 0 ? settings : {}).then(data => { printWindow.close(); res.json({ result: data.toString('base64'), diff --git a/resources/js/electron-plugin/src/server/api/system.ts b/resources/js/electron-plugin/src/server/api/system.ts index 8c6fa213..4c74e0a0 100644 --- a/resources/js/electron-plugin/src/server/api/system.ts +++ b/resources/js/electron-plugin/src/server/api/system.ts @@ -60,17 +60,24 @@ router.get('/printers', async (req, res) => { }); router.post('/print', async (req, res) => { - const {printer, html} = req.body; + const {printer, html, settings} = req.body; let printWindow = new BrowserWindow({ show: false, }); + const defaultSettings = { + silent: true, + deviceName: printer, + }; + + const mergedSettings = { + ...defaultSettings, + ...(settings && typeof settings === 'object' ? settings : {}), + }; + printWindow.webContents.on('did-finish-load', () => { - printWindow.webContents.print({ - silent: true, - deviceName: printer, - }, (success, errorType) => { + printWindow.webContents.print(mergedSettings, (success, errorType) => { if (success) { console.log('Print job completed successfully.'); res.sendStatus(200); @@ -89,14 +96,14 @@ router.post('/print', async (req, res) => { }); router.post('/print-to-pdf', async (req, res) => { - const {html} = req.body; + const {html, settings} = req.body; let printWindow = new BrowserWindow({ show: false, }); printWindow.webContents.on('did-finish-load', () => { - printWindow.webContents.printToPDF({}).then(data => { + printWindow.webContents.printToPDF(settings ?? {}).then(data => { printWindow.close(); res.json({ result: data.toString('base64'),