Smarter ideas worth writing about.

Mobile App PDF Generation

 

Good mobile apps have a compelling user experience to initially draw in the user. However, great mobile apps combine user experience with rich data. More often than not, the mobile applications you use consume data from a back end web server. It's your job as a developer to display that data quickly and concisely using the tools provided by your chosen platform. What if you have a requirement to allow your users to export data into a PDF document? Dynamic PDF generation presents the following considerations:

  • If it's a native application, you might consider developing separate drawing routines to provide the PDF version of your custom views.
  • Does the mobile device have the horsepower to generate a PDF without comprising the user experience?
  • If it's an HTML/JavaScript app are you going to support all browsers?

If you are developing native iOS apps then you can use the UIKit and Core Graphic frameworks to generate a PDF. This requires you to draw the content through code, which could be a sizable development undertaking. The Android platform requires using third party libraries to generate PDFs. If you are working with an HTML/JavaScript mobile app, then finding a JavaScript library that can generate PDF documents on the fly without Flash while supporting all browsers is difficult.

I have been working on a medium-sized JavaScript web application, which consumes JSON data from a .NET REST web service. The website is very dynamic, utilizing JavaScript libraries such as JQuery, KnockoutJS, Amplify, and RequireJS to support a rich user experience. A requirement exists to allow users to export data into a generated PDF document across all browsers. We could not find a JavaScript library that supported all browsers and that did not require Flash. We started to look at server-side tools from Adobe, but that was an expensive alternative and required more integration and deployment resources. We turned to the tool by Microsoft called Client Side Reporting Services (RDLC) that exists with the .NET framework. Our HTML/JavaScript application has a .NET backend providing a natural choice to offload the PDF generation to the server. The integration effort was minimal and the PDFs render crisp and clean, while being cross-browser friendly.

RDLC is packaged with the .NET framework and utilizes Visual Studio as a rich designer tool. It does not require a SQL Server license or even a running instance of the database server. It only requires .NET and IIS running on the server. RDLC can consume data from a number of different data sources (SQL Server, Oracle, web services, or custom objects) and can be integrated into many applications. However, its best feature is its ability to generate PDF documents. Once the report is deployed to a web server, a simple web request (NSURLConnection on iOS or HttpConnection on Android), HTML link, or JavaScript function can load the PDF document. RDLC doesn't stop there; the same report can be exported into Word or Excel on the fly so your users can have their data in their preferred format.

I know I have skipped over all the technical jargon that describes how to build a complete working sample to export a PDF. This post is about opening your mind to the idea that an alternate tool exists to solve a problem that native and HTML/JavaScript app developers may overlook. There is a tendency to only use the tools localized to your chosen platform; however, some content cannot easily be generated without multiple browser plugins, third party libraries, or expensive server side tools. If your native or HTML/JavaScript application has a .NET back end, then look no further than Microsoft's RDLC as your means to generate dynamic PDF documents.

Share:

About The Author

Steven is a developer in Cardinal's Cincinnati Mobile Practice. He has experience with iOS, Android, as well as the Microsoft platform.