From 7c1cd50defdde200eeb8300fc7336ac47f77a6d0 Mon Sep 17 00:00:00 2001 From: Evan Miller Date: Mon, 3 Dec 2018 13:12:22 -0500 Subject: [PATCH 01/12] Add structure for exporting PDFs --- browser/components/MarkdownPreview.js | 9 +++++++++ browser/main/Detail/InfoPanel.js | 8 +++++++- browser/main/Detail/InfoPanelTrashed.js | 7 ++++--- browser/main/Detail/MarkdownNoteDetail.js | 6 ++++++ browser/main/NoteList/index.js | 1 + lib/main-menu.js | 7 +++++++ locales/da.json | 1 + locales/de.json | 1 + locales/en.json | 1 + locales/es-ES.json | 1 + locales/fa.json | 1 + locales/fr.json | 1 + locales/hu.json | 1 + locales/it.json | 1 + locales/ja.json | 1 + locales/ko.json | 1 + locales/no.json | 1 + locales/pl.json | 1 + locales/pt-BR.json | 1 + locales/pt-PT.json | 1 + locales/ru.json | 1 + locales/sq.json | 1 + locales/th.json | 1 + locales/tr.json | 1 + locales/zh-CN.json | 1 + locales/zh-TW.json | 1 + 26 files changed, 54 insertions(+), 4 deletions(-) diff --git a/browser/components/MarkdownPreview.js b/browser/components/MarkdownPreview.js index 17d2cb82..87d1d02a 100755 --- a/browser/components/MarkdownPreview.js +++ b/browser/components/MarkdownPreview.js @@ -205,6 +205,7 @@ export default class MarkdownPreview extends React.Component { this.saveAsTextHandler = () => this.handleSaveAsText() this.saveAsMdHandler = () => this.handleSaveAsMd() this.saveAsHtmlHandler = () => this.handleSaveAsHtml() + this.saveAsPdfHandler = () => this.handleSaveAsPdf() this.printHandler = () => this.handlePrint() this.linkClickHandler = this.handlelinkClick.bind(this) @@ -349,6 +350,12 @@ export default class MarkdownPreview extends React.Component { }) } + handleSaveAsPdf () { + this.exportAsDocument('pdf', (noteContent, exportTasks) => { + // Return pdf source + }) + } + handlePrint () { this.refs.root.contentWindow.print() } @@ -460,6 +467,7 @@ export default class MarkdownPreview extends React.Component { eventEmitter.on('export:save-text', this.saveAsTextHandler) eventEmitter.on('export:save-md', this.saveAsMdHandler) eventEmitter.on('export:save-html', this.saveAsHtmlHandler) + eventEmitter.on('export:save-pdf', this.saveAsPdfHandler) eventEmitter.on('print', this.printHandler) } @@ -495,6 +503,7 @@ export default class MarkdownPreview extends React.Component { eventEmitter.off('export:save-text', this.saveAsTextHandler) eventEmitter.off('export:save-md', this.saveAsMdHandler) eventEmitter.off('export:save-html', this.saveAsHtmlHandler) + eventEmitter.off('export:save-pdf', this.saveAsPdfHandler) eventEmitter.off('print', this.printHandler) } diff --git a/browser/main/Detail/InfoPanel.js b/browser/main/Detail/InfoPanel.js index 15535186..8fe0a855 100644 --- a/browser/main/Detail/InfoPanel.js +++ b/browser/main/Detail/InfoPanel.js @@ -14,7 +14,7 @@ class InfoPanel extends React.Component { render () { const { - storageName, folderName, noteLink, updatedAt, createdAt, exportAsMd, exportAsTxt, exportAsHtml, wordCount, letterCount, type, print + storageName, folderName, noteLink, updatedAt, createdAt, exportAsMd, exportAsTxt, exportAsHtml, exportAsPdf, wordCount, letterCount, type, print } = this.props return (
@@ -85,6 +85,11 @@ class InfoPanel extends React.Component {

{i18n.__('.html')}

+ + - @@ -61,7 +61,8 @@ InfoPanelTrashed.propTypes = { createdAt: PropTypes.string.isRequired, exportAsMd: PropTypes.func.isRequired, exportAsTxt: PropTypes.func.isRequired, - exportAsHtml: PropTypes.func.isRequired + exportAsHtml: PropTypes.func.isRequired, + exportAsPdf: PropTypes.func.isRequired } export default CSSModules(InfoPanelTrashed, styles) diff --git a/browser/main/Detail/MarkdownNoteDetail.js b/browser/main/Detail/MarkdownNoteDetail.js index b4e7a5b3..08d8bfbd 100755 --- a/browser/main/Detail/MarkdownNoteDetail.js +++ b/browser/main/Detail/MarkdownNoteDetail.js @@ -190,6 +190,10 @@ class MarkdownNoteDetail extends React.Component { ee.emit('export:save-html') } + exportAsPdf () { + ee.emit('export:save-pdf') + } + handleKeyDown (e) { switch (e.keyCode) { // tab key @@ -411,6 +415,7 @@ class MarkdownNoteDetail extends React.Component { exportAsHtml={this.exportAsHtml} exportAsMd={this.exportAsMd} exportAsTxt={this.exportAsTxt} + exportAsPdf={this.exportAsPdf} />
@@ -476,6 +481,7 @@ class MarkdownNoteDetail extends React.Component { exportAsMd={this.exportAsMd} exportAsTxt={this.exportAsTxt} exportAsHtml={this.exportAsHtml} + exportAsPdf={this.exportAsPdf} wordCount={note.content.split(' ').length} letterCount={note.content.replace(/\r?\n/g, '').length} type={note.type} diff --git a/browser/main/NoteList/index.js b/browser/main/NoteList/index.js index 31efaede..b5748fd4 100644 --- a/browser/main/NoteList/index.js +++ b/browser/main/NoteList/index.js @@ -500,6 +500,7 @@ class NoteList extends React.Component { 'export-txt': 'Text export', 'export-md': 'Markdown export', 'export-html': 'HTML export', + 'export-pdf': 'PDF export', 'print': 'Print' })[msg] diff --git a/lib/main-menu.js b/lib/main-menu.js index eb08273a..012c9ea3 100644 --- a/lib/main-menu.js +++ b/lib/main-menu.js @@ -116,6 +116,13 @@ const file = { mainWindow.webContents.send('list:isMarkdownNote', 'export-html') mainWindow.webContents.send('export:save-html') } + }, + { + label: 'PDF (.pdf)', + click () { + mainWindow.webContents.send('list:isMarkdownNote', 'export-pdf') + mainWindow.webContents.send('export:save-pdf') + } } ] }, diff --git a/locales/da.json b/locales/da.json index da5843f3..5d1a392b 100644 --- a/locales/da.json +++ b/locales/da.json @@ -18,6 +18,7 @@ ".md": ".md", ".txt": ".txt", ".html": ".html", + ".pdf": ".pdf", "Print": "Print", "Your preferences for Boostnote": "Your preferences for Boostnote", "Storage Locations": "Storage Locations", diff --git a/locales/de.json b/locales/de.json index 1b90ab63..9177adec 100644 --- a/locales/de.json +++ b/locales/de.json @@ -18,6 +18,7 @@ ".md": ".md", ".txt": ".txt", ".html": ".html", + ".pdf": ".pdf", "Print": "Drucken", "Your preferences for Boostnote": "Boostnote Einstellungen", "Storage Locations": "Speicherverwaltung", diff --git a/locales/en.json b/locales/en.json index fe7931da..831789c1 100644 --- a/locales/en.json +++ b/locales/en.json @@ -19,6 +19,7 @@ ".md": ".md", ".txt": ".txt", ".html": ".html", + ".pdf": ".pdf", "Print": "Print", "Your preferences for Boostnote": "Your preferences for Boostnote", "Help": "Help", diff --git a/locales/es-ES.json b/locales/es-ES.json index 8b2da1b7..3bd2cb49 100644 --- a/locales/es-ES.json +++ b/locales/es-ES.json @@ -18,6 +18,7 @@ ".md": ".md", ".txt": ".txt", ".html": ".html", + ".pdf": ".pdf", "Print": "Imprimir", "Your preferences for Boostnote": "Tus preferencias para Boostnote", "Storage Locations": "Almacenamientos", diff --git a/locales/fa.json b/locales/fa.json index 18bef679..8f702767 100644 --- a/locales/fa.json +++ b/locales/fa.json @@ -18,6 +18,7 @@ ".md": ".md", ".txt": ".txt", ".html": ".html", + ".pdf": ".pdf", "Print": "پرینت", "Your preferences for Boostnote": "تنظیمات شما برای boostnote", "Storage Locations": "ذخیره سازی", diff --git a/locales/fr.json b/locales/fr.json index ea5a1c05..35d2f3c8 100644 --- a/locales/fr.json +++ b/locales/fr.json @@ -18,6 +18,7 @@ ".md": ".md", ".txt": ".txt", ".html": ".html", + ".pdf": ".pdf", "Print": "Imprimer", "Your preferences for Boostnote": "Vos préférences pour Boostnote", "Storage Locations": "Stockages", diff --git a/locales/hu.json b/locales/hu.json index 77bdb2ab..e76f06c9 100644 --- a/locales/hu.json +++ b/locales/hu.json @@ -19,6 +19,7 @@ ".md": ".md", ".txt": ".txt", ".html": ".html", + ".pdf": ".pdf", "Print": "Nyomtatás", "Your preferences for Boostnote": "Boostnote beállításaid", "Help": "Súgó", diff --git a/locales/it.json b/locales/it.json index 05f454f3..69ddd380 100644 --- a/locales/it.json +++ b/locales/it.json @@ -18,6 +18,7 @@ ".md": ".md", ".txt": ".txt", ".html": ".html", + ".pdf": ".pdf", "Print": "Stampa", "Your preferences for Boostnote": "Le tue preferenze per Boostnote", "Storage Locations": "Posizioni", diff --git a/locales/ja.json b/locales/ja.json index e33bbaa6..b9618381 100644 --- a/locales/ja.json +++ b/locales/ja.json @@ -19,6 +19,7 @@ ".md": ".md", ".txt": ".txt", ".html": ".html", + ".pdf": ".pdf", "Print": "印刷", "Your preferences for Boostnote": "Boostnoteの個人設定", "Help": "ヘルプ", diff --git a/locales/ko.json b/locales/ko.json index 9a8bf8c7..59ffe7b9 100644 --- a/locales/ko.json +++ b/locales/ko.json @@ -18,6 +18,7 @@ ".md": ".md", ".txt": ".txt", ".html": ".html", + ".pdf": ".pdf", "Print": "인쇄", "Your preferences for Boostnote": "Boostnote 설정", "Storage Locations": "저장소", diff --git a/locales/no.json b/locales/no.json index 2d6c92f5..66109a34 100644 --- a/locales/no.json +++ b/locales/no.json @@ -18,6 +18,7 @@ ".md": ".md", ".txt": ".txt", ".html": ".html", + ".pdf": ".pdf", "Print": "Print", "Your preferences for Boostnote": "Your preferences for Boostnote", "Storage Locations": "Storage Locations", diff --git a/locales/pl.json b/locales/pl.json index 68719aef..577f46e6 100644 --- a/locales/pl.json +++ b/locales/pl.json @@ -19,6 +19,7 @@ ".md": ".md", ".txt": ".txt", ".html": ".html", + ".pdf": ".pdf", "Print": "Drukuj", "Help": "Pomoc", "Your preferences for Boostnote": "Twoje ustawienia dla Boostnote", diff --git a/locales/pt-BR.json b/locales/pt-BR.json index 6b3126cc..6072b023 100644 --- a/locales/pt-BR.json +++ b/locales/pt-BR.json @@ -18,6 +18,7 @@ ".md": ".md", ".txt": ".txt", ".html": ".html", + ".pdf": ".pdf", "Print": "Imprimir", "Your preferences for Boostnote": "Suas preferências para o Boostnote", "Storage Locations": "Armazenamentos", diff --git a/locales/pt-PT.json b/locales/pt-PT.json index 774919a2..5beb18dd 100644 --- a/locales/pt-PT.json +++ b/locales/pt-PT.json @@ -18,6 +18,7 @@ ".md": ".md", ".txt": ".txt", ".html": ".html", + ".pdf": ".pdf", "Print": "Imprimir", "Your preferences for Boostnote": "As tuas definiçōes para Boostnote", "Storage Locations": "Locais de Armazenamento", diff --git a/locales/ru.json b/locales/ru.json index 793e1511..c4e9e1a2 100644 --- a/locales/ru.json +++ b/locales/ru.json @@ -18,6 +18,7 @@ ".md": ".md", ".txt": ".txt", ".html": ".html", + ".pdf": ".pdf", "Print": "Print", "Your preferences for Boostnote": "Настройки Boostnote", "Storage Locations": "Хранилища", diff --git a/locales/sq.json b/locales/sq.json index e4cc01ac..80f737a3 100644 --- a/locales/sq.json +++ b/locales/sq.json @@ -18,6 +18,7 @@ ".md": ".md", ".txt": ".txt", ".html": ".html", + ".pdf": ".pdf", "Print": "Print", "Your preferences for Boostnote": "Your preferences for Boostnote", "Storage Locations": "Storage Locations", diff --git a/locales/th.json b/locales/th.json index 49d8e7cd..358d49ab 100644 --- a/locales/th.json +++ b/locales/th.json @@ -19,6 +19,7 @@ ".md": ".md", ".txt": ".txt", ".html": ".html", + ".pdf": ".pdf", "Print": "พิมพ์", "Your preferences for Boostnote": "การตั้งค่าของคุณสำหรับ Boostnote", "Help": "ช่วยเหลือ", diff --git a/locales/tr.json b/locales/tr.json index 03a9791d..077fa1e4 100644 --- a/locales/tr.json +++ b/locales/tr.json @@ -18,6 +18,7 @@ ".md": ".md", ".txt": ".txt", ".html": ".html", + ".pdf": ".pdf", "Print": "Yazdır", "Your preferences for Boostnote": "Boostnote tercihleriniz", "Storage Locations": "Saklama Alanları", diff --git a/locales/zh-CN.json b/locales/zh-CN.json index 2e12323e..8e5537d2 100755 --- a/locales/zh-CN.json +++ b/locales/zh-CN.json @@ -18,6 +18,7 @@ ".md": ".md", ".txt": ".txt", ".html": ".html", + ".pdf": ".pdf", "Print": "打印", "Your preferences for Boostnote": "个性设置", "Storage Locations": "本地存储", diff --git a/locales/zh-TW.json b/locales/zh-TW.json index 93a8afd5..add73073 100755 --- a/locales/zh-TW.json +++ b/locales/zh-TW.json @@ -18,6 +18,7 @@ ".md": ".md", ".txt": ".txt", ".html": ".html", + ".pdf": ".pdf", "Print": "列印", "Your preferences for Boostnote": "Boostnote 偏好設定", "Storage Locations": "儲存空間", From c1deeaf5f759e590c91e125061b5d9c1f8702c37 Mon Sep 17 00:00:00 2001 From: Evan Miller Date: Mon, 3 Dec 2018 14:40:52 -0500 Subject: [PATCH 02/12] Added PDF error to SnippetNoteDetail --- browser/main/Detail/SnippetNoteDetail.js | 3 +++ 1 file changed, 3 insertions(+) diff --git a/browser/main/Detail/SnippetNoteDetail.js b/browser/main/Detail/SnippetNoteDetail.js index 4a5076da..2e93ea25 100644 --- a/browser/main/Detail/SnippetNoteDetail.js +++ b/browser/main/Detail/SnippetNoteDetail.js @@ -650,6 +650,7 @@ class SnippetNoteDetail extends React.Component { 'export-txt': 'Text export', 'export-md': 'Markdown export', 'export-html': 'HTML export', + 'export-pdf': 'PDF export', 'print': 'Print' })[msg] @@ -757,6 +758,7 @@ class SnippetNoteDetail extends React.Component { exportAsMd={this.showWarning} exportAsTxt={this.showWarning} exportAsHtml={this.showWarning} + exportAsPdf={this.showWarning} /> @@ -808,6 +810,7 @@ class SnippetNoteDetail extends React.Component { exportAsMd={this.showWarning} exportAsTxt={this.showWarning} exportAsHtml={this.showWarning} + exportAsPdf={this.showWarning} type={note.type} print={this.showWarning} /> From 33d0a9d3b3b67a474ea9f00d903fa059a7b21180 Mon Sep 17 00:00:00 2001 From: Evan Miller Date: Mon, 3 Dec 2018 15:49:41 -0500 Subject: [PATCH 03/12] extract html contentformatter --- browser/components/MarkdownPreview.js | 108 ++++++++++++++------------ 1 file changed, 57 insertions(+), 51 deletions(-) diff --git a/browser/components/MarkdownPreview.js b/browser/components/MarkdownPreview.js index 87d1d02a..3c8b7c54 100755 --- a/browser/components/MarkdownPreview.js +++ b/browser/components/MarkdownPreview.js @@ -23,7 +23,7 @@ import i18n from 'browser/lib/i18n' import fs from 'fs' import ConfigManager from '../main/lib/ConfigManager' -const { remote, shell } = require('electron') +const { remote, shell, BrowserWindow } = require('electron') const attachmentManagement = require('../main/lib/dataApi/attachmentManagement') const { app } = remote @@ -295,64 +295,70 @@ export default class MarkdownPreview extends React.Component { this.exportAsDocument('md') } - handleSaveAsHtml () { - this.exportAsDocument('html', (noteContent, exportTasks) => { - const { - fontFamily, - fontSize, - codeBlockFontFamily, - lineNumber, - codeBlockTheme, - scrollPastEnd, - theme, - allowCustomCSS, - customCSS - } = this.getStyleParams() + htmlContentFormatter (noteContent, exportTasks) { + const { + fontFamily, + fontSize, + codeBlockFontFamily, + lineNumber, + codeBlockTheme, + scrollPastEnd, + theme, + allowCustomCSS, + customCSS + } = this.getStyleParams() - const inlineStyles = buildStyle( - fontFamily, - fontSize, - codeBlockFontFamily, - lineNumber, - scrollPastEnd, - theme, - allowCustomCSS, - customCSS - ) - let body = this.markdown.render(noteContent) - const files = [this.GetCodeThemeLink(codeBlockTheme), ...CSS_FILES] - files.forEach(file => { - if (global.process.platform === 'win32') { - file = file.replace('file:///', '') - } else { - file = file.replace('file://', '') - } - exportTasks.push({ - src: file, - dst: 'css' - }) + const inlineStyles = buildStyle( + fontFamily, + fontSize, + codeBlockFontFamily, + lineNumber, + scrollPastEnd, + theme, + allowCustomCSS, + customCSS + ) + let body = this.markdown.render(noteContent) + const files = [this.GetCodeThemeLink(codeBlockTheme), ...CSS_FILES] + files.forEach(file => { + if (global.process.platform === 'win32') { + file = file.replace('file:///', '') + } else { + file = file.replace('file://', '') + } + exportTasks.push({ + src: file, + dst: 'css' }) - - let styles = '' - files.forEach(file => { - styles += `` - }) - - return ` - - - - - ${styles} - - ${body} - ` }) + + let styles = '' + files.forEach(file => { + styles += `` + }) + + return ` + + + + + ${styles} + + ${body} + ` + } + + handleSaveAsHtml () { + this.exportAsDocument('html', (noteContent, exportTasks) => this.htmlContentFormatter(noteContent, exportTasks)) } handleSaveAsPdf () { this.exportAsDocument('pdf', (noteContent, exportTasks) => { // Return pdf source + // const doc = new jsPDF() + // doc.fromHTML(this.markdown.render(noteContent), 0, 0) + // return doc.output() + }) } From 0a7fd0288cd80fffbdbcc0f30098db43aba499e5 Mon Sep 17 00:00:00 2001 From: Evan Miller Date: Mon, 3 Dec 2018 16:14:28 -0500 Subject: [PATCH 04/12] Use promises for outputFormatter --- browser/main/lib/dataApi/exportNote.js | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/browser/main/lib/dataApi/exportNote.js b/browser/main/lib/dataApi/exportNote.js index b358e548..c6569730 100755 --- a/browser/main/lib/dataApi/exportNote.js +++ b/browser/main/lib/dataApi/exportNote.js @@ -44,13 +44,16 @@ function exportNote (nodeKey, storageKey, noteContent, targetPath, outputFormatt if (outputFormatter) { exportedData = outputFormatter(exportedData, exportTasks) + } else { + exportedData = Promise.resolve(exportedData) } const tasks = prepareTasks(exportTasks, storagePath, path.dirname(targetPath)) return Promise.all(tasks.map((task) => copyFile(task.src, task.dst))) - .then(() => { - return saveToFile(exportedData, targetPath) + .then(() => exportedData) + .then(data => { + return saveToFile(data, targetPath) }).catch((err) => { rollbackExport(tasks) throw err From 660a27850f26193d7d8487515ce117d65c29f8fe Mon Sep 17 00:00:00 2001 From: Evan Miller Date: Mon, 3 Dec 2018 16:39:41 -0500 Subject: [PATCH 05/12] Generate PDF through an Electron BrowserWindow --- browser/components/MarkdownPreview.js | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/browser/components/MarkdownPreview.js b/browser/components/MarkdownPreview.js index 3c8b7c54..da022a98 100755 --- a/browser/components/MarkdownPreview.js +++ b/browser/components/MarkdownPreview.js @@ -23,7 +23,7 @@ import i18n from 'browser/lib/i18n' import fs from 'fs' 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 { app } = remote @@ -349,16 +349,21 @@ export default class MarkdownPreview extends React.Component { } handleSaveAsHtml () { - this.exportAsDocument('html', (noteContent, exportTasks) => this.htmlContentFormatter(noteContent, exportTasks)) + this.exportAsDocument('html', (noteContent, exportTasks) => Promise.resolve(this.htmlContentFormatter(noteContent, exportTasks))) } handleSaveAsPdf () { this.exportAsDocument('pdf', (noteContent, exportTasks) => { - // Return pdf source - // const doc = new jsPDF() - // doc.fromHTML(this.markdown.render(noteContent), 0, 0) - // return doc.output() - + const printout = new remote.BrowserWindow({show: false}) + printout.loadURL('data:text/html;charset=UTF-8,'+this.htmlContentFormatter(noteContent, exportTasks)) + return new Promise((resolve, reject) => { + printout.webContents.on('did-finish-load', () => { + printout.webContents.printToPDF({}, (err, data) => { + if (err) reject(err) + else resolve(data) + }) + }) + }) }) } From dceed7d84d1cdcfba2d92fa0c3ee694045e519ae Mon Sep 17 00:00:00 2001 From: Evan Miller Date: Mon, 3 Dec 2018 16:51:59 -0500 Subject: [PATCH 06/12] Fixes exportFolder by making it actually wait for each exportNote --- browser/main/lib/dataApi/exportFolder.js | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/browser/main/lib/dataApi/exportFolder.js b/browser/main/lib/dataApi/exportFolder.js index 771f77dc..8f15b147 100644 --- a/browser/main/lib/dataApi/exportFolder.js +++ b/browser/main/lib/dataApi/exportFolder.js @@ -43,19 +43,18 @@ function exportFolder (storageKey, folderKey, fileType, exportDir) { .then(function exportNotes (data) { const { storage, notes } = data - notes + return Promise.all(notes .filter(note => note.folder === folderKey && note.isTrashed === false && note.type === 'MARKDOWN_NOTE') - .forEach(note => { + .map(note => { const notePath = path.join(exportDir, `${filenamify(note.title, {replacement: '_'})}.${fileType}`) - exportNote(note.key, storage.path, note.content, notePath, null) + return exportNote(note.key, storage.path, note.content, notePath, null) }) - - return { + ).then(() => ({ storage, folderKey, fileType, exportDir - } + })) }) } From ce9f76fa639d11ce52929418ca10a1e8833d5429 Mon Sep 17 00:00:00 2001 From: Evan Miller Date: Mon, 3 Dec 2018 16:55:05 -0500 Subject: [PATCH 07/12] fixed code style error --- browser/components/MarkdownPreview.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/browser/components/MarkdownPreview.js b/browser/components/MarkdownPreview.js index da022a98..1eee5005 100755 --- a/browser/components/MarkdownPreview.js +++ b/browser/components/MarkdownPreview.js @@ -355,7 +355,7 @@ export default class MarkdownPreview extends React.Component { handleSaveAsPdf () { this.exportAsDocument('pdf', (noteContent, exportTasks) => { const printout = new remote.BrowserWindow({show: false}) - printout.loadURL('data:text/html;charset=UTF-8,'+this.htmlContentFormatter(noteContent, exportTasks)) + printout.loadURL('data:text/html;charset=UTF-8,' + this.htmlContentFormatter(noteContent, exportTasks)) return new Promise((resolve, reject) => { printout.webContents.on('did-finish-load', () => { printout.webContents.printToPDF({}, (err, data) => { From b546b9cbe75bcfd19537f1593930bd65332837f5 Mon Sep 17 00:00:00 2001 From: Evan Miller Date: Mon, 3 Dec 2018 17:04:04 -0500 Subject: [PATCH 08/12] InfoPanel automatically adjusts its width --- browser/main/Detail/InfoPanel.styl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/browser/main/Detail/InfoPanel.styl b/browser/main/Detail/InfoPanel.styl index 1f774174..e9f7f59b 100644 --- a/browser/main/Detail/InfoPanel.styl +++ b/browser/main/Detail/InfoPanel.styl @@ -15,7 +15,7 @@ right 25px position absolute padding 20px 25px 0 25px - width 300px + // width 300px overflow auto background-color $ui-noteList-backgroundColor box-shadow 2px 12px 15px 2px rgba(0, 0, 0, 0.1), 2px 1px 50px 2px rgba(0, 0, 0, 0.1) From 4d727b0af7a00193b046cb9c20e53a3dd74aaa49 Mon Sep 17 00:00:00 2001 From: Evan Miller Date: Mon, 11 Feb 2019 10:39:51 -0500 Subject: [PATCH 09/12] destroy window after printing --- browser/components/MarkdownPreview.js | 1 + 1 file changed, 1 insertion(+) diff --git a/browser/components/MarkdownPreview.js b/browser/components/MarkdownPreview.js index 1eee5005..6307abf4 100755 --- a/browser/components/MarkdownPreview.js +++ b/browser/components/MarkdownPreview.js @@ -361,6 +361,7 @@ export default class MarkdownPreview extends React.Component { printout.webContents.printToPDF({}, (err, data) => { if (err) reject(err) else resolve(data) + printout.destroy() }) }) }) From bc24acd057d06a691af93c701e0da839cb1fbd20 Mon Sep 17 00:00:00 2001 From: Evan Miller Date: Mon, 11 Feb 2019 11:10:10 -0500 Subject: [PATCH 10/12] add targetDir parameter to outputFormatter --- browser/components/MarkdownPreview.js | 11 ++++++----- browser/main/lib/dataApi/exportNote.js | 2 +- 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/browser/components/MarkdownPreview.js b/browser/components/MarkdownPreview.js index 6307abf4..7a814202 100755 --- a/browser/components/MarkdownPreview.js +++ b/browser/components/MarkdownPreview.js @@ -295,7 +295,7 @@ export default class MarkdownPreview extends React.Component { this.exportAsDocument('md') } - htmlContentFormatter (noteContent, exportTasks) { + htmlContentFormatter (noteContent, exportTasks, targetDir) { const { fontFamily, fontSize, @@ -339,6 +339,7 @@ export default class MarkdownPreview extends React.Component { return ` + @@ -349,13 +350,13 @@ export default class MarkdownPreview extends React.Component { } handleSaveAsHtml () { - this.exportAsDocument('html', (noteContent, exportTasks) => Promise.resolve(this.htmlContentFormatter(noteContent, exportTasks))) + this.exportAsDocument('html', (noteContent, exportTasks, targetDir) => Promise.resolve(this.htmlContentFormatter(noteContent, exportTasks, targetDir))) } handleSaveAsPdf () { - this.exportAsDocument('pdf', (noteContent, exportTasks) => { - const printout = new remote.BrowserWindow({show: false}) - printout.loadURL('data:text/html;charset=UTF-8,' + this.htmlContentFormatter(noteContent, exportTasks)) + this.exportAsDocument('pdf', (noteContent, exportTasks, targetDir) => { + const printout = new remote.BrowserWindow({show: true}) + printout.loadURL('data:text/html;charset=UTF-8,' + this.htmlContentFormatter(noteContent, exportTasks, targetDir)) return new Promise((resolve, reject) => { printout.webContents.on('did-finish-load', () => { printout.webContents.printToPDF({}, (err, data) => { diff --git a/browser/main/lib/dataApi/exportNote.js b/browser/main/lib/dataApi/exportNote.js index c6569730..75c451c1 100755 --- a/browser/main/lib/dataApi/exportNote.js +++ b/browser/main/lib/dataApi/exportNote.js @@ -43,7 +43,7 @@ function exportNote (nodeKey, storageKey, noteContent, targetPath, outputFormatt ) if (outputFormatter) { - exportedData = outputFormatter(exportedData, exportTasks) + exportedData = outputFormatter(exportedData, exportTasks, path.dirname(targetPath)) } else { exportedData = Promise.resolve(exportedData) } From 177888b1592c6c74787893277484433b106c8e78 Mon Sep 17 00:00:00 2001 From: Evan Miller Date: Mon, 11 Feb 2019 11:10:33 -0500 Subject: [PATCH 11/12] disable webSecurity to render files to pdf --- browser/components/MarkdownPreview.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/browser/components/MarkdownPreview.js b/browser/components/MarkdownPreview.js index 7a814202..10836a0f 100755 --- a/browser/components/MarkdownPreview.js +++ b/browser/components/MarkdownPreview.js @@ -355,7 +355,7 @@ export default class MarkdownPreview extends React.Component { handleSaveAsPdf () { this.exportAsDocument('pdf', (noteContent, exportTasks, targetDir) => { - const printout = new remote.BrowserWindow({show: true}) + const printout = new remote.BrowserWindow({show: true, webPreferences: {webSecurity: false}}) printout.loadURL('data:text/html;charset=UTF-8,' + this.htmlContentFormatter(noteContent, exportTasks, targetDir)) return new Promise((resolve, reject) => { printout.webContents.on('did-finish-load', () => { From 2a0906d88e7e7bca1c146c11428504de40a4c49a Mon Sep 17 00:00:00 2001 From: Evan Miller Date: Mon, 18 Mar 2019 10:02:20 -0400 Subject: [PATCH 12/12] Rehid printout BrowserWindow --- browser/components/MarkdownPreview.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/browser/components/MarkdownPreview.js b/browser/components/MarkdownPreview.js index 10836a0f..d5df8de4 100755 --- a/browser/components/MarkdownPreview.js +++ b/browser/components/MarkdownPreview.js @@ -355,7 +355,7 @@ export default class MarkdownPreview extends React.Component { handleSaveAsPdf () { this.exportAsDocument('pdf', (noteContent, exportTasks, targetDir) => { - const printout = new remote.BrowserWindow({show: true, webPreferences: {webSecurity: false}}) + const printout = new remote.BrowserWindow({show: false, webPreferences: {webSecurity: false}}) printout.loadURL('data:text/html;charset=UTF-8,' + this.htmlContentFormatter(noteContent, exportTasks, targetDir)) return new Promise((resolve, reject) => { printout.webContents.on('did-finish-load', () => {