Curt asks:
I am wondering what you do if you are creating a large pdf. I am using <cfdocument> to create a pdf that ends up being about 1500 pages. The file size is about 150MB and it obviously takes forever to create the document. Is there some other better way to create large pdf files. The application creates statements for the customer on a monthly basis.
Wow, 1500?? As much as I love ColdFusion, I would have assumed that would have brought down the server. If you are only making the PDF once a month, then you probably want to ensure that a web site user isn't the one making it. By that I mean, don't punish some poor user and make him wait the many minutes (hours?) it would take to make the PDF. Use something like the ColdFusion Schedular to generate the PDF, and I'd highly recommend doing it during off hours.
Another tip I'd recommend, and something I did at the ColdFusion Cookbook, was to find parts of the PDF that don't change, like title pages, legal notices, that kind of junk. Generate those pages and save them forever. Generate the rest of the document, and use CFPDF to merge the old PDFs and the new PDFs together into a final PDF.
Is anyone else pushing CFDOCUMENT this far?
Archived Comments
I'd say dedicate an instance or an entire server to generate the document.
Although not cfdocument, but we have successfully utilized Apache FOP in our environment has allowed us to produce real complex PDF reports. Some of our report contains Indices, footnotes, markers etc. Surely there is some learning curve to FOP but once you understand the XML syntax everything else just falls into place.
This might be a good opportunity for threads. I'm assuming since it takes so long to create the pdf it would be OK if it ran in the background and was available later?
The other thing to consider is CFREPORT -- on one of our projects we have to create a mass mailing/mail merge based on the users in the system. We were looking at something that was taking close to 15 minutes to generate using CFDOCUMENT to create a PDF of about 1,000 pages. Switched to CFREPORT because it gave us much more reliable control and it took about 30 seconds. At first, I didn't think it had worked or that we had left a MAXROWS on the query that pulled the data. Definitely worth looking into for something that big and if it's the same sort of document you are generating...
I have pushed it this far as well, used ColdFusion to create a Cupon printing system, but its a local system to runs great.
I forgot how to a Word mail merge a while ago, and I just couldn't be bothered to learn. So I wrote a script which uses CFDOCUMENT to make a PDF off a mySQL database, formatted to use with the labels we use in the office.
It takes a few seconds, but loops through 5000+ rows of addresses.. works a treat :)
I was doing a project that required a nightly run of a pdf, but it was ginormous and timed out/crashed/etc most of the time. I ended up generating each chapter staggered with threading and then merged them at the end. It works like a champ now. I forget the exact size but it wasn't far off.
I like Ray's idea of splitting up parts of the pdf generation, put them all in one folder and then use cfpdf merge which can work on a folder to create the big pdf.
I use ABCpdf with great success. http://www.websupergoo.com/...
It is very powerful really fast. It is windows only.
You can get a free license with a link back to their site.
I generated reports like this with a different method. Use <cffile> to build an html / table formatted report 1 line at a time (you can make this as large as you want). Then I used a command-line HTML to PDF converter using cfexecute to write my pdf file directly. I think it was just called HTMLtoPDF.exe, but I dont recall now, that was a while ago, some googling may find it =)
I followed Ron Stewart's advice and spent the day retooling my statement using CFReport. The file size dropped from 150MB to about 2MB and the page load time went from 30 mins to less then 1 minute. Thanks for all the great suggestions. I think I will also use cfthread as suggested and alert the user after creatation so that they don't even have to wait the minute. Yet another reason Coldfusion is GREAT!
I create a image-rich for a client and the file sizes typically reach 50mb. I had always assumed that was because we were creating a PDF for off-set press printing and the images had to be high-rez. I just broke up the sections of the catalog into logical chunks and that got us to 50mb size. I was going to look at CFTHREAD, but the comment on CFREPORT is intriguing and I'll take a look.
@Qasim Rasheed: could you elaborate on the process you use, jdk, FOP version, etc?
Dan,
Currently we are using version 0.93 of FOP with the default JDK provided with ColdFusion. Please feel free to email me @ qasimrasheed AT gmail Dot com if you have any addiitonal questions.
Thanks
I was having a different problem and came across this thread, just thought I would share. I was making sorta large pdfs several times a month, and it was just awful. But it has actually turned around with cf8.
in a nutshell, they were pick tickets and packing slips for 500-5000 shipments that needed to be sent out. 1 page for pick ticket and 1-2 pages for the packing slip both on legal size paper. pick ticket structure was required to be the same for all tickets for a particular shipment, but the qtys are very different on each one. fortunately there are very few images included.
We cut it down to 250 locations per pdf just to keep from using up all the memory, and just ran the job in batches of 250. Depending on the complexity of the orders (1-200 items), it could take anywhere from 2-20 minutes to create 1 batch for 250 locations.
Anyway, along comes cf8, and it didn't really get much better, until we refactored it. basically we switched it to create an individual pdf for each of the locations (run in a cfthread with low priority and saved with a filename that would put them in the correct order upon merging), then used cfpdf to merge them all together.
What previously would often take several hours to run has improved substantially. to the tune of creating 4588 individual 2-3 page pdfs with 158 different items that could be picked took ~ 15 minutes today and didn't require interaction, and the cfpdf that merged them together took a little over 1 minute. to give me a 9606 page, 160mb pdf.
hope that helps someone.
A follow-up to Ron Stewart's comment. First, I would like say thank you Ron Stewart. Without your suggestion I would not have been able to do something that we really needed to do.
I was querying a blob field. Using cfdocument and cfimage worked when dealing with 50 or 60 pages (records) but when the query pulled up 1100 pages it crashed our server.
I used cfreport as suggested by Mr. Stewart. The only thing I needed on the pages were the blobs, no headers, footers etc.
I set the entire document to be a page of 8.5 by 11 with a .5 margin top, bottom, left and right.
I set everything (header, footer, watermark etc) but the center/main band to have a height of 0. I set the main band to have a height of 10.
I inserted an image structure in the main area and set it's dimensions to 7.5 by 10 and set the value to be the blob field.
It worked like a charm, creating an 1200 page pdf, almost 40 meg in under 2 minutes. The average size reports 40-100 pages were almost instantaneous.
Thanks for sharing that. I would have assumed that would have never run that fast.
CFPDF - I think it has a bug - I've tried using setinfo= but instead of reading in a pdf from disk I've passed it a cfdocument variable, it crashes out every time. Any ideas?
I, too have gone the cfreport route, and can already see that it's the fastest way to generate very large pdf's with ColdFusion.
I'm having kind of a 'duh' moment, and hope that someone can shed some light here.
So my query pulls about 450 employee records, and I want it to output each employees name/bio/picture to a page.
I have an input parameter in report builder, and use the cfreportparam to inject the data to the report. I get the 450 pages populated, but the first employee's name is shown on every page. I tried looping in the cfreport tag but that didnt work either.
Check out my code:
<cfreport template="../specialscripts/bioprint.cfr" format="pdf" overwrite="yes" query="perslisting">
<cfreportparam name="empname" value="#perslisting.firstname# #perslisting.lastname#">
</cfreport>
Any thoughts?
Ok, I got a solution...in the docs (go figure) it shows a way to Concatenate the FIRSTNAME and LASTNAME fields, which what I was trying to do anyway.
Just put this in my expression builder:
FIRSTNAME &" "& LASTNAME
Works like a charm.
I have the same problem with CFDOCUMENT and might try the merging PDF method. Have any of you had any success working with tabular Data in CFReport?