Printing web pages has been a problem since the beginning of the web itself. Because a computer monitor is wider than it is tall, developing pages for the screen often results in pages that print off the edge of standard paper because it is taller than it is wide. To address the issue, web developers have come up with scripts that parse text, secondary printable page templates, and a host of other tricks, but most of them take quite a bit of time and energy to create. With the new ColdFusion MX 7, Macromedia has created a quick, easy way to make any web page printable with the introduction of the new <cfdocument> tag. This tag renders any text or images located inside the tag in the PDF or FlashPaper formats and enables you to control page aspects such as orientation, page size, headers, footers, and formatting options. So with the addition of one simple tag, you can now avoid the hassle of making printable pages, and ensure that your pages will be just as readable offline as they are online. You can implement application of the <cfdocument> tag by using it like this: <cfdocument format = "PDF"> Hello World! <img src="/books/1/325/1/html/2/my_image.gif"> </cfreport> To adjust the properties of the resulting document, you can use the following attributes:
After you have the tag in place and the attributes set, implementing the printable document is easy. Use code similar to this: <cfhttp url="http://www.yahoo.com" method="get" resolveURL="true"> <cfdocument format="PDF"> <cfoutput>#cfhttp.filecontent#</cfoutput> </cfdocument> The <cfhttp> tag specifies the URL to obtain and the <cfoutput> tag renders the page content to a PDF document (see Figure 19.29). Figure 19.29. A web page that would have printed off the page is now easily printable.As you can see, ColdFusion continues to grow in its capabilities. Being able to generate stunning reports and printer-friendly web pages is certainly one of the application's biggest steps in continuing to establish the ColdFusion platform as the most user-friendly and adaptable platforms on the market. |