5 Replies Latest reply on Jan 10, 2016 7:16 AM by tonym64063353

    CFPDF read error

    tonym64063353

      Getting a strange error when trying to do a CFPDF "read":

       

      <cfpdf action="read" source="c:\test.pdf" name="myBook">

       

      An error occurred during the READ operation in the cfpdf tag.

      Error: Invalid Document c:/test.pdf specified for source or directory.


      The file is defintely there, and I can open the PDF fine with acrobat reader (or any other pdf reader). 

      Could it be partial corruption of the PDF itself somehow?

        • 1. Re: CFPDF read error
          Jamo Level 2

          Which version of ColdFusion?

           

          When you open the PDF and select "File | Properties", what information is displayed regarding "Producer" and "Version"?

           

          What happens if you use "isPDFFile()" to verify whether it's a PDF file or not?  (Does it return true or false?)

          https://helpx.adobe.com/coldfusion/cfml-reference/coldfusion-functions/functions-in-k/ispd ffile.html

           

          ... and what are you trying to do with the PDF after you read it?  (We've encountered issues with Adobe ColdFusion not liking PDF files generated by other software.  For some PDF functions, we've started using CFExecute to use XPDF, PDFtk and WKHTMLTOPDF.)

          • 2. Re: CFPDF read error
            tonym64063353 Level 1

            Hi Jamo,

             

            I'm pretty certain this is caused by the application generating the PDF.  It's some sort of printer/scanner doing a save as PDF to a network drive.

             

            CF Version 10 (whatever the latest patch is)

            isPDFFile() comes back TRUE

            The PDF in file/properties says:  PDF Version 1.7, Application by HP Smart Document Scan Software 3.7, Producer OmnipageCsdk18.  This is probably the problem child.

             

            Right now I'm not trying to do anything after reading the PDF - haven't gotten that far yet!  Eventually I'll need to merge it with other PDF's.

            • 3. Re: CFPDF read error
              Jamo Level 2

              You can use isPDFFile() to simply confirm that Adobe believes it's a valid PDF and then use cfpdf action="merge" to combine them. Create another copy of the PDF file and test if CF is capable of merging them together into a single PDF.  (NOTE: If you merge similar PDF forms that have the same fieldnames, Adobe does some weird stuff and you may need to "flatten" them prior to merging.)

              • 4. Re: CFPDF read error
                BKBK Adobe Community Professional & MVP

                Tony, this need not be a show-stopper. You could apply CfSearching's trick for reading corrupt PDFs. The code creates a copy, then reads it rather than the original.

                 

                <cfscript>

                pdfFileIn = "c:\test.pdf";

                pdfFileOut = "c:\testCopy.pdf";

                pdfReader = createObject("java", "com.lowagie.text.pdf.PdfReader").init( pdfFileIn );

                streamOut = createObject("java", "java.io.FileOutputStream").init( pdfFileOut );

                pdfStamper = createObject("java", "com.lowagie.text.pdf.PdfStamper").init( pdfReader, streamOut );

                pdfStamper.close();

                streamOut.close();

                </cfscript>

                 

                <cfpdf action="read" source="#pdfFileOut#" name="pdfContent">

                • 5. Re: CFPDF read error
                  tonym64063353 Level 1

                  That works - thank you!!