AspAlliance.com LogoASPAlliance: Articles, reviews, and samples for .NET Developers
URL:
http://aspalliance.com/articleViewer.aspx?aId=114&pId=-1
How to implement a "Render this page in PDF"
page
by Markus Schneider
Feedback
Average Rating: This article has not yet been rated.
Views (Total / Last 10 Days): 19481/ 30

Introduction
Step 1: Prepare the HTML pages

In order to create useful PDFs from HTML you first need to prepare the html Templates in a way that they can be printed without errors and malformating. Many state-of-the-art websites got a print button anyway or may be printed as they are without limitations. If your site is missing this feature you may create an additional dynamic template that ignores menus, banner, teasers etc. If your site isn't dynamic you should consider switching to a content management system!

Note that there is a parameter called landscape if your HTML pages are too wide for the default portrait format.
The Code
Step 2: Render some test pages to PDF

Before you start writing code be sure to test your printable pages by using our Test Form You may also test the html2pdf parameters like landscape, JPG quality, Hyperlinks etc. If you do not want to use the default values be sure to include them in your code.

Step 3: Write the code

There are several possibilities to set up your site for html2pdf.

A) If you simply want to render a standard page (not a special print page) you just need to put the following link to your "render this page to PDF button": http://html2pdf.adfinis.com/refer2pdf.php The Script will request the referer and render it to PDF.

B) If you want to insert the link in your current code the dynamic link on the "render this page to PDF button" should look something like this: http://html2pdf.adfinis.com/render.php?URL=encoded printer friendly full URL of current page&jpeg=60

Please note that the parameter jpeg is like all others (exept url!) optional!

C) If you would like to leave the current code of your pages untouched you may create a simple refer2pdf file and copy it on your server. Here are some examples for such a file:

refer2pdf.aspx using VB.NET

refer2pdf.asp using VBScript

This article was contributed by Markus Schneider and he can be reached at schneider@mms.ch


Product Spotlight
Product Spotlight 

©Copyright 1998-2024 ASPAlliance.com  |  Page Processed at 2024-03-28 5:18:19 AM  AspAlliance Recent Articles RSS Feed
About ASPAlliance | Newsgroups | Advertise | Authors | Email Lists | Feedback | Link To Us | Privacy | Search