Creating Printable Web Pages


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:

  • Format Determines whether the output will be PDF or FlashPaper format.

  • MarginTop Sets the top margin for the output document. Default is .5 inches.

  • MarginBottom Sets the bottom margin for the output document. Default is .5 inches.

  • MarginLeft Sets the left margin for the output document. Default is .5 inches.

  • MarginRight Sets the right margin for the output document. Default is .5 inches.

  • BackgroundVisible Determines whether the web page's background color or image is printed.

  • Orientation Specifies landscape or portrait. Default is portrait.

  • PageType Specifies one of nine different output file types: letter, legal, A4, A5, B4, B5, B4-JIS, B5-JIS, and custom.

  • PageWidth Used with the custom page type, enables you to set a custom page width.

  • PageHeight Used with the custom page type, enables you to set a custom page height.

  • Encryption In the PDF format, this attribute enables you to choose from 128-bit, 40-bit, or no encryption.

  • OwnerPassword When encryption is enabled, this tag sets an owner password.

  • UserPassword When encryption is enabled, this tag sets a user password.

  • Permissions Sets various permission types.

  • Unit Determines whether your numeric attributes are measured in inches or centimeters.

  • FontEmbed Embeds the fonts within the document for accurate rendering.

  • Filename Specifies where to save the output file.

  • Overwrite Determines whether existing files with the same name can be overwritten.

  • Name Saves the result content to a ColdFusion variable that can be used later in the document.

  • Scale Specifies the zoom factor for the document.

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.



Special Edition Using Macromedia Studio 8
Special Edition Using Macromedia Studio 8
ISBN: 0789733854
EAN: 2147483647
Year: 2003
Pages: 337

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net