Customizing document styles with FSharp.Markdown.Pdf

Presently sponsored by Serverless Guru: Your guide to cloud excellence, helping you every step of your serverless journey, including team training, pattern development, mass service migrations, architecting, and developing new solutions. Speak to a Guru today.

Following on from my last post on formatting a Markdown document into PDF using FSharp.Markdown.Pdf, if you don’t like the default styling (which I tried to mimic style Github formats Markdown documents with) you can set your own styling for the different types of Markdown elements by going down a level of abstraction.

The FSharp.Markdown.Pdf.MarkdownStyleNames module defines all the names of styles used to format the different Markdown elements (e.g. heading 1-6, code block, listing 1-3, etc.) into PDF. To override the default styles, you need to:

  1. Instantiate an instance of the Document type from the MigraDoc.DocumentObjectModel namespace.
  2. Add the predefined style names from the aforementioned MarkdownStyleNames module to the document’s collection of styles.
  3. Tweak the style to your liking.
  4. Call the FSharp.Markdown.Pdf.PdfFormatting.formatMarkdown function with the Document value.
  5. Voila! You now have an instance of PdfDocument which has been formatted with your custom styling.

to see these simple steps in action:

You can compare the original and customized PDF outputs here and here.

1 thought on “Customizing document styles with FSharp.Markdown.Pdf”

  1. Pingback: F# Weekly #26 2013 | Sergey Tihon's Blog

Leave a Comment

Your email address will not be published. Required fields are marked *