Skip to main content
Inspiring
May 28, 2014
Answered

cfpdf optimize

  • May 28, 2014
  • 3 replies
  • 2226 views

I am uploading pdf files to our server and want to save space.  I am trying to use cfpdf to optimize the file size.  The one I am testing on is 1.25MB, so it's not a big file.  When I reduce it using desktop Acrobat it takes less than 1 second.  When I use Coldfusion it times out after several minutes.

The file is first uploaded to it's own directory, then I use this to try to reduce it.

<cfpdf

    action = "optimize"

    source = "H:\Inetpub\Wwwroot\MySite.com\newsletters\files\#Section#\#issue#.pdf" 

    algo = "bilinear" />

I'm sure it's something I've done wrong, please advise.

    This topic has been closed for replies.
    Correct answer BKBK

    ctreeves wrote:

    Thank you, I tried your code to see if I could reduce one file directly on the server as compared to while I am uploading it.  The pdf is not protected and does have many images embedded.

    I get this error:

    An error occurred during OPTIMIZE operation in the cfpdf tag.

    Error: com.adobe.internal.pdftoolkit.core.exceptions.PDFCosParseException: Undefined filter - JPXDecode

    In my opinion, you have found a bug in ColdFusion 9. You should create a bug report, attaching the PDF file to it.

    3 replies

    ConsoleGenRL
    Known Participant
    November 23, 2017

    Have you tried a PDF "transform" action on your result PDF? I've found this can make a massive difference to the file size. eg:

     

        <cflock name="PerformTransform" timeout="160" throwontimeout="yes" type="exclusive">

            <cfpdf action="GetInfo" name="GetPDFInfo" source="mydocument.pdf" password="ifrequired">

            <cfset NumberOfPages=GetPDFInfo.TotalPages>
       
            <cfloop index="p" from="1" to="#NumberOfPages#" step="1">
       
                <cfpdf action="transform" source="mydocument.pdf" pages="#p#" overwrite="yes" destination="reducedsize.pdf" password="ifrequired">
       
            </cfloop>

        </cflock>

    BKBK
    Community Expert
    Community Expert
    June 3, 2014

    It should take seconds, not minutes. When I tested, using the following code on a 2MB PDF, it took 8 seconds.

    <cfpdf

        action = "optimize"

        source =  "C:\ColdFusion11\cfusion\wwwroot\workspace\cfTest\pdf\myDoc.pdf"

        algo = "bilinear"

        pages = "*"

        destination =  "C:\ColdFusion11\cfusion\wwwroot\workspace\cfTest\pdf\myDoc_optimized.pdf" 

        overwrite = "true">

       Done optimizing.

    ctreevesAuthor
    Inspiring
    June 3, 2014

    Thank you, I tried your code to see if I could reduce one file directly on the server as compared to while I am uploading it.  The pdf is not protected and does have many images embedded.

    I get this error:

    An error occurred during OPTIMIZE operation in the cfpdf tag.

    Error: com.adobe.internal.pdftoolkit.core.exceptions.PDFCosParseException: Undefined filter - JPXDecode
    BKBK
    Community Expert
    Community Expert
    June 4, 2014

    Your Coldfusion version?

    ctreevesAuthor
    Inspiring
    June 2, 2014

    Bump