Advertisement
jamo

ColdFusion FontList - PDF/Flash

Feb 14th, 2012
241
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. <!--- FontList: Some installed fonts may work in both PDF & Flash formats, but there's no guarantee.
  2. This script will test available fonts using CFDocument and generates a PDF or Flash document.
  3. Requirement: ColdFusion 8 or 9 --->
  4. <CFSET CFPassword = "xxxxxxxxx">
  5. <CFSET PhysicalDir = GetDirectoryFromPath(GetCurrentTemplatePath())>
  6. <CFSET WebDir = "/FontList">
  7. <!--- Get Font Lists --->
  8. <cfinvoke component="cfide.adminapi.administrator" method="login" adminPassword="#CFPassword#">
  9. <CFSET FontStruct = createObject("component", "cfide.adminapi.runtime").getFonts()>
  10. <CFSET SystemFonts = ListSort(StructKeyList(FontStruct.SystemFonts), "textnocase")>
  11. <CFSET UserFonts = ListSort(StructKeyList(FontStruct.Userfonts), "textnocase")>
  12.  
  13. <cfsavecontent variable="DefaultSample"><CFOUTPUT><h1>Header</h1>
  14.  
  15. <div style="font-size:9px !important;">This text is set to 9px and should be small.</div>
  16.  
  17. The <u>quick</u> <b>brown</b> <i>fox</i> jumped over the lazy dog.
  18. </CFOUTPUT></cfsavecontent>
  19.  
  20. <CFPARAM NAME="Attributes.Content" DEFAULT="#DefaultSample#">
  21. <CFPARAM NAME="Attributes.Fonts" DEFAULT="#ListFirst(userFonts)#">
  22. <CFIF NOT LEN(Attributes.Fonts)><CFSET Attributes.Fonts = ListFirst(userFonts)></CFIF>
  23. <CFIF NOT LEN(trim(Attributes.Content))><CFSET Attributes.Content = DefaultSample></CFIF>
  24.  
  25. <CFOUTPUT>
  26. <form action="./fontlist.cfm" method="post">
  27. <table class="vTable2">
  28. <tr><td><b>Fonts:</b></td><td><b>Sample Text/HTML:</b></td><tr>
  29.  
  30. <tr valign="top"><td><div style="height:300px; overflow-y:scroll;"><CFLOOP LIST="#userFonts#" INDEX="this">
  31. <div><label for="#Request.KeyString(This)#"><input id="#Request.KeyString(This)#" type="checkbox" name="Fonts" value="#This#"<CFIF ListFindnocase(Attributes.Fonts,this)> checked</CFIF>>#This#</label></div></CFLOOP>
  32. <b>SYSTEM FONTS</b><CFLOOP LIST="#SystemFonts#" INDEX="this"><CFIF NOT Listfindnocase(userFonts,this)>
  33. <div><label for="#Request.KeyString(This)#"><input id="#Request.KeyString(This)#" type="checkbox" name="Fonts" value="#This#"<CFIF ListFindnocase(Attributes.Fonts,this)> checked</CFIF>>#This#</label></div></CFIF></CFLOOP>
  34. </div>
  35. </td><td><textarea name="Content" rows=#ListLen(userFonts)# cols=50 style="height:300px;">#trim(Attributes.Content)#</textarea></td></tr>
  36.  
  37. <tr><td colspan=2 class="center" style="background-color:##c0c0c0;"><input name="go" type="submit" value="Test Fonts - PDF"> <input name="go" type="submit" value="Test Fonts - Flash"></td></tr>
  38. </table>
  39. </form>
  40. </CFOUTPUT>
  41. <CFIF NOT ISDefined("Attributes.Go")><CFEXIT></CFIF>
  42.  
  43. <cfsavecontent variable="TheHTML"><CFOUTPUT><CFLOOP LIST="#Attributes.Fonts#" INDEX="this">
  44. <fieldset style="padding-bottom:25px;"><legend style="background-color:##e0e0e0;"><span style="font-family:Arial !important;">#This#  (#DateFormat(Now(),'m/d/yyyy')# #timeFormat(Now(),'h:mm tt')#)</span></legend>
  45. <div style="font-family:#this# !important;">
  46. #Attributes.Content#</div>
  47. </fieldset></CFLOOP>
  48. </CFOUTPUT></CFSAVECONTENT>
  49.  
  50.  
  51. <CFIF Findnocase("Flash",Attributes.Go)>
  52.  
  53.     <cfdocument filename="#PhysicalDir#FontList.swf" format="flashpaper" pagetype="letter" margintop="0.1" marginbottom="0.1" marginright="0.1" marginleft="0.1" orientation="portrait" unit="in" encryption="none" fontembed="Yes" backgroundvisible="Yes" overwrite="yes"><CFOUTPUT>#TheHTML#</CFOUTPUT></cfdocument>
  54.     <CFSET SWFWebPath = "#WebDir#/FontList.swf?a=#GetTickCount()#">
  55.     <CFOUTPUT><object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="https://active.macromedia.com/flash2/cabs/swflash.cab##version=4,0,2,0" id="test" name="test" width="800" height="400">
  56.     <param name="movie" value="#SWFWebPath#">
  57.     <param name="quality" value="high">
  58.     <param name="bgcolor" value="##FFFFFF">
  59. <embed wmode="opaque" src="#SWFWebPath#" quality="high" bgcolor="##FFFFFF" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/shockwave/download/index.cgi?P1_Prod_Version=ShockwaveFlash" width="800" height="400">
  60. </object></CFOUTPUT>
  61.  
  62. <CFELSE>
  63.     <cfheader name="content-disposition" value="attachment; filename=FontTest.pdf">
  64.     <cfdocument format="pdf" pagetype="letter" margintop="0.1" marginbottom="0.1" marginright="0.1" marginleft="0.1" orientation="portrait" unit="in" encryption="none" fontembed="Yes" backgroundvisible="Yes" overwrite="yes"><CFOUTPUT>#TheHTML#</CFOUTPUT></cfdocument>
  65. </CFIF>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement