2

I am trying to use cfpdf and keep getting the following error:

String index out of range: -1

I don't understand why. I'm running ColdFusion 11 on Debian Linux.

<CFIF FileExists("#getDirectoryFromPath(getCurrentTemplatePath())#REPORT.pdf")>
    <cfpdfform 
        action="read" 
        source="#getDirectoryFromPath(getCurrentTemplatePath())#REPORT.pdf" xmldata="x" 
        result="r">
    </cfpdfform>

    <cfdump var="#x#" label="XMLData">
    <cfdump var="#r#" label="Result">
<CFELSE>
    File doesn't exist
</CFIF>

Exact error:

String index out of range: -1 

 The error occurred in /var/www/www.test.com/test.cfm: line 2

1 : <CFIF FileExists("#getDirectoryFromPath(getCurrentTemplatePath())#REPORT.pdf")>
2 : <cfpdfform 
action="read" 
source="#getDirectoryFromPath(getCurrentTemplatePath())#REPORT.pdf" 
xmldata="x" result="r">
3 : </cfpdfform>
4 : <cfdump var="#x#" label="XMLData">
Community
  • 1
  • 1
Brad Hazelnut
  • 1,603
  • 5
  • 21
  • 33
  • you're missing a closing `>` on your second cfdump, so this code won't compile. Please post the exact code that's throwing the error and what line is throwing the error – Matt Busche Jun 16 '14 at 20:06
  • good catch, but for some reason it got deleted when i posted and formatted the code. But even with the closing tag, it still gives the same error. – Brad Hazelnut Jun 16 '14 at 20:18
  • I never use cfpdfform, but the first thing I would do is to take away the x and r attributes to see if the error goes away. If so, put them back one by one so you can identify the culprit. – Dan Bracuk Jun 17 '14 at 01:57
  • You're not using any sub-tags like `cfpdfformparam` or `cfpdfsubform` so you may want to try writing it without the closing tag (it's unlikely this would be the source of your error but you never know) `` – duncan Jun 17 '14 at 08:12
  • How complex is your `report.pdf`? I'd troubleshoot this by starting with as simple a test case as possible, and augment it from there until you find out what's causing the issue. First things first... use a very basic PDF as the input file, and see what happens. And as @duncan suggests: don't close tags that don't require closing. – Adam Cameron Jun 17 '14 at 12:57
  • The report is very simple I just added one text box and want to populate it to test, I just wanted to get the structure, that's why I am doing a dump, but when I removed the closing tag, this is what I get The "start tag must have a matching end tag. An explicit end tag can be provided by adding . If the body of the tag is empty you can use the shortcut . " – Brad Hazelnut Jun 17 '14 at 20:31
  • Can you stick report.pdf somewhere so we can replicate your situation? – Adam Cameron Jun 17 '14 at 21:49
  • Sure, here is the link to the pdf file https://www.dropbox.com/s/iw9xqjlace869ci/TEST.pdf – Brad Hazelnut Jun 17 '14 at 22:28
  • were you able to download the pdf? – Brad Hazelnut Jun 18 '14 at 17:04
  • Ok i got it working, the resolution is opening the pdf in acrobat pro and saving it as new pdf. Apparently a pdf created is livecycle es 2 causes this issue, not sure why though. but the resolution works. – Brad Hazelnut Jun 19 '14 at 03:59

1 Answers1

0

I have had similar issues in the past. The problem has been using non Adobe programs to create the pdf - making a pdf form in Libreoffice, for example, can cause this issue. I assume some internal formatting in the file that CF is looking for is missing.

You can try opening in Acrobat and resaving it.