• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

CFPDF read error

Explorer ,
Jan 08, 2016 Jan 08, 2016

Copy link to clipboard

Copied

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?

Views

1.9K

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Community Expert , Jan 10, 2016 Jan 10, 2016

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, streamO

...

Votes

Translate

Translate
Enthusiast ,
Jan 08, 2016 Jan 08, 2016

Copy link to clipboard

Copied

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/ispdffile.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.)

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Jan 08, 2016 Jan 08, 2016

Copy link to clipboard

Copied

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.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Enthusiast ,
Jan 08, 2016 Jan 08, 2016

Copy link to clipboard

Copied

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.)

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jan 10, 2016 Jan 10, 2016

Copy link to clipboard

Copied

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">

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Jan 10, 2016 Jan 10, 2016

Copy link to clipboard

Copied

LATEST

That works - thank you!!

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Resources
Documentation