Case Study: Creating PDFs From ASP.NET Automatically
We completed another interesting project using technologies that we don't normally use - creating PDFs from ASP.NET. Our client supplies materials around the world to research institutions. For decades, every year they produced a paper-based catalogue - an impressive heavyweight document - which they send to all their clients and anybody else who wanted one anywhere in the world. This was a successful marketing strategy and great customer service, but extremely expensive and very time-consuming. They approached us to find out if we could automate the production of their product catalogue and make it downloadable from their web site. We said "Of course!" Then we had find out how to do that.
PDFs from ASP.NET
Since their web site technology stack includes ASP.NET, C# code, and Microsoft SQL Server, it made sense to source a software library that would easily fit in. We looked at several PDF libraries for ASP.NET and found the most popular to be iText - but when we received a license quotation from them we realised it would not be financially viable to use this software. In the end we plumped for PDFSharp and MigraDoc.
Getting the data
Once installed, these libraries allow programmers to create PDF documents, add pages, images, paragraphs, tables of data, tables of contents, headers, footers, page numbers - exactly what we wanted. First we created software classed that would extract the relevant data from the database, using the specified currency - our clients sell in GBP, Euros, US dollars, Japanese Yen and Swiss Francs. Then we created classes using PDFSharp that would inject the product data in the right format and right currency into the document. Once that was done, we focussed on building a table of contents.
Tables of Contents
Seemingly simple, the table of contents turned out to be one of the most challenging parts of the project. The client wanted two nested levels of contents - the main material and within that, the form of the material (sheet, rod, wire etc). All these had to linked to the relevant pages in the document, but of course it's impossible to know which pages those products might appear on. Fortunately PDFSharp provides a way of setting up a bookmark and taking care of the page numbers itself - a very handy feature which makes internal linking easy.
Finally we added a full-page cover image with the company's logo, a terms and conditions page and introduction pages. We added headers and footers to the product pages with the company's logo as a watermark to add polish and panache to the finished product.
Automatically generating the catalogue
The last piece of the project was to get the catalogue to be generated daily in each of the five currencies. To do this we set up a .net page which generates the catalogues and saves to the server's filesystem, making them available to be linked to for download. We set up a scheduled task to allow this to happen daily at 5am. Finally, we added links to the catalogues from all the relevant points of the web site.
This automatic system now does away with the heavy, expensive and out-of-date catalogue. Now our client can point their customers to a brand new downloadable catalogue that is produced every day so has the most up-to-date prices. They will save considerable amounts by not having to send the paper-based catalogue around the world. And customers can now download the catalogue in their preferred currency at any time from anywhere in the world. Visit the client site