Customizing document styles with FSharp.Markdown.Pdf

Fol­low­ing on from my last post on for­mat­ting a Mark­down doc­u­ment into PDF using FSharp.Markdown.Pdf, if you don’t like the default styling (which I tried to mim­ic style Github for­mats Mark­down doc­u­ments with) you can set your own styling for the dif­fer­ent types of Mark­down ele­ments by going down a lev­el of abstrac­tion.

The FSharp.Markdown.Pdf.MarkdownStyleNames mod­ule defines all the names of styles used to for­mat the dif­fer­ent Mark­down ele­ments (e.g. head­ing 1–6, code block, list­ing 1–3, etc.) into PDF. To over­ride the default styles, you need to:

  1. Instan­ti­ate an instance of the Doc­u­ment type from the MigraDoc.DocumentObjectModel name­space.
  2. Add the pre­de­fined style names from the afore­men­tioned Mark­down­Style­Names mod­ule to the document’s col­lec­tion of styles.
  3. Tweak the style to your lik­ing.
  4. Call the FSharp.Markdown.Pdf.PdfFormatting.formatMarkdown func­tion with the Doc­u­ment val­ue.
  5. Voila! You now have an instance of Pdf­Doc­u­ment which has been for­mat­ted with your cus­tom styling.

to see these sim­ple steps in action:

You can com­pare the orig­i­nal and cus­tomized PDF out­puts here and here.