<CFDOCUMENT> Tag - ColdFusion
>> Return to CF Tag List
The <CFDOCUMENT> tag is one of the coolest tags there is! Unfortunately you won't
find it in versions of ColdFusion before MX 7. What does the thing do? It allows you to
easily generate Adobe Acrobat PDF files as well as Flash Paper files. To be honest, I have
not seen alot of sites serving up Flash Paper files (but maybe Macromedia has high hopes)!
The generating of PDF files without needing any add-ons is way cool! Basically, just place
HTML of what you want between opening and closing CFDOCUMENT tags with a few set parameters
and bingo! You have a PDF document. You can send it straight to the web browser or you can
save it as a file.
Syntax:
<CFDOCUMENT FORMAT="PDF/FlashPaper"
[FILENAME="file name"]
[OVERWRITE="Yes/No"]
[NAME="variable name"]
[PAGETYPE="page type"]
[PAGEHEIGHT="page height"]
[PAGEWIDTH="page width"]
[ORIENTATION="potrait/landscape"]
[MARGINTOP="top margin"]
<CFDOCUMENT> Comments from Macromedia LiveDocsLiveDocs Comments - coldfusion - 7 - htmldocs - 00000236.htm This is how I eliminate the invisible margin on the right hand side of PDF documents: <cfdocument format="pdf" marginright="0" marginleft="0" unit="cm"> <cfoutput> <html> <body style="position: relative; left: 60px;"> content goes here </body> </html> </cfoutput> </cfdocument>LiveDocs Comments - coldfusion - 7 - htmldocs - 00000236.htm I ran into the issue with image sizes being blown up. I found a blog entry that suggested using in vs px for the image width and adding it to the style attribute vs the width attribute of the img tag. It seemed to work. Example: <img style="width: 2in;" src="/images/citynet_csr_header.gif" border="0"/>LiveDocs Comments - coldfusion - 7 - htmldocs - 00000236.htm for wrong-sized IMG in cfdocument (which also affected cfcharts-pngs ..) check out latest cfdocument-hotfix: http://kb.adobe.com/selfservice/viewContent.do?externalId=kb402093&sliceId=1 or cum-hotfix after that. this seem to fix badly-sized IMGs Great News (after a couple of years -or so- pdf-printing can be used without that "ups.. sorry - sometimes images are not rendered correctly - try again") Thanks for that anywaysLiveDocs Comments - coldfusion - 7 - htmldocs - 00000236.htm I have a problem with <CFDOCUMENT> paginating and honoring the formatting at the same time in both PDF and FlashPaper. I removed my <HTML> and <BODY> tags because I read somewhere that they mess up <CFDOCUMENT>. If I run my report one person at a time, I can ignore pagination and the report looks fine. If the report runs to multiple pages, there is no predicting where the page will break, and there are no page numbers, but that's fine. However, when I put virtually the same code inside a <CFOUTPUT> (<CFDOCUMENT> is outside the <CFOUTPUT> because there is report data before that output) in order to run reports for multiple people, I start having problems. Originally I attempted to use <cfdocumentitem type = "pagebreak"/> right before </CFOUTPUT> to get pagination, but the result was a blank page or two at the beginning and no page break between people. My second option was to use <CFDOCUMENTSECTION> around the <CFOUTPUT> (I actually tried putting it in various places with no success.) I discovered that the pagination worked fine but I lost data formatting. 1. The font was changed to a larger size and possibly a different face. 2. Those rows that were formatted as: <table> <tr> <table> <tr> <td>Question1</td> <td>Answer1</td> <td>Question2</td> <td>Answer2</td> </tr> </table> </tr> </table> were changed to an appearance of <table> <tr> <table> <tr> <td>Question1</td> <td>Answer1</td> </tr> <tr> <td>Question2</td> <td>Answer2</td> </tr> </table> </tr> </table> There are some that were actually setup that way, and there were some set up with a single <TD>. Those tables with one or two <TD> elements remained that way, but the ones with four became two <TR> with two <TD> 3. An added factor is that the <TD> widths are table driven so as to be able to adjust how closely a question (first or third column) is followed by its answer (second or fourth column). The bugs appear to be: 1. <cfdocumentitem type = "pagebreak"/> not working inside a <CFOUTPUT>. 2. <CFDOCUMENTSECTION> changing the font and various table elements of the report.LiveDocs Comments - coldfusion - 7 - htmldocs - 00000236.htm Text clipping/chop off problem: Until there is a better fix, I have found that by setting scale="95" in the cfdocument tag solves the problem of text being chopped off at the tops and bottoms of the pages.LiveDocs Comments - coldfusion - 7 - htmldocs - 00000236.htm In addition to my previous comment... the margin: 0, padding: 0 fixed it on multiple pages, but i was still getting an extra blank page on single page documents. Adding body, html { height: auto; } to the css seems to have fixed that however.LiveDocs Comments - coldfusion - 7 - htmldocs - 00000236.htm Not sure if this has been mentioned before, (I did not read through everyone's comments) but I have found that the extra blank page inserted at the end of a cfdocument may be due to a <body> tag padding. I have eliminated it by adding body { padding: 0px; margin: 0px; } to the cfdocument's css.LiveDocs Comments - coldfusion - 7 - htmldocs - 00000236.htm Also, the documents make no mention of page size minimums, but there is one--for instance the page width must be 2 inches (which is a problem for me, because I am trying to make individual labels for printing on a label printer)LiveDocs Comments - coldfusion - 7 - htmldocs - 00000236.htm It would be nice if the docs said something about the expected extention for flashpaper. Somewhere it should just say "use swf for the extention for flash paper' (dummy)LiveDocs Comments - coldfusion - 7 - htmldocs - 00000236.htm style="border-bottom: 1px dotted #000000;" doesn't work - no border is produced... style="border-bottom: 1px dashed #000000;" or style="border-bottom: 1px solid #000000;" both work fine.LiveDocs Comments - coldfusion - 7 - htmldocs - 00000236.htm Hi all, for those looking for a quick fix to embed repeating images, or just images. One solution that found itself being very efficient was using the CFreport tag. You can also use the coldfusion report builder if you need to do this in the most easyest manner possible. You can then reuse it when needed and overwrite the image file used with cffile to update the report/document/whateveryouredoing.file : )LiveDocs Comments - coldfusion - 7 - htmldocs - 00000236.htm Basic Best Practices (or more like, best luck for me): -If creating new images set the dpi to 96 not 72. -Use inline css -Use css to insert background images (ie. background: white url(filename.jpg) no-repeat fixed; - CSS, set font-size using pt not px -Include any calls to imported files (css) within the cfdocument region - define as many cfdocument attributes as are applicable (format, pagetype, margin, backgrounvisible, fontembed) - for tables, define widths using percentages instead of absolutes - Make sure to install non-system fonts on the server that will be rendering the PDF - Only install true type fonts (using CF admin), some Type 1 fonts will ruin the formatting of the \\CFusionMX7\lib\neo-document.xml file rendering the font manager in the CF admin to break.LiveDocs Comments - coldfusion - 7 - htmldocs - 00000236.htm Brad, I've had the same problem with PDFs generated on Linux. I've had to strip all of the HTML tags out of my content before putting it into a CFDocument PDF. This is a serious limitation of CFDocument, and I sincerely hope it can be fixed with a patch!LiveDocs Comments - coldfusion - 7 - htmldocs - 00000236.htm Look at: http://www.bradwood.com/cfdocumenttest/ We are experiencing a handful of anomalies with the cfdocument tag when generating PDF's. *One* of which is that text surrounded by <u> </u> exhibits strange behavior such as extra spaces (which are underlined) magically appearing before and or after the text. Example <u>test</u> would have extra "______" at the end of it-- sometimes all the way to the end of the page. I have run 4 tests. a) PDF Generation using cfdocument on a Windows server using CF 7.0.2 b) FlashPaper Generation using cfdocument on a Windows server using CF 7.0.2 c) PDF Generation using cfdocument on a Liniux server using CF 7.0.2 d) FlashPaper Generation using cfdocument on a Liniux server using CF 7.0.2 a) Works! 51 KB File b) Works! 57 KB File c) Broken! 2 KB File!!!!!! d) Works! 56 KB File The problem does in fact seem to be limited to PDF files on Linux servers. And why the heck is the file so small??? All of these test files are available for you to view at www.bradwood.com/cfdocumenttest. Please check them out to prove I'm not completely insane. Thanks. ~BradLiveDocs Comments - coldfusion - 7 - htmldocs - 00000236.htm I have noticed a bit of funkyness with background images. If i were to use an image 1px tall and repeat it among the y axis, it seemed to enlarge it in size by about 10 times. I am calling the background image on a div by css using background-image: url(); Without the use of the background-repeat: repeat-y; it would not display the image at all (although it would display it in a html file). If I re-made the background image to something very large, it would work correctly. So instead of a 1px image that would repeat 1000 times on the y axis, I made it 1000px tall and it seemed to fix the problem. Hope that helps somebody.LiveDocs Comments - coldfusion - 7 - htmldocs - 00000236.htm Solved: margen issue ... Try to define the style element body in a css file with the following params: margin 0px; padding: 0px; ... The "padding 0px;" is the most importend param ... hope this helps ... pirreLiveDocs Comments - coldfusion - 7 - htmldocs - 00000236.htm Coreth: cfdocument will use a stylesheet that is specified for print media. ex/ <link rel="stylesheet" type="text/css" href="myPrintStyle.css" media="print" />LiveDocs Comments - coldfusion - 7 - htmldocs - 00000236.htm Another thing to remember is that CFDOCUMENT does not read authenticated sessions so if you are doing a PDF report in a password protected area of your site it's best to put the imags in a non-password protected folder.LiveDocs Comments - coldfusion - 7 - htmldocs - 00000236.htm Regarding missing images in generated pdf files: I've seen many workarounds suggested but I found a really simple solution. Use the file: protocol in the img src if the file is local. I.e. src=file:///c:/somedir/somefile.gif. Note that 3 slashes are necessary after file:. Hope this helps someone.LiveDocs Comments - coldfusion - 7 - htmldocs - 00000236.htm Acting on the above tip to try 65/75% for the image, I noticed that even at 85 it was running close to the border so I tried 100% for the height and width and BOOM, it works! So if you're having image scaling issues, try setting the td cell width height to the image size and set the height/width of the image to 100%.LiveDocs Comments - coldfusion - 7 - htmldocs - 00000236.htm It appears that images are cached when using the cfdocument tag. This is great until you have an image that needs to change everytime the document is rendered. It seems like there needs to be an attribute called cacheimages or something. To get around this, I am adding ?foo=#DateFormat(now(),'yyyymmddhhmmss')# to the end of my image src.LiveDocs Comments - coldfusion - 7 - htmldocs - 00000236.htm There is a tech note: "Flash Player 8 issue with cfdocument and cfreport" at http://www.macromedia.com/cfusion/knowledgebase/index.cfm?id=a8a77279LiveDocs Comments - coldfusion - 7 - htmldocs - 00000236.htm I applied HotFix 3 to ColdFusionMX7 and I was still having the image problem. The work around I found that seems to be working 100% of the time is to, create the table cell with the same Height and Width of the image and instead of using the IMG tag, I set the table cells background to my image. <tr> <td width="490" height="118" background="Images/my_image.gif"> </td> </tr> Keep in mind, backgroundvisible attribute must be set to 'yes'.LiveDocs Comments - coldfusion - 7 - htmldocs - 00000236.htm Will CFDocument listen to the media attribute of the link tag, when including CSS? If yes, does it respond as screen or print? or something else?LiveDocs Comments - coldfusion - 7 - htmldocs - 00000236.htm I'm not sure if this will help anyone... I'm not even sure if it's good form... However, I managed to include a style sheet in the following way: <cffile action="read" file="c:/my_app/main.css" variable="myStyle"> <cfdocument format="pdf" filename="..." overwrite="yes"... pagetype="letter"> <html> <head> <title></title> </head> <body> <cfdocumentsection> <cfdocumentitem type="header">...</cfdocumentitem> <style><cfoutput>#myStyle#</cfoutput></style> <p class="larger_headings"><cfoutput>My Report</cfoutput></p><br> <p class="content"><cfoutput>My content</cfoutput></p> <cfdocumentitem type="footer">...</cfdocumentitem> </cfdocumentsection> </body> </html> </cfdocument>LiveDocs Comments - coldfusion - 7 - htmldocs - 00000236.htm When using the cfdocument to generate a pdf from another webpage, it breaks up the page into pages on the PDF document. Is there a way to make it shrink everything down to the size of paper i have specified: <cfdocument format="pdf" pagetype="legal">LiveDocs Comments - coldfusion - 7 - htmldocs - 00000236.htm iots190 You have to put the <link> tag to your css stylesheet inside the <cfdocument> tag.LiveDocs Comments - coldfusion - 7 - htmldocs - 00000236.htm Does anyone know if cfdocument can use the style sheets when included using <link>? When I run the page as HTML, it uses my style sheets, but when I try it with cfdocument, its just plain. Here is the code that is between the cfdocument tags. Thanks! :) <!-- Start Employee Site headwhite.txt --> <script language="javascript" src="/ssi/apps/browserdetect.js"></script> <script language="javascript" src="/ssi/apps/internal_cssdefinition.js"></script> <noscript> <link rel="stylesheet" type="text/css" href="\css\apps\app.css" /> </noscript> <!-- End Employee Site headwhite.txt --> <table width="50%" cellspacing="0" cellpadding="0" class="separatedSM"> <tr class="HeaderRow"> <td>Name</td> <td>Role</td> </tr> <tr class="RowOne"> <td>Bill</td> <td>Lead</td> </tr> <tr class="RowTwo"> <td>Susan</td> <td>Principal Writer</td> </tr> </table>LiveDocs Comments - coldfusion - 7 - htmldocs - 00000236.htm You can't use the cfdocument.currentpagenumber and cfdocument.totalpagenumber scopes outside the cfdocumentitem tags. Is this a bug or is designed such as? Is there a trick to use it inside th cfdocument body? I need the evaluation of page number to display different data in pages body. Could someone reply??LiveDocs Comments - coldfusion - 7 - htmldocs - 00000236.htm I agree that it doesn't seem right and I have searched high and low but haven't seen it reported as a bug or included in the documentation on using <cfdocument> I'm no MM expert but in my opinion it should be considered a bug and fixed on their next upgrade.[Top]
Recommended Books
COLDFUSION MX Web Application Construction Kit (5th Edition)
Authors: Ben Forta and Nate Weiss
1500 pages
[Top]
Web Sites
[Top]