Question

I have an online document which shows a report built dynamically from database values and application values. What type of report it shows to the user is based on various security permissions that a user has. So generally a Manager can see a full report, but a Customer Service adviser will only see part of that same report. It does this just fine.

But now the same report that is seen 'online' also needs a PDF version. I have started to build a new .CFM template which should handle rendering a PDF version of the same document. Its essentially a duplicate of the online version but with basic CSS formatting and change to way the document is structured (e.g. no jquery tabs). It still has the conditional logic in it.

But I have now come to a stage where I think it may be difficult to handle two files for the same document. What I mean is that if something changes in the 'online' version, then code in the PDF version also has to change.

Is this the only way to go about this or is there any better method of tackling exporting to PDF from a webpage? I just feel I'm doing it wrong.

Was it helpful?

Solution 2

The cfdocument tag allows you to dynamically create PDF files. You can allow users to choose their output formats in a variety of ways.

The one I use most often is to include a select control on the form where the user enters their search parameters. My choices are generally HTML or Excel, but it's the same general idea. When processing the form submission, I do the display stuff last. It will resemble this:

<cfif form.showas is 'html'>
code for web page
<cfelse>
code for something else
<cfif>

Since your choices are HTML or PDF, the cfsavecontent tag might come in handy.

If your page is not accessed from a form, you could use cfsavecontent to generate a session variable with all the output. Then, on your web page, offer a link or button or something that allows the user to render as PDF. All you do is combine the session variable with the cfdocument tag and Bob's your uncle.

OTHER TIPS

wkHTMLToPDF is a pretty good option for doing this.

I'm afraid your question - whilst a good one - will get closed due to it being too subjective to answer definitively.

As for the logic, possibly something like this

if (requestIsForPdfVersion){
    call wkHTMLToPDF passing the *html* version of the URL to it
    use cfcontent to set the mimetype and return the file
}
business as usual for HTML
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top