开发者

CFDocument PDFs are huge (ColdFusion 8)

开发者 https://www.devze.com 2023-03-25 12:25 出处:网络
I wanted to add a PDF generation button for articles. Everything is working well until I noticed that the file sizes are upwards of 4MB for a document with 200KB of JPG images and about 120KB of HTML.

I wanted to add a PDF generation button for articles. Everything is working well until I noticed that the file sizes are upwards of 4MB for a document with 200KB of JPG images and about 120KB of HTML. So, I tossed the CFDocument into the CFPDF tag which reduced it to 1.5MB. Better. Then I put it through Acrobat's web optimizer which took it down to 335KB. I cannot find an "optimizing" solution with either CFDocument or CFPDF. I was hoping for a quality setting or something. I should also note that CFDocument takes a while to process (relatively sp开发者_开发百科eaking). Since ColdFusion 9 added an optimize function, I'm guessing that I'm out of luck until this server is upgraded. True?

<cfdocument format="pdf" 
            localurl=true 
            name="loc.tempPDF">

    <cfoutput>#loc.articleContent#</cfoutput>

</cfdocument>

<cfpdf action = "write" 
       destination = "#expandPath('\pdf\temp.pdf')#" 
       source = "loc.tempPDF"  
       overwrite = "yes" 
       saveOption = "linear" />


That's correct, there is currently no way to optimize PDFs in ColdFusion 8 with the native cfdocument or cfpdf tags. If you absolutely have to make this happen without upgrading to CF9 (which has much improved PDF compression), then you could look at the iText library for generating PDFs via Java.


I built a Document Management System using CF 6.1 a few years ago. I used GhostScript to create, concatenate and optimize PDFs.

Here's a blog post showing how you can use GS to optimize a PDF's size.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号