-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
45 lines (40 loc) · 1.36 KB
/
Copy pathindex.js
File metadata and controls
45 lines (40 loc) · 1.36 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
const util = require('util');
const _ = require('lodash');
const PDFDocument = require('pdfkit');
const fs = require('fs');
const fetchNewEmail = require('./fetch-new-email-simple');
const printEmailToPdfPage = require('./print-email-to-pdf-page');
const width = 144;
const maxheight = 500;
fetchNewEmail().then((list) => {
console.log(`Received ${list.length} emails`);
const doc = new PDFDocument({ autoFirstPage: false });
// create tmp if it needs creating, and assume the log file needs creating too
if (!fs.existsSync('./tmp')){
fs.mkdirSync('./tmp');
fs.mkdirSync('./log');
}
doc.pipe(fs.createWriteStream('./tmp/current.pdf'));
_.forEach(list, email => {
console.log('Adding page for email', email);
console.log('START >>>>>>>>>>>>');
doc.addPage({
size: [width, maxheight],
margins: {
left: 5,
right: 5,
top: 10,
bottom: 10,
}
});
// create a test file for this email
fs.writeFileSync(email.from[0]+'.email', email.bodies, { flag: 'w' });
printEmailToPdfPage(doc, email, maxWidth = width);
console.log('FINISH <<<<<<<<<<<');
});
doc.end();
//console.log(util.inspect(list));
}).catch((err) => {
console.log(`Received ${err}`);
console.log(err.stack);
});