[Plugin] PDF Header & Footer: a header, footer and page numbers on every page of exported PDFs

I needed every PDF I export from Joplin to carry my company's header and tagline. So far I'd been hard-coding them in the custom stylesheet, which had two problems. The text only appeared once (at the top of the first page and at the end of the note), and changing it meant editing CSS. This plugin replaces that with a settings page.

What is it?

A plugin that adds a header and footer to every page of a note when you export it to PDF. You type the text in Joplin's settings, with no CSS editing, and you can add page numbers and the date.

Repository: GitHub - tnoahc/joplin-pdf-header-footer Β· GitHub

Why this exists

Many of us have to produce documents that follow a house style: a company name at the top, a tagline or confidentiality line at the bottom, and page numbers. Joplin's PDF export doesn't offer that. Pasting CSS into userstyle.css gets you part of the way, but ::before/::after rules only print once per document, not once per page. And the text is buried in a stylesheet.

Current state

Version 1.0.0, released as a small .jpl with no dependencies. It's plain JavaScript, so there's no build step. I've tested it on Joplin desktop 3.7.21 (Linux) in development mode, exporting multi-page notes to PDF.

What works:

Feature Status
Header on every page: left, centre and right text :white_check_mark:
Footer on every page: left, centre and right text :white_check_mark:
Placeholders: {page}, {pages}, {date} :white_check_mark:
Optional separator lines under the header and above the footer :white_check_mark:
Adjustable font size and top and bottom page margins :white_check_mark:
Note viewer unaffected (only exported PDFs change) :white_check_mark:
File β†’ Print :x: (see Caveats)

For example, Page {page} of {pages} in the footer prints "Page 2 of 5".

How it works

My first idea was to use Electron's built-in header and footer options for printToPDF (displayHeaderFooter, headerTemplate, footerTemplate). Reading InteropServiceHelper.ts showed that this route is closed. Joplin builds the print options itself, and a plugin can't add to them.

Two other details in the same code made a plugin possible:

  1. To make a PDF, Joplin first exports the note to HTML with plugin content scripts applied, then prints that HTML in a hidden window.
  2. It prints with preferCSSPageSize: true, so the document's own CSS @page rules are respected.

So the plugin is a Markdown-it content script. It adds a <style> block with @page margin boxes (@top-left, @bottom-right and so on) to the rendered note. Chromium has supported these since version 131, and they repeat on every printed page. counter(page) and counter(pages) provide the page numbers. The content script reads your settings through pluginOptions.settingValue(), which also works during export. Because @page rules only apply in print, the viewer looks the same.

Setup

  1. Download plugin.tnoahc.pdf-header-footer.jpl from the latest release.
  2. Go to Tools β†’ Options β†’ Plugins β†’ :gear: β†’ Install from file, choose the file, and restart Joplin.
  3. Fill in the text under Tools β†’ Options β†’ PDF Header & Footer.
  4. Export as usual with File β†’ Export β†’ PDF.

If your custom stylesheet already adds a header or footer through .exported-note::before/::after, remove those rules so the text doesn't appear twice.

Requires Joplin desktop 3.2 or later.

What's next

Ideas I'm considering. Tell me which would be most useful:

  • A different header (or none) on the first page
  • A logo image in the header
  • Different header and footer text per notebook
  • The note title as a placeholder
  • Submission to the official plugin repository

Caveats

  • File β†’ Print doesn't include the header and footer. Joplin's print command doesn't load plugins, unlike the PDF export. Export to PDF first, then print the PDF.
  • The note title isn't available as a placeholder yet. Joplin already prints it at the top of the note.
  • Joplin's own PDF margin settings may interact with the plugin's margin settings. Adjust the top and bottom margins if the header sits too close to the edge.
  • This was developed with AI assistance (Claude).

Feedback, bug reports and contributions are welcome. I'm particularly interested in how it behaves with other page sizes, other operating systems and custom stylesheets.

Thank you for this plugin. Much simpler then CSS fiddling for printouts.

My feedback and ideas for future versions:

  • Submission to the official plugin repository would be great
  • Note title as a placeholder would be great
  • No header on the first page would be great
  • Draw lines should be set separate by header and footer
  • Options for left and right margins would be great

Thank you for the feedback! The plugin is now available in the official repository, you can find it by searching for PDF Header & Footer in Joplin’s plugin settings.

Separate header/footer line controls, left/right margins, and an option to hide the header on the first page all sound useful. I’ll also investigate a note-title placeholder. I want to make sure it uses the correct title when exporting multiple notes.

For the first-page option, would you expect the header space to remain empty, or the note content to move up into that space?