Solved

Print Page Button in ColdFusion

Posted on 2010-08-25
5
958 Views
Last Modified: 2013-12-24
Hi,
I'm sure I'm not the first to ask this so please be patient.

I have a dynamic "Order Detail" page that I would like to have the user be able to print using a PRINT button.

To do this I will need a "printer friendly" version of the page without the header/footer and some graphic border changes.

I can create a separate CF template (for printing) and dynamically build the page again when the PRINT button is hit - BUT there is a small chance that the data could change in between.

How is this done with dynamic pages - to create printer friendly versions without rebuilding the data in CF.  Is CFdocument involved?

Thanks in advance (but confused)
hefterr
0
Comment
Question by:hefterr
  • 3
  • 2
5 Comments
 
LVL 4

Expert Comment

by:JohnHowlett
ID: 33526126
Link the print button to a new page and wrap the cfdocument tag around your current page to output the page as a [printer friendly] pdf:


<cfdocument format = "PDF" pagetype = "A4" orientation = "portrait">
    <cfinclude template="[Your_original_file].cfm" />
</cfdocument>
0
 
LVL 1

Author Comment

by:hefterr
ID: 33526213
Hi JohnHowlett,
Thanks for an answer so quickly.

I am basically doing this - but the new page retrieves again the data from the DB and it's possible an order status (for example) has changed when re-retrieved by the new page.  It's not just making it printer friendly - but also keeping the data the same.

hefterr
0
 
LVL 4

Accepted Solution

by:
JohnHowlett earned 500 total points
ID: 33526267
OK. In which case I would try and save the information to a file - which is later called upon to print within the cfdocument tag.

To save the content:
<cfsavecontent variable = "theContent">
...
[currrent cfm page]
...
</cfsavecontent>

Then save the variable 'theContent' to a file (probably best to save it to an html file), using cffile.
If the Print button is pressed, then use cfdocument:

<cfdocument format = "PDF" pagetype = "A4" orientation = "portrait">
    <cfinclude template="[Your_saved _html_file].html" />
</cfdocument>

0
 
LVL 1

Author Comment

by:hefterr
ID: 33527320
Hi JohnHowlett:
I guess one way or another you have to save the "state" of the data in advance in case the print button is subsequebtly hit.  Can you use the "cfsavecontent" and also output a page at the same time with the same HTML/CF?

This sounds like high overhead as the print page button will not be frequently used.  I found another post on EE using a bit of Javascript that may help out:

http://www.experts-exchange.com/Web_Development/Software/ColdFusion_Studio/Q_25271624.html

Thanks for your help!!!
hefterr
0
 
LVL 1

Author Comment

by:hefterr
ID: 33531343
I guess my question is also "best practices".

Is it acceptable to go to (or pop up) a separate window that "rebuilds" the page with simpler formating (omit the header/footer and remove certain graphics). for printing?  The downside, is that the data could possible change from the original page if (for example) the status of an order changed?

Or is this technique (I mentioned) a standard procedure on sites that provide "printer friendly version" button on a page.  The interval is very small (I would imaging) between showing the original page and rebuilding the page if the user hits the "printer friendly" button.

Thanks in advance,
hefterr
0

Featured Post

Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Have you ever sent email via ColdFusion and thought of tracking this mail to capture the exact date and time when the message was opened ?  If yes, then this article is for you ! First we need a table user_email with columns user_id , email , sub…
One of the typical problems I have experienced is when you have to move a web server from one hosting site to another. You normally prepare all on the new host, transfer the site, change DNS and cross your fingers hoping all will be ok on new server…
This Micro Tutorial hows how you can integrate  Mac OSX to a Windows Active Directory Domain. Apple has made it easy to allow users to bind their macs to a windows domain with relative ease. The following video show how to bind OSX Mavericks to …
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…

813 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now