RazorPDF – MVC View As A PDF

RazorPDF - create a PDF document using view data

RazorPDF - create a PDF document using view data

I have recently been working with a very useful PDF generator tool called RazorPDF. This is available via Nuget and lets developers write familiar XHTML-style code to render model data as PDF.

Coding a PDF document using RazorPDF will be already quite familiar to MVC developers. The syntax wraps around model data in much the same way that HTML surrounds razor code. As you can see from the screenshot above, there are specific RazorPDF elements and attributes that are required for the API to render the PDF, and those elements surround the familiar model syntax. Standard razor code blocks are still valid and preserve C# functionality.

For example, to render a table, there is a table element. And the table element has attributes. There are similar paragraph, section and phrase elements (just to name a few).

My only criticism is the lack of documentation. There is a Github repo for the project and you can find it here. However, there seems to be an obvious lack of detailed documentation about elements and attributes.

There are a myriad of elements which seem to be quite easy to find however, the attributes available for those elements are sometimes difficult to realise. And some attributes are only available on specific elements too. For example, the paragraph element does not seem to have a font colour attribute, so you need to insert a element inside the paragraph in order to colour your text.

Next time you need to render a PDF version of your data, checkout RazorPDF.

Til next time...