@@ -62,15 +62,17 @@ router.get('/printers', (req, res) => __awaiter(void 0, void 0, void 0, function
62
62
} ) ;
63
63
} ) ) ;
64
64
router . post ( '/print' , ( req , res ) => __awaiter ( void 0 , void 0 , void 0 , function * ( ) {
65
- const { printer, html } = req . body ;
65
+ const { printer, html, settings } = req . body ;
66
66
let printWindow = new BrowserWindow ( {
67
67
show : false ,
68
68
} ) ;
69
+ const defaultSettings = {
70
+ silent : true ,
71
+ deviceName : printer ,
72
+ } ;
73
+ const mergedSettings = Object . assign ( Object . assign ( { } , defaultSettings ) , ( settings && typeof settings === 'object' ? settings : { } ) ) ;
69
74
printWindow . webContents . on ( 'did-finish-load' , ( ) => {
70
- printWindow . webContents . print ( {
71
- silent : true ,
72
- deviceName : printer ,
73
- } , ( success , errorType ) => {
75
+ printWindow . webContents . print ( mergedSettings , ( success , errorType ) => {
74
76
if ( success ) {
75
77
console . log ( 'Print job completed successfully.' ) ;
76
78
res . sendStatus ( 200 ) ;
@@ -88,12 +90,12 @@ router.post('/print', (req, res) => __awaiter(void 0, void 0, void 0, function*
88
90
yield printWindow . loadURL ( `data:text/html;charset=UTF-8,${ html } ` ) ;
89
91
} ) ) ;
90
92
router . post ( '/print-to-pdf' , ( req , res ) => __awaiter ( void 0 , void 0 , void 0 , function * ( ) {
91
- const { html } = req . body ;
93
+ const { html, settings } = req . body ;
92
94
let printWindow = new BrowserWindow ( {
93
95
show : false ,
94
96
} ) ;
95
97
printWindow . webContents . on ( 'did-finish-load' , ( ) => {
96
- printWindow . webContents . printToPDF ( { } ) . then ( data => {
98
+ printWindow . webContents . printToPDF ( settings !== null && settings !== void 0 ? settings : { } ) . then ( data => {
97
99
printWindow . close ( ) ;
98
100
res . json ( {
99
101
result : data . toString ( 'base64' ) ,
0 commit comments