Wednesday, February 14, 2018

Exporting Html to Pdf using only JavaScript


Sometimes you get those requests to "export to pdf" a given web page you developed. Turns out that sometimes, and just sometimes =), it's too complex to produce a custom report, the time to setup a reporting server, the costs, etc, are too impeditive. What can we do?

It can be easily done using two popular javascript libraries: jQuery and the excellent JsPdf.

Here's a snippet, feel free to play it on your end. It works even on your local machine, not needing to deploy it to a webserver.

A simple example

Here's the source code for it
Hope it helps =)

See Also

Why you should start using .Net Core
Package Management in .Net Core
Importing CSVs with .Net Core and C#Exporting a CSV generated in-memory in Asp.Net with C#
Building and Running Asp.Net Core apps on Linux
Asp.Net / Asp.Net Core: Generating views in the backend

For more posts on .Net Core, please click here.

References

jQuery - Home
JsPdf - Home
JsPdf - Documentation