1
0
Fork 0
mirror of https://github.com/anyproto/anytype-ts.git synced 2025-06-08 05:57:02 +09:00

JS-832: print to PDF basic solution

This commit is contained in:
Mike Mhlv 2022-11-23 17:03:43 +00:00
parent dd5799eac2
commit 9764246207
5 changed files with 49 additions and 0 deletions

View file

@ -2,6 +2,7 @@ const { app, shell, nativeTheme } = require('electron');
const { is } = require('electron-util');
const log = require('electron-log');
const path = require('path');
const fs = require('fs');
const protocol = 'anytype';
const userPath = app.getPath('userData');
@ -171,6 +172,28 @@ class Util {
});
};
printPDF (win, exportPath, name) {
name = String(name || 'untitled').replace(/[^\w -\._]/gi, ' ').trim();
let options = {};
let pdfPath = path.join(exportPath, name + '.pdf');
win.webContents.printToPDF(options).then(data => {
fs.writeFile(pdfPath, data, (error) => {
if (error) throw error
shell.openPath(exportPath).catch(err => {
this.log('info', err);
});
this.send(win, 'command', 'saveAsHTMLSuccess');
});
}).catch(err => {
this.send(win, 'command', 'saveAsHTMLSuccess');
this.log('info', err);
});
}
};
module.exports = new Util();