Using RotativaHQ in the same way you use Asp.Net code should be enough to get reasonable performance in creating your PDF files. There are cases, though, perhaps complex or large pages, in which this is not enough. In this blog post we will cover some aspects that, with some attention, can make your PDF creation faster.
Web page elements
Most issues about PDF creation slowness can be routed down to web page slowness. In the case of remote PDF creation this issues can stand out greatly. It all boils down to total page size, and I mean total by adding up all elements needed for a page render.
For those reasons consider making a dedicated layout page, maybe taking the _Layout.cshtml as a source and stripping out unused elements. For css files consider inspecting your PDF HTML source for unused styles. You can do this by visualizing your HTML as a page instead of a PDF, turning
View and using Chrome Developer Tools using a technique explained in this blog post: Remove Unused CSS to Reduce the Size of your Stylesheets.
By default RotativaHQ compresses the content of the API call to the service. This is really useful in the development stage and shouldn’t effect substantially once deployed to the server. But in some scenario this can affect performance if you use the standard
Bundles Asp.Net MVC feature. Bundling means that multiple js or css files are bundled together and minified. Compressing and uncompressing minified content can result in unnecessary computing activity.
The good news is that you can in fact control whether compression is applied or not very easily. There is Web.config appsetting you can use, it’s the
RotativaGZip setting. You can easily setup a Web.config transform to disable compression only for the published web app. Simply add this to the
This way you will benefit from compression when developing locally and, at the same time, avoid unnecessary work on the server thus having faster PDF creation.