Customizing PDF export per note

I was recently looking for how to make a standard pdf style without changing my whole obsidian theme or using external stuff. So, I wrote a css snippet that affects how things look in the editor and therefore affects how the pdf export looks.

In the header of a file that I want to export to pdf, I put:

cssclass: academia_pdf

This makes it easy to use my regular theme to write and edit my files, and then add that to the header before exporting.

Then, I put a css snippet in the snippets folder (I named it PDFFont.css). Remember to go to Settings>Appearance>CSS Snippets to activate it.

The properties in the first block below affect all of the text in the editor. I illustrate here how to change the font, the text size, add paragraph indents, and change the line spacing. The next one affects the color of links (external and internal). The third affects the highlight color. This is for the new editor (WYSIWYG), and notice that each one has .academia_pdf out front (same name as what is in my header).

.academia_pdf .cm-content {
font-family: “Times New Roman”, Times, serif;
font-size: 11.5px;
text-indent: 2em;
line-height: 2;
}

.academia_pdf .cm-content .cm-url {
color: red;
}

.academia_pdf .cm-content .cm-highlight {
background: LightSkyBlue;
}

3 Likes

I moved this to its own thread so it wasn’t lost, but the OP originally posted it in reply here:

Customising PDF formatting

Hi, just a follow up to my own post. This actually wasn’t doing exactly what I wanted - I got over-excited and didn’t realize my small changes weren’t affecting the pdf export. I have found how to do it, though.

Save the following as a css snippet and toggle it on and off as needed. Nothing needed in the header/frontmatter of any individual .md file.

@media print {

body {
  font-family: "Times New Roman", Times, serif; 
  font-size: 11.5px;
  text-indent: 2em;
  line-height: 2;
}

a {
  color: black;
} 

}

1 Like