2

I'm trying to overhaul a pdf report generation application built in CF8 and they have an interface which generates a 50 page legal report as a pdf and sends it out about 100x a day. However, its very cumbersome and bogs down an already overworked server. Is there a good PDF compression script that I can run with coldfusion or a way to integrate with Adobe acrobat to have it compress the pdf before the server sends the pdf via email? The system is already setup using the available Coldfusion resources to try and help with this process, but its still not sufficient.

Update: I had the opportunity to further dig into this issue. The way these documents are compiled its via 4 CF forms where someone manually types in the legal data as it comes in to the system. Some of the form fields are lengthy (accepting in excess of 10,000 characters or more). Once completed, it runs a cfdocument tag that converts everything into a pdf.

Alex
  • 443
  • 3
  • 18
  • How do you generate the PDF? CFDOCUMENT tag? How large is it in MB? – Bernhard Döbler May 26 '15 at 16:25
  • Its using the CF document tag. They are over 8Mb. It depends on the page. Average document is 50. But some documents exceeding 100pages aren't uncommon. They would like to see the documents compressed to a few Mb. If it could get below 1.5Mb they would be elated. – Alex May 26 '15 at 16:32
  • A quick google search lead me to [iText library](http://itextpdf.com/) written in Java. I think that is the option other people have used while working with CF8. – Tushar Bhaware May 27 '15 at 09:36
  • Whether a PDF document can be further compressed (and how much) really depends on the PDF document and its content. Can you post an example (or fake) document so that we could take a look at it and potentially suggest what is possible? – David van Driessche May 27 '15 at 10:39
  • Are there any images in your document? – Nebu May 27 '15 at 11:02
  • There are no images. Its a legal document. I can't specify a specific document size for PDF conversion as sometimes they are 2 pages and other times they are 50-100pages. It really varies on a case by case basis as the code takes data from several sources and compiles it together with a final report so that is why number of pages can vary so much. Its just when its 50+ pages that it needs to be compressed more than what its currently generating. – Alex May 27 '15 at 13:33

2 Answers2

2

CFDocument generates bloated PDFs. We tested GhostScript and used the following parameters to compress a 22.3mb PDF to 4mb. (If set to "screen", the file size shrunk down further to 2.5mb.) http://www.ghostscript.com/

To use this, you'll have to perform this optimization as an extra step after the generation of your PDF and use cftry/catch in case there are any issues or timeouts.

<CFSET ThePDFFile = "C:\test\OriginalPDF.pdf">
<cfexecute name="c:\Program Files\gs\gs9.14\bin\gswin64.exe"
arguments="-sDEVICE=pdfwrite -dPDFSETTINGS=/prepress -dNOPAUSE -dQUIET -dBATCH -sOutputFile=#replace(ThePDFFile,'.pdf','-opt.pdf')# #ThePDFFile#" timeOut="160">
</cfexecute>

Another solution would be to generate your PDFs using WKHTML2PDF. The resultant files are much smaller. The quality is consistent on ColdFusion 8-11. You can embed TrueType fonts without having to register them and it doesn't have any of the HTML/CSS quirks that are present with CFDocument. http://wkhtmltopdf.org/

Here's a link to an article and some sample ColdFusion code that you can use to compare the results of WKHTMLTOPDF to CFDocument. http://gamesover2600.tumblr.com/post/108490381084/wkhtmltopdf-demo-to-compare-w-adobe-coldfusion

James Moberg
  • 4,360
  • 1
  • 22
  • 21
  • I implemented the ghost script but when I run it, the browser keeps showing the spinning status in the tab with no outcome for several minutes – Alex Jun 05 '15 at 20:32
  • Have you tested running it locally and directly using the command line? If so, does it take more than 3 minutes? (It shouldn't.) Add the CFExecute "variable" parameter to determine what the console outputting in case there's an error. – James Moberg Jun 08 '15 at 18:28
0

I was actually able to resolve it utilzing the NeeviaPDF compression application and tied it into ColdFusion with the following code:

<cfset pdf_file_name = 'qryGetFileJustUploaded' />
<cfexecute name="C:\Program Files (x86)\neeviaPDF.com\PDFcompress\cmdLine\CLcompr.exe"
arguments="C:\inetpub\wwwroot\testingFolder\PDFCompression2\pdf\#pdf_file_name# C:\inetpub\wwwroot\testingFolder\PDFCompression2\pdf\#pdf_file_name# -co -ci jpg -cq 10 -gi jpg -gq 10 -mi jbig2 -mq 1"
outputfile="C:\inetpub\wwwroot\testingFolder\PDFCompression2\output.txt"
timeout="250">
</cfexecute>

where you can pass in a value to the variable #pdf_file_name# and if you want to set name of the output compressed pdf, just pick a name and place that name where #pdf_file_name# is referenced in the second C:\ line.

Alex
  • 443
  • 3
  • 18