Monday, November 1, 2010

CFDocument and Really Large Files

I've been having a bit of trouble lately generating a large pdf on a shared server. The file was so large it would time out. (a little over 4 megs)

I finally got it to work by streamlining the cfdocument and wrapping it in a cfthread.

Here's the CFcocktail for large pdf files:

1. Use gif images (I have no idea why this makes the file size smaller but it does, even when the gifs are larger than the jpgs)

2. Put all images in the same folder as pdf creation and make sure to put localurl="true" in the cfdocument tag

3. Make sure the page validates before you wrap it with cfdocument

4. Import your stylesheet



5. Finally, if the file is still too large, wrap it in a cfthread

I tried a lot of different combinations, and this was the only way I could get the file to generate.

Another little neat trick, to make the file open automatically after it's generated is to put this after your tag:



That will prompt a download after the file is generated.

1 comment:

CS said...

Just a footnote.. am generating this in CFWheels and I think the cfthread is causing problems in wheels. I filed a ticket on it, but had to move this out of wheels (actually put it in the miscellaneous folder) to get it to work.