Independent Razor View

Hi, I created the invoicing SaaS iFacture

Currently, PDF documents (invoices and quotes) are generated using code + iTextSharp. This executes very fast but this is not easy to modify.
So, for the new version I want to use ServiceStack + Puppeteer Sharp to generate PDF from a Razor view (.cshtml).
The idea is to have the Razor view inside ServiceInterface project (embedded resource?) (and not on the web project) and pass a populated model during execution to be able to render the HTML View. Since I want to populate the HTML file directly from the model, I don’t need things like relative path or absolute URIs…
After that, Puppeteer Sharp will transform the HTML rendered view in PDF. It’s slower but easier to change.

A project like RazorEngine could do the trick, but it is not maintained anymore and maybe I can do that with ServiceStack Razor.

I am using Framework 6.

How would you do this?

Thank you in advance.

No idea about iTextSharp or Puppeteer which I’ve never used before.

If it’s just the HTML output you want generated it would be much easier to embed #Script since it’s entire environment can be programmatically customized & encapsulated within a Service impl. The service impl of Email Templates is a good example of adding in memory pages / layout in a new ScriptContext and accessing rendered pages content.

Razor by contrast is very fragile and reliant on a number of external moving parts & proper configuration. But here’s a stand-alone example of rendering Razor within a Service impl:

https://docs.servicestack.net/netcore-razor#stand-alone-razor-views

Nice work on the SaaS product, I hope it’s successful! Would make a nice entry in the showcase category on ServiceStack/Discuss.

1 Like

Thank you very much. I will try that.
On another part, I’m using ServiceStack on the company I work too (as employeeà. I made an ERP and it is driven by ServiceStack (since 2013). It is not publicly accessible but I am open to share some screenshots and do a use case if you want.

2 Likes

Yeah definitely the more the merrier, a summary of the App with screenshots would be great.

1 Like