I found the Coldfusion .pdf writer to be too slow for my use, and I
wrote a simple .pdf writer component that accepts a comma separated list
of .tiff files and writes out a .pdf file. I have been using it
successfully now for about 4 months, writing on average 1000 .pdf's a
night composed of between 2 and 20 pages each. Here is the component if
it will help you! It uses the iText java .pdf library
(http://www.lowagie.com/iText/) The component will handle multi-page
tiff's as well.
<cffunction name="writePdfFromTiffs" output="false"
returntype="string" hint="This will output a .pdf file containing
multiple tiff images">
<cfargument name="pdfOutput" required="true" type="string"
hint="Provide a full path to output your PDF too">
<cfargument name="tiffList" required="true" type="string"
hint="Provide a comma seperated list of tiff images to include">
<!---// This code was modified from code provided by bryan AT
electricedgesystems D0T com, thanks a ton! //--->
<!---// Declare local variables to keep everything clean
//--->
<cfset var cb = '' />
<cfset var curFile = '' />
<cfset var ra = '' />
<cfset var comps = '' />
<cfset var i = '' />
<cfset var img = '' />
<cfset var writer = '' />
<cfset var TiffImage = '' />
<cfset var PdfFile = '' />
<cfset var Document = '' />
<cfset var Image = '' />
<cfset var Paragraph = '' />
<cfset var PdfContentByte = '' />
<cfset var PdfWriter = '' />
<cfset var RandomAccessFileOrArray = '' />
<!---// Opan file system I/O to write pdf too //--->
<cfset PdfFile =
createObject("java","java.io.FileOutputStream").init(arguments.pdfOutput
)>
<!---// Init the text.document object //--->
<cfset Document = createObject("java",
"com.lowagie.text.Document").init()>
<!---// Create pagesize argument so I can set new page sizes
//--->
<cfset PageSize = createObject("java",
"com.lowagie.text.PageSize") />
<!---// Init the text.image object //--->
<cfset Image = createObject("java", "com.lowagie.text.Image")>
<!---// Create our default paragraph object to contain our
images //--->
<cfset Paragraph = createObject("java",
"com.lowagie.text.Paragraph")>
<!---// not sure what this does, but it needs to be here
//--->
<cfset PdfContentByte = createObject("java",
"com.lowagie.text.pdf.PdfContentByte")>
<!---// Create PDFWriter class //--->
<cfset PdfWriter = createObject("java",
"com.lowagie.text.pdf.PdfWriter")>
<!---// Create array to contain image //--->
<cfset RandomAccessFileOrArray = createObject("java",
"com.lowagie.text.pdf.RandomAccessFileOrArray")>
<!---// Load TIFF image handling //--->
<cfset TiffImage = createObject("java",
"com.lowagie.text.pdf.codec.TiffImage")>
<!---// Assign the page size //--->
<cfset document.setPageSize(PageSize.Letter) />
<!---// Set page margins to all 10 //--->
<cfset document.setMargins(10,10,10,10) />
<!---// Create instance of writer //--->
<cfset Writer = PdfWriter.getInstance(document, PdfFile)>
<cftry>
<!---// Open document for writing //--->
<cfset document.open()>
<cfset cb = writer.getDirectContent()>
<!---// Loop through list of files provided as an
argument and add each to our pdf //--->
<cfloop list="#arguments.tiffList#" delimiters=","
index="curFile">
<!---// stuff file into memory //--->
<cfset ra =
RandomAccessFileOrArray.init(curFile)>
<!---// read file and determine number of pages
in TIFF //--->
<cfset comps = TiffImage.getNumberOfPages(ra)>
<!---// loop over number of pages and add each
one to the PDF //--->
<cfloop index="i" from="1" to="#comps#">
<cfset img =
TiffImage.getTiffImage(ra,javacast("int",i))>
<cfset img.scaleToFit(592, 772)>
<cfset img.setAbsolutePosition(10,10)>
<cfset cb.addImage(img)>
<!---// force new page after each image is
added //--->
<cfset document.newPage()>
</cfloop>
<!---// Close each file after a loop //--->
<cfset ra.close()>
</cfloop>
<!---// close document, this will write the pdf to the
filesystem //--->
<cfset document.close()>
<!---// Return success //--->
<cfreturn 'Success' />
<!---// Catch any errors and return failed //--->
<cfcatch type="any">
<cfreturn 'Failed' />
</cfcatch>
</cftry>
</cffunction>
-----Original Message-----
From: Peter Legg [mailto:[EMAIL PROTECTED]
Sent: Monday, June 05, 2006 10:54 AM
To: CF-Talk
Subject: Re: Document Upload/Retrieval Security
Russ, how do you do it and how many and what size documents do you
typically have? How long does it take to convert say 10 documents to
one pdf?
Thanks, Peter
>I would convert everything to a single pdf (not sure if there's a
>cheap/easy way to do this from CF), but that's what I usually do with
my documents.
>
>Russ
>
>>
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~|
Message: http://www.houseoffusion.com/lists.cfm/link=i:4:242414
Archives: http://www.houseoffusion.com/cf_lists/threads.cfm/4
Subscription: http://www.houseoffusion.com/lists.cfm/link=s:4
Unsubscribe: http://www.houseoffusion.com/cf_lists/unsubscribe.cfm?user=89.70.4
Donations & Support: http://www.houseoffusion.com/tiny.cfm/54