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:
parent
dd5799eac2
commit
9764246207
5 changed files with 49 additions and 0 deletions
|
@ -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();
|
Loading…
Add table
Add a link
Reference in a new issue