问题
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.
回答1:
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
回答2:
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.
来源:https://stackoverflow.com/questions/30463886/compressing-a-pdf-document-generated-by-coldfusion