私はフードの下に行き、iText を使用します。これを行うことで、非常に堅牢な印刷フレームワーク (フォームの印刷用) とレポート フレームワーク (表形式のレポート) を作成できました。何年にもわたって微調整してきましたが、何十万行も問題なく PDF を生成できます。それは 4 人の子供を深くすることができ、多くの機能/設定を備えています。広くてごめんなさい。あなたがこの道を行くなら、私は具体的に助けることができます.
onApplicationStart でJavaLoader ( http://javaloader.riaforge.org/ ) を使用して、iText (およびアプリで必要な他の jar) をロードします...
<!--- note, this is actually a harcoded UUID value --->
<cfset MyUniqueKeyForJavaLoader = "1111-2222-3333444455556666">
<!--- if we have not already created the javaLoader --->
<cfif not structKeyExists(server, MyUniqueKeyForJavaLoader)>
<!--- construct an array containing the full path to the jars you wish to load --->
<cfset pathArray = arrayNew(1)>
<cfset arrayAppend(pathArray, expandpath('jars/iText-2.1.3.jar'))>
<!---<cfset arrayAppend(pathArray, expandpath('jars/iText-5.0.6.jar'))>--->
<cfset arrayAppend(pathArray, expandpath('jars/IDADataMatrix.jar'))>
<cfset arrayAppend(pathArray, expandpath('jars/LinearBarCode.jar'))>
<cfset arrayAppend(pathArray, expandpath('jars/barcodeencoder.jar'))>
<cfset arrayAppend(pathArray, expandpath('jars/sshcommandexecutor.jar'))>
<!--- <cfset arrayAppend(pathArray, expandpath('jars/jsch-0.1.40.jar'))> --->
<cflock scope="server" type="exclusive" timeout="10">
<!--- verify again the javaloader was not already created --->
<cfif not StructKeyExists(server, MyUniqueKeyForJavaLoader)>
<cfset server[MyUniqueKeyForJavaLoader] = createObject("component", "javaloader.JavaLoader").init(pathArray)>
</cfif>
</cflock>
</cfif>
次に、レポート フレームワークで、これがすべての初期化を開始する方法です。(これはほんの小さなスニペットです。これにはさらに多くの内容がありますが、必要に応じて、いじり始めるには十分なはずです)。
<cfscript>
pathAndFile = request.reportDir.fpath&request.reportDir.pdfFile;
session.reports[libRptId].pathAndFile = pathAndFile;
loader = server['1111-2222-3333444455556666']; //Our iText version which currently is 2.1.3 (yes, we need to update soon)
document = loader.create("com.lowagie.text.Document");
PdfWriter = loader.create("com.lowagie.text.pdf.PdfWriter");
FileOutputStream = createObject("java", "java.io.FileOutputStream");
myFile = CreateObject("java","java.io.File").init(pathAndFile); //Only used for getting the file size to display on screen in real-time as the pdf is being generated
Color = createObject("java", "java.awt.Color");
element = loader.create("com.lowagie.text.Element");
Chunk = loader.create("com.lowagie.text.Chunk");
PageSize = loader.create("com.lowagie.text.PageSize");
HeaderFooter = loader.create("com.lowagie.text.HeaderFooter");
Rectangle = loader.create("com.lowagie.text.Rectangle");
Paragraph = loader.create("com.lowagie.text.Paragraph");
PdfPCell = loader.create("com.lowagie.text.pdf.PdfPCell");
PdfPTable = loader.create("com.lowagie.text.pdf.PdfPTable");
Phrase = loader.create("com.lowagie.text.Phrase");
Font = loader.create("com.lowagie.text.Font");
FontFactory = loader.create("com.lowagie.text.FontFactory");
</cfscript>
<!--- Define our different fonts --->
<cfset fontTitle = FontFactory.getFont("Arial", 10, Font.BOLD, Color.BLACK)>
<cfset fontSubRptTitle = FontFactory.getFont("Arial", 10, Font.BOLDITALIC, Color.BLACK)>
<cfset fontStandard = FontFactory.getFont("Arial", 8, Font.NORMAL, Color.BLACK)>
<cfset fontHeader = FontFactory.getFont("Arial", 9, Font.NORMAL, Color.GRAY)>
<cfset fontFooter = FontFactory.getFont("Arial", 9, Font.NORMAL, Color.GRAY)>
<cfset fontColHeader = FontFactory.getFont("Arial", rpt.fontsizeLabel, Font.BOLD, Color.BLACK)>
<cfset fontData = FontFactory.getFont("Arial", rpt.fontsize, Font.NORMAL, Color.BLACK)>
<cfset marginTop = round(72 / (100 / (rpt.marginTop * 100))) >
<cfset marginright = round(72 / (100 / (rpt.marginright * 100))) >
<cfset marginbottom = round(72 / (100 / (rpt.marginbottom * 100))) >
<cfset marginleft = round(72 / (100 / (rpt.marginleft * 100))) >
<!--- Page Setup (PageSize and Margins) For the margins 18 = .25inches --->
<cfif rpt.pagetype eq "letter">
<cfif rpt.orientation eq "portrait">
<cfset document = document.init(PageSize.LETTER, marginleft, marginright, marginTop, marginbottom)>
<cfelse><!--- Landscape --->
<cfset document = document.init(PageSize.LETTER.rotate(), marginleft, marginright, marginTop, marginbottom)>
</cfif>
<cfelseif rpt.pagetype eq "legal">
<cfif rpt.orientation eq "portrait">
<cfset document = document.init(PageSize.LEGAL, marginleft, marginright, marginTop, marginbottom)>
<cfelse><!--- Landscape --->
<cfset document = document.init(PageSize.LEGAL.rotate(), marginleft, marginright, marginTop, marginbottom)>
</cfif>
<cfelseif rpt.pagetype eq "ledger">
<!--- We found that ledger logic is backward from letter and legal. Long edge is portrait 11 X 17 and landscape mode = 17 X 11 --->
<cfif rpt.orientation eq "portrait">
<cfset document = document.init(PageSize.LEDGER.rotate(), marginleft, marginright, marginTop, marginbottom)>
<cfelse><!--- Landscape --->
<cfset document = document.init(PageSize.LEDGER, marginleft, marginright, marginTop, marginbottom)>
</cfif>
</cfif>
<cfset writer = PdfWriter.getInstance(document, FileOutputStream.init(pathAndFile))> <!--- Init the variable "document" that we write to --->