Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .git-blame-ignore-revs
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
a76ab284a8d30c669b5ad2278bbcd050dea13abe
2 changes: 2 additions & 0 deletions .github/workflows/lint-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ jobs:
node-version: ${{ matrix.node-version }}
- name: Install dependencies
run: yarn --frozen-lockfile
- name: Run Prettier check
run: npm run prettier -- --check
- name: Run ESLint
run: npm run lint
- name: Run tests
Expand Down
6 changes: 5 additions & 1 deletion .prettierignore
Original file line number Diff line number Diff line change
@@ -1 +1,5 @@
demo/bundle.js
**.html
**.md
demo/bundle.js
tests/images/bee.js
tests/visual/pdfmake/*.js
40 changes: 20 additions & 20 deletions docs/generate.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,52 +16,52 @@ const styles = {
h1: {
font: 'fonts/Alegreya-Bold.ttf',
fontSize: 25,
padding: 15
padding: 15,
},
h2: {
font: 'fonts/Alegreya-Bold.ttf',
fontSize: 18,
padding: 10
padding: 10,
},
h3: {
font: 'fonts/Alegreya-Bold.ttf',
fontSize: 18,
padding: 10
padding: 10,
},
para: {
font: 'fonts/Merriweather-Regular.ttf',
fontSize: 10,
padding: 10
padding: 10,
},
code: {
font: 'fonts/SourceCodePro-Regular.ttf',
fontSize: 9
fontSize: 9,
},
code_block: {
padding: 10,
background: '#2c2c2c'
background: '#2c2c2c',
},
inlinecode: {
font: 'fonts/SourceCodePro-Bold.ttf',
fontSize: 10
fontSize: 10,
},
listitem: {
font: 'fonts/Merriweather-Regular.ttf',
fontSize: 10,
padding: 6
padding: 6,
},
link: {
font: 'fonts/Merriweather-Regular.ttf',
fontSize: 10,
color: 'blue',
underline: true
underline: true,
},
example: {
font: 'Helvetica',
fontSize: 9,
color: 'black',
padding: 10
}
padding: 10,
},
};

// syntax highlighting colors
Expand Down Expand Up @@ -89,7 +89,7 @@ const colors = {
quote: '#93a1a1',
link: '#93a1a1',
special: '#6c71c4',
default: '#002b36'
default: '#002b36',
};

// shared lorem ipsum text so we don't need to copy it into every example
Expand Down Expand Up @@ -135,7 +135,7 @@ class Node {
const color = colors[style] || colors.default;
const opts = {
color,
continued: text !== '\n'
continued: text !== '\n',
};

return this.content.push(new Node(['code', opts, text]));
Expand Down Expand Up @@ -164,7 +164,7 @@ class Node {
}

// sets the styles on the document for this node
setStyle (doc) {
setStyle(doc) {
if (this.style.font) {
doc.font(this.style.font);
}
Expand All @@ -189,7 +189,7 @@ class Node {
}

// renders this node and its subnodes to the document
render (doc, continued) {
render(doc, continued) {
let y;
if (continued == null) {
continued = false;
Expand Down Expand Up @@ -217,7 +217,7 @@ class Node {
// run the example code with the document
vm.runInNewContext(this.code, {
doc,
lorem
lorem,
});

// restore points and styles
Expand Down Expand Up @@ -273,7 +273,7 @@ class Node {
} else {
fragment.render(
doc,
index < this.content.length - 1 && this.type !== 'bulletlist'
index < this.content.length - 1 && this.type !== 'bulletlist',
);
}

Expand Down Expand Up @@ -302,7 +302,7 @@ const render = (doc, filename) => {
};

// renders the title page of the guide
const renderTitlePage = doc => {
const renderTitlePage = (doc) => {
const title = 'PDFKit Guide';
const author = 'By Devon Govett';
const version = `Version ${require('../package.json').version}`;
Expand All @@ -317,13 +317,13 @@ const renderTitlePage = doc => {
doc.y -= 10;
doc.text(author, {
align: 'center',
indent: w - doc.widthOfString(author)
indent: w - doc.widthOfString(author),
});

doc.font(styles.para.font, 10);
doc.text(version, {
align: 'center',
indent: w - doc.widthOfString(version)
indent: w - doc.widthOfString(version),
});

doc.addPage();
Expand Down
18 changes: 9 additions & 9 deletions docs/generate_website.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,14 @@ const files = [
'attachments.md',
'accessibility.md',
'table.md',
'you_made_it.md'
'you_made_it.md',
];

// shared lorem ipsum text so we don't need to copy it into every example
const lorem =
'Lorem ipsum dolor sit amet, consectetur adipiscing elit. Etiam in suscipit purus. Vestibulum ante ipsum primis in faucibus orci luctus et ultrices posuere cubilia Curae; Vivamus nec hendrerit felis. Morbi aliquam facilisis risus eu lacinia. Sed eu leo in turpis fringilla hendrerit. Ut nec accumsan nisl. Suspendisse rhoncus nisl posuere tortor tempus et dapibus elit porta. Cras leo neque, elementum a rhoncus ut, vestibulum non nibh. Phasellus pretium justo turpis. Etiam vulputate, odio vitae tincidunt ultricies, eros odio dapibus nisi, ut tincidunt lacus arcu eu elit. Aenean velit erat, vehicula eget lacinia ut, dignissim non tellus. Aliquam nec lacus mi, sed vestibulum nunc. Suspendisse potenti. Curabitur vitae sem turpis. Vestibulum sed neque eget dolor dapibus porttitor at sit amet sem. Fusce a turpis lorem. Vestibulum ante ipsum primis in faucibus orci luctus et ultrices posuere cubilia Curae;';

const getNodeName = function(node) {
const getNodeName = function (node) {
if (node.length === 3) {
return node[2];
}
Expand All @@ -49,7 +49,7 @@ const getNodeName = function(node) {
return words.join('');
};

const extractHeaders = function(tree) {
const extractHeaders = function (tree) {
const headers = [];

for (let index = 0; index < tree.length; index++) {
Expand All @@ -63,7 +63,7 @@ const extractHeaders = function(tree) {
node[1].id = hash;
headers.push({
hash,
title: name
title: name,
});
}
}
Expand All @@ -72,7 +72,7 @@ const extractHeaders = function(tree) {
};

let imageIndex = 0;
const generateImages = function(tree) {
const generateImages = function (tree) {
// find code blocks
const codeBlocks = [];
for (var node of tree) {
Expand Down Expand Up @@ -100,7 +100,7 @@ const generateImages = function(tree) {

vm.runInNewContext(code, {
doc,
lorem
lorem,
});

delete attrs.title;
Expand All @@ -119,7 +119,7 @@ const generateImages = function(tree) {
console.error(err);
}
fs.unlinkSync(`${f}.pdf`);
}
},
);
});

Expand All @@ -135,7 +135,7 @@ for (let file of Array.from(files)) {
// turn github highlighted code blocks into normal markdown code blocks
content = content.replace(
/^```javascript\n((:?.|\n)*?)\n```/gm,
(m, $1) => ` ${$1.split('\n').join('\n ')}`
(m, $1) => ` ${$1.split('\n').join('\n ')}`,
);

const tree = markdown.parse(content);
Expand All @@ -149,7 +149,7 @@ for (let file of Array.from(files)) {
url: `/docs/${file}.html`,
title: headers[0].title,
headers: headers.slice(1),
content: markdown.toHTML(tree)
content: markdown.toHTML(tree),
});
}

Expand Down
8 changes: 4 additions & 4 deletions docs/publish_website.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,14 @@ ghpages.publish(
'docs/guide.pdf',
'examples/browserify/browser.html',
'examples/browserify/bundle.js',
'examples/kitchen-sink.pdf'
'examples/kitchen-sink.pdf',
],
add: true,
message
message,
},
function(err) {
function (err) {
if (err) {
console.error(err);
}
}
},
);
2 changes: 1 addition & 1 deletion lib/data.js
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@ class Data {
}

write(bytes) {
return bytes.map(byte => this.writeByte(byte));
return bytes.map((byte) => this.writeByte(byte));
}
}

Expand Down
30 changes: 15 additions & 15 deletions lib/document.js
Original file line number Diff line number Diff line change
Expand Up @@ -64,17 +64,17 @@ class PDFDocument extends stream.Readable {
const Pages = this.ref({
Type: 'Pages',
Count: 0,
Kids: []
Kids: [],
});

const Names = this.ref({
Dests: new PDFNameTree()
Dests: new PDFNameTree(),
});

this._root = this.ref({
Type: 'Catalog',
Pages,
Names
Names,
});

if (this.options.lang) {
Expand All @@ -100,7 +100,7 @@ class PDFDocument extends stream.Readable {
this.info = {
Producer: 'PDFKit',
Creator: 'PDFKit',
CreationDate: new Date()
CreationDate: new Date(),
};

if (this.options.info) {
Expand All @@ -112,7 +112,7 @@ class PDFDocument extends stream.Readable {

if (this.options.displayTitle) {
this._root.data.ViewerPreferences = this.ref({
DisplayDocTitle: true
DisplayDocTitle: true,
});
}

Expand Down Expand Up @@ -188,7 +188,7 @@ class PDFDocument extends stream.Readable {
throw new Error(
`switchToPage(${n}) out of bounds, current buffer covers pages ${
this._pageBufferStart
} to ${this._pageBufferStart + this._pageBuffer.length - 1}`
} to ${this._pageBufferStart + this._pageBuffer.length - 1}`,
);
}

Expand Down Expand Up @@ -222,7 +222,7 @@ class PDFDocument extends stream.Readable {
if (!this._root.data.Names.data.EmbeddedFiles) {
// disabling /Limits for this tree fixes attachments not showing in Adobe Reader
this._root.data.Names.data.EmbeddedFiles = new PDFNameTree({
limits: false
limits: false,
});
}

Expand All @@ -236,7 +236,7 @@ class PDFDocument extends stream.Readable {
}
let data = {
JS: new String(js),
S: 'JavaScript'
S: 'JavaScript',
};
this._root.data.Names.data.JavaScript.add(name, data);
}
Expand All @@ -257,7 +257,7 @@ class PDFDocument extends stream.Readable {
}

this.push(data);
return (this._offset += data.length);
this._offset += data.length;
}

addContent(data) {
Expand All @@ -269,7 +269,7 @@ class PDFDocument extends stream.Readable {
this._offsets[ref.id - 1] = ref.offset;
if (--this._waiting === 0 && this._ended) {
this._finalize();
return (this._ended = false);
this._ended = false;
}
}

Expand Down Expand Up @@ -319,9 +319,9 @@ class PDFDocument extends stream.Readable {
}

if (this._waiting === 0) {
return this._finalize();
this._finalize();
} else {
return (this._ended = true);
this._ended = true;
}
}

Expand All @@ -342,7 +342,7 @@ class PDFDocument extends stream.Readable {
Size: this._offsets.length + 1,
Root: this._root,
Info: this._info,
ID: [this._id, this._id]
ID: [this._id, this._id],
};
if (this._security) {
trailer.Encrypt = this._security.dictionary;
Expand All @@ -356,15 +356,15 @@ class PDFDocument extends stream.Readable {
this._write('%%EOF');

// end the stream
return this.push(null);
this.push(null);
}

toString() {
return '[object PDFDocument]';
}
}

const mixin = methods => {
const mixin = (methods) => {
Object.assign(PDFDocument.prototype, methods);
};

Expand Down
Loading
Loading