mirror of
https://github.com/BoostIo/Boostnote
synced 2025-12-13 17:56:25 +00:00
Generate PDF through an Electron BrowserWindow
This commit is contained in:
@@ -23,7 +23,7 @@ import i18n from 'browser/lib/i18n'
|
|||||||
import fs from 'fs'
|
import fs from 'fs'
|
||||||
import ConfigManager from '../main/lib/ConfigManager'
|
import ConfigManager from '../main/lib/ConfigManager'
|
||||||
|
|
||||||
const { remote, shell, BrowserWindow } = require('electron')
|
const { remote, shell } = require('electron')
|
||||||
const attachmentManagement = require('../main/lib/dataApi/attachmentManagement')
|
const attachmentManagement = require('../main/lib/dataApi/attachmentManagement')
|
||||||
|
|
||||||
const { app } = remote
|
const { app } = remote
|
||||||
@@ -349,16 +349,21 @@ export default class MarkdownPreview extends React.Component {
|
|||||||
}
|
}
|
||||||
|
|
||||||
handleSaveAsHtml () {
|
handleSaveAsHtml () {
|
||||||
this.exportAsDocument('html', (noteContent, exportTasks) => this.htmlContentFormatter(noteContent, exportTasks))
|
this.exportAsDocument('html', (noteContent, exportTasks) => Promise.resolve(this.htmlContentFormatter(noteContent, exportTasks)))
|
||||||
}
|
}
|
||||||
|
|
||||||
handleSaveAsPdf () {
|
handleSaveAsPdf () {
|
||||||
this.exportAsDocument('pdf', (noteContent, exportTasks) => {
|
this.exportAsDocument('pdf', (noteContent, exportTasks) => {
|
||||||
// Return pdf source
|
const printout = new remote.BrowserWindow({show: false})
|
||||||
// const doc = new jsPDF()
|
printout.loadURL('data:text/html;charset=UTF-8,'+this.htmlContentFormatter(noteContent, exportTasks))
|
||||||
// doc.fromHTML(this.markdown.render(noteContent), 0, 0)
|
return new Promise((resolve, reject) => {
|
||||||
// return doc.output()
|
printout.webContents.on('did-finish-load', () => {
|
||||||
|
printout.webContents.printToPDF({}, (err, data) => {
|
||||||
|
if (err) reject(err)
|
||||||
|
else resolve(data)
|
||||||
|
})
|
||||||
|
})
|
||||||
|
})
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user