Skip to content

Commit

Permalink
Added Export Note as PDF feature
Browse files Browse the repository at this point in the history
  • Loading branch information
klaudiosinani committed Sep 16, 2017
1 parent d86a21c commit 909f2df
Show file tree
Hide file tree
Showing 4 changed files with 63 additions and 1 deletion.
6 changes: 6 additions & 0 deletions browser.js
Original file line number Diff line number Diff line change
Expand Up @@ -255,6 +255,12 @@ function printToPDF() {

ipc.on('print', printToPDF);

function exportAsPDF() {
ipc.send('export-as-pdf');
}

ipc.on('export', exportAsPDF);

ipc.on('next-note', goToNextNote);

ipc.on('previous-note', goToPreviewsNote);
Expand Down
42 changes: 42 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ const app = electron.app;
const BrowserWindow = electron.BrowserWindow;
const ipcMain = electron.ipcMain;
const shell = electron.shell;
const dialog = electron.dialog;

require('electron-debug')({enabled: true});
require('electron-dl')();
Expand Down Expand Up @@ -169,6 +170,47 @@ ipcMain.on('print-to-pdf', event => {
});
});

ipcMain.on('export-as-pdf', event => {
// Strin to be removed from note title
const removeString = ' | Evernote Web';
// Get the note title
const noteTitle = mainWindow.webContents.getTitle().replace(removeString, '');
console.log('Note to be exported is titled: ' + noteTitle);
const noteWindow = BrowserWindow.fromWebContents(event.sender);
// `Save note` dialog options
const options = {
// Suggest note title as filename
defaultPath: noteTitle,
filters: [{
name: 'PDF File',
extensions: ['pdf']
}, {
name: 'All Files',
extensions: ['*']
}]
};
// Intialize printing process
noteWindow.webContents.printToPDF({}, (error, data) => {
if (error) {
return console.log(error.message);
}
// Set out the `Save note` dialog
dialog.showSaveDialog(options, fileName => {
// Check if the filepath is valid
if (fileName === undefined) {
return console.log('Note was not exported');
}
// Intialize the file writing process
fs.writeFile(fileName, data, err => {
if (err) {
dialog.showErrorBox('Exporting note error', err.message);
return console.log(err.message);
}
});
});
});
});

app.on('activate', () => {
mainWindow.show();
});
Expand Down
12 changes: 12 additions & 0 deletions menu.js
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,12 @@ const darwinTpl = [{
click() {
activate('print');
}
}, {
label: 'Export Note as PDF',
accelerator: 'CmdorCtrl+Shift+E',
click() {
activate('export');
}
}, {
type: 'separator'
}, {
Expand Down Expand Up @@ -553,6 +559,12 @@ const otherTpl = [{
click() {
activate('print');
}
}, {
label: 'Export Note as PDF',
accelerator: 'CmdorCtrl+Shift+E',
click() {
activate('export');
}
}, {
type: 'separator'
}, {
Expand Down
4 changes: 3 additions & 1 deletion readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,9 @@ Come over to our [Twitter](https://twitter.com/champloohq) account to share your
- [Focus Mode](#focus-mode)
- [Compact Mode](#compact-mode)
- [Note Navigation](#note-navigation)
- [Note Printing](#note-printing)
- [Scalable Interface](#scalable-interface)
- [Export Notes](#export-notes)
- [Yinxiang Support](#yinxiang-support)
- [Keyboard Shortcuts](#keyboard-shortcuts)
- [Build-in Markdown](#build-in-markdown)
Expand Down Expand Up @@ -174,6 +176,7 @@ Align Center | <kbd>Cmd/Ctrl</kbd> <kbd>Alt</kbd> <kbd>M</kbd>
Align Right | <kbd>Cmd/Ctrl</kbd> <kbd>Alt</kbd> <kbd>R</kbd>
Increase Indentation | <kbd>Cmd/Ctrl</kbd> <kbd>Alt</kbd> <kbd>K</kbd>
Make Text Larger | <kbd>Cmd/Ctrl</kbd> <kbd>Shift</kbd> <kbd>=</kbd>
Export Note as PDF | <kbd>Cmd/Ctrl</kbd> <kbd>Shift</kbd> <kbd>P</kbd>
New Tag | <kbd>Cmd/Ctrl</kbd> <kbd>Shift</kbd> <kbd>T</kbd>
New Notebook | <kbd>Cmd/Ctrl</kbd> <kbd>Shift</kbd> <kbd>N</kbd>
Toggle Checkbox | <kbd>Cmd/Ctrl</kbd> <kbd>Shift</kbd> <kbd>C</kbd>
Expand Down Expand Up @@ -219,7 +222,6 @@ Feel like suggesting a new feature? Open a [`feature-request issue`](https://git

- [ ] App pin lock
- [ ] Automatic night mode
- [ ] Note printing
- [ ] Code blocks highlighting
- [ ] RTL support

Expand Down

0 comments on commit 909f2df

Please sign in to comment.