Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(export): allow setting paper size in pdf export #728

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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 README.md
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ Please npm install the theme you wish to use locally before attempting to export
Options:

- `--format <file type>` Example: `--format pdf`
- `--papersize <paper size>` Example: `--papersize a4`
- `--theme <name>` Example: `--theme even`

## `resume serve`
Expand Down
15 changes: 11 additions & 4 deletions lib/export-resume.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ const puppeteer = require('puppeteer');
const btoa = require('btoa');

module.exports = (
{ resume: resumeJson, fileName, theme, format },
{ resume: resumeJson, fileName, theme, format, papersize },
callback,
) => {
if (!fileName) {
Expand All @@ -28,7 +28,7 @@ module.exports = (
callback(error, fileName, formatToUse);
});
} else if (formatToUse === '.pdf') {
createPdf(resumeJson, fileName, theme, formatToUse, (error) => {
createPdf(resumeJson, fileName, theme, formatToUse, papersize, (error) => {
if (error) {
console.error(error, '`createPdf` errored out');
}
Expand Down Expand Up @@ -76,7 +76,14 @@ async function createHtml(resumeJson, fileName, themePath, format, callback) {
stream.close(callback);
});
}
const createPdf = (resumeJson, fileName, theme, format, callback) => {
const createPdf = (
resumeJson,
fileName,
theme,
format,
papersize,
callback,
) => {
(async () => {
const themePkg = getThemePkg(theme);
const puppeteerLaunchArgs = [];
Expand Down Expand Up @@ -107,7 +114,7 @@ const createPdf = (resumeJson, fileName, theme, format, callback) => {
}
await page.pdf({
path: fileName + format,
format: 'Letter',
format: papersize,
printBackground: true,
...themePkg.pdfRenderOptions,
});
Expand Down
5 changes: 4 additions & 1 deletion lib/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ const normalizeTheme = (value, defaultValue) => {
'jsonresume-theme-even',
)
.option('-f, --format <file type extension>', 'Used by `export`.')
.option('--papersize <papersize>', 'Used by `export`.', 'Letter')
.option(
'-r, --resume <resume filename>',
"path to the resume in json format. Use '-' to read from stdin",
Expand Down Expand Up @@ -89,8 +90,10 @@ const normalizeTheme = (value, defaultValue) => {
program
.command('export [fileName]')
.description(
'Export locally to .html or .pdf. Supply a --format <file format> flag and argument to specify export format.',
'Export locally to .html or .pdf. Supply a --format <file format> flag and argument to specify export format. ' +
'Supply --papersize flag and argument to specify export page format when rendering a PDF.',
)
.option('--papersize <papersize>', 'Paper size to use with PDF', 'Letter')
.action(async (fileName) => {
const resume = await getResume({ path: program.resume });
exportResume(
Expand Down