How do I get Obsidian to display the file name in a PDF printout?

Input (Markdown)


function format_date($date) {
    if (empty($date)) {
        return $date;
    }
    return str_replace('-', '/', $date);
}

Output (PDF)

My Expected Output

  • I want to display the file name somewhere in the code block. Ideally, it should be displayed in the upper left corner.
  • It would be even better if the same syntax highlighting that appears on the Obsidian preview screen could also be applied to printouts.

Obsidian will show the file name on mouse hover if you write the file name after the file extension, but will not print the file name when printing PDF.

I would like to print the file name when printing a PDF, even if it means that the file name is always displayed.

How can I achieve this?

This might not be the best approach, but I’ve found a solution for now and wanted to share it.

By using the “callout” syntax, I was able to achieve a display that’s close to the ideal look.

Sample

> [!NOTE]+ php:application/helpers/admin_helper.php
> ```php
> function format_date($date) {
>     if (empty($date)) {
>         return $date;
>     }
>     return str_replace('-', '/', $date);
> }
> ```

Important Rules

  • > [!NOTE]+ {label} … This part is required, including the quotation marks.
  • > ```{syntax_name} … A single space is required. Entering a syntax name enables syntax highlighting.

Source Mode + Live Preview

PDF Outputs

What is a “callout” ?

If anyone knows of a better solution, please let me know.
Thank you!