8000 Support custom settings by simonhamp · Pull Request #229 · NativePHP/electron · GitHub
[go: up one dir, main page]

Skip to content

Support custom settings #229

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jul 9, 2025
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
Support custom settings
  • Loading branch information
simonhamp committed Jun 25, 2025
commit 301aa11b2e5aeda4e7291300b830abceebc90b84
21 changes: 14 additions & 7 deletions resources/js/electron-plugin/src/server/api/system.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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'),
Expand Down
Loading
0