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

bug: headerTemplate and footerTemplate properties do not work with pdf-options CLI option #59

Closed
ltfschoen opened this issue Jan 24, 2020 · 3 comments
Labels

Comments

@ltfschoen
Copy link

ltfschoen commented Jan 24, 2020

Context:

  • version (md-to-pdf -v): 2.8.2
  • platform (Unix, macOS, Windows): macOS
  • node version: v13.3.0

Describe the bug:

When I run the following, it generates a PDF file and correctly applies the styles in style.css, and it is correctly formatted as A4, but it doesn't contain a header or a footer, even though I've specified a headerTemplate and footerTemplate in the --pdf-options.

md-to-pdf ./README.md \
  --stylesheet ./style.css \
  --highlight-style monokai \
  --pdf-options '{ "format": "A4", "margin": "30mm 20mm", "printBackground": true, "headerTemplate": "<style> section { margin: 0 auto; font-family: system-ui; font-size: 11px; } </style><section><span class='date'></span></section>", "footerTemplate": "<section><div>Page <span class='pageNumber'></span> of <span class='totalPages'></span></div></section>"
  }' \
  ./output.pdf
@ltfschoen ltfschoen added the bug label Jan 24, 2020
@ltfschoen
Copy link
Author

I tried using the config.json file instead and running the following, but neither the HTML or PDF output files have the header or footer:

md-to-pdf --as-html ./README.md \
  --config-file ./config.json \
  ./output.html

md-to-pdf ./README.md \
  --config-file ./config.json \
  ./output.pdf

where the contents of the JSON file is

{
  "stylesheet": [
    "./style.css"
  ],
  "css": "body { color: tomato; }",
  "body_class": "markdown-body",
  "highlight_style": "monokai",
  "marked_options": {
    "headerIds": false,
    "smartypants": true
  },
  "pdf_options": {
    "format": "A4",
    "margin": "30mm 20mm",
    "printBackground": true,
    "headerTemplate": "<style> section { margin: 0 auto; font-family: system-ui; font-size: 11px; } </style><section><span class='date'></span></section>",
    "footerTemplate": "<section><div>Page <span class='pageNumber'></span> of <span class='totalPages'></span></div></section>"
  }
}

@simonhaenisch
Copy link
Owner

That's because you forgot to add "displayHeaderFooter": true. Sorry, it's a Puppeteer thing. It's mentioned in the first line of https://github.com/simonhaenisch/md-to-pdf#headerfooter.

Now I'm thinking of auto-setting it to true by default if either headerTemplate or footerTemplate is set because the same thing has happened to me before 🙈

@ltfschoen
Copy link
Author

Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants