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">
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.
Related
PdfBox 2.0.24.
Hi, I'm developing a PDF writer and I need to use "AR PL Zenkai Uni Font".
When I try to load it PDFBox crash with the following error:
Exception in thread "main" java.io.IOException: Invalid characters codes
at org.apache.fontbox.ttf.CmapSubtable.processSubtype12(CmapSubtable.java:257)
at org.apache.fontbox.ttf.CmapSubtable.initSubtable(CmapSubtable.java:111)
at org.apache.fontbox.ttf.CmapTable.read(CmapTable.java:86)
at org.apache.fontbox.ttf.TrueTypeFont.readTable(TrueTypeFont.java:361)
at org.apache.fontbox.ttf.TTFParser.parseTables(TTFParser.java:173)
at org.apache.fontbox.ttf.TTFParser.parse(TTFParser.java:150)
at org.apache.fontbox.ttf.TTFParser.parse(TTFParser.java:106)
at org.apache.pdfbox.pdmodel.font.PDType0Font.load(PDType0Font.java:97)
at com.vgs.pdf.PDFCreatorSandbox.main(PDFCreatorSandbox.java:166)e here
To load this font i'm usign the following code:
PDType0Font brokenFont = PDType0Font.load(document, new FileInputStream("font/ukai.ttf"), false);
This code was run on Windows 10 with java 1.8.0_291
Any suggestions?
Thanks in advance
I'm trying to debug a cf query and cannot do this because of his complex structure.The code is following:
<cfquery name="qQuery" datasource="#variables.datasource#">
<cfloop index="i" from="1" to="#ArrayLen(aSQL)#" step="1">
<cfif IsSimpleValue(aSQL[i])>
<cfset temp = aSQL[i]>#Trim(DMPreserveSingleQuotes(temp))#
<cfelseif IsStruct(aSQL[i])>
<cfset aSQL[i] = queryparam(argumentCollection=aSQL[i])>
<cfswitch expression="#aSQL[i].cfsqltype#">
<cfcase value="CF_SQL_BIT">
#getBooleanSqlValue(aSQL[i].value)#
</cfcase>
<cfcase value="CF_SQL_DATE,CF_SQL_DATETIME">
#CreateODBCDateTime(aSQL[i].value)#
</cfcase>
<cfdefaultcase>
<!--- <cfif ListFindNoCase(variables.dectypes,aSQL[i].cfsqltype)>#Val(aSQL[i].value)#<cfelse> --->
<cfqueryparam value="#aSQL[i].value#" cfsqltype="#aSQL[i].cfsqltype#" maxlength="#aSQL[i].maxlength#" scale="#aSQL[i].scale#" null="#aSQL[i].null#" list="#aSQL[i].list#" separator="#aSQL[i].separator#">
<!--- </cfif> --->
</cfdefaultcase>
</cfswitch>
</cfif>
</cfloop>
</cfquery>
If I run <cfdump var="#qQuery#"> it's not working nor cfoutput, I get undefined qQuery error. How can I find what query is executing behind ? I don't want to use MS SQL profiler.
Thanks,
Take everything inside the query and wrap it in a cfsavecontent instead. Output that result.
If you place the cfsavecontent inside the cfquery tags, you don't even need to worry about the cfqueryparam tags barfing, although you do need to re-output that saved content inside the query. See http://coldflint.blogspot.com/2016/01/debugging-queries-dirty-way.html
Basically, you should have this:
<cfquery name="qQuery" datasource="#variables.datasource#">
<cfsavecontent variable="sqlContent">
<cfloop index="i" from="1" to="#ArrayLen(aSQL)#" step="1">
<cfif IsSimpleValue(aSQL[i])>
<cfset temp = aSQL[i]>#Trim(DMPreserveSingleQuotes(temp))#
<cfelseif IsStruct(aSQL[i])>
<cfset aSQL[i] = queryparam(argumentCollection=aSQL[i])>
<cfswitch expression="#aSQL[i].cfsqltype#">
<cfcase value="CF_SQL_BIT">
#getBooleanSqlValue(aSQL[i].value)#
</cfcase>
<cfcase value="CF_SQL_DATE,CF_SQL_DATETIME">
#CreateODBCDateTime(aSQL[i].value)#
</cfcase>
<cfdefaultcase>
<!--- <cfif ListFindNoCase(variables.dectypes,aSQL[i].cfsqltype)>#Val(aSQL[i].value)#<cfelse> --->
<cfqueryparam value="#aSQL[i].value#" cfsqltype="#aSQL[i].cfsqltype#" maxlength="#aSQL[i].maxlength#" scale="#aSQL[i].scale#" null="#aSQL[i].null#" list="#aSQL[i].list#" separator="#aSQL[i].separator#">
<!--- </cfif> --->
</cfdefaultcase>
</cfswitch>
</cfif>
</cfloop>
</cfsavecontent>
#sqlContent#
</cfquery>
<pre>#sqlContent#</pre>
Do make sure to put everything back to normal once you're done debugging.
If this question is more about HOW to debug or get some output you can work with, cftry and cfcatch are your friends.
<cftry>
---code logic---
<cfcatch>
<cfdump var="#cfcatch#">
</cfcatch>
</cfctry>
This should provide a complete dump of whatever errors ColdFusion encounters as well as SQL statements that were attempted, if there is indeed a syntax error generated by the loopy logic.
You have to work from the inside out this.
As I look at this query, I note that it is split on IsSimpleValue() and IsStruct(). So run this
<cfquery name="qQuery" datasource="#variables.datasource#">
<cfloop index="i" from="1" to="#ArrayLen(aSQL)#" step="1">
<cfif IsSimpleValue(aSQL[i])>
<cfset temp = aSQL[i]>#Trim(DMPreserveSingleQuotes(temp))#
</cfif>
</cfloop>
</cfquery>
Note that temp is never used.
The rest of the code creates <cfqueryparam>s
Conclusion
This code cannot work. It cannot create valid SQL.
Your error has nothing to do with the sql being generated by the code in the cfquery block. It's an undefined variable. If there was a problem with the code you displayed, the error message would be different.
Troublehoot as follows. First comment out all the code inside that query and replace it with:
select 1 record
This is valid for MS SQL. Leave everything else unchanged.
Running the page will produce the same error. You then have to determine why the query is not running. Likely, you have something like this going on:
<cfif some Condition is met>
run the query
</cfif>
dump the query
You'll have to determine why your condition wasn't met and make sure your page runs properly when it isn't.
The solution was to put <cftry> outside <cfloop> but not outside <cfquery>.I found that I forgot to send one parametter.
So the code is following:
<cfquery name="qQuery" datasource="#variables.datasource#">
<cftry>
<cfloop index="i" from="1" to="#ArrayLen(aSQL)#" step="1">
<cfif IsSimpleValue(aSQL[i])>
<cfset temp = aSQL[i]>#Trim(DMPreserveSingleQuotes(temp))#
<cfelseif IsStruct(aSQL[i])>
<cfset aSQL[i] = queryparam(argumentCollection=aSQL[i])>
<cfswitch expression="#aSQL[i].cfsqltype#">
<cfcase value="CF_SQL_BIT">
#getBooleanSqlValue(aSQL[i].value)#
</cfcase>
<cfcase value="CF_SQL_DATE,CF_SQL_DATETIME">
#CreateODBCDateTime(aSQL[i].value)#
</cfcase>
<cfdefaultcase>
<cfqueryparam value="#aSQL[i].value#" cfsqltype="#aSQL[i].cfsqltype#" maxlength="#aSQL[i].maxlength#" scale="#aSQL[i].scale#" null="#aSQL[i].null#" list="#aSQL[i].list#" separator="#aSQL[i].separator#">
</cfdefaultcase>
</cfswitch>
</cfif>
</cfloop>
<cfcatch>
<cfdump var="#cfcatch#" >
</cfcatch>
</cftry>
</cfquery
Having a bit of trouble inserting a LIKE and using a wildcard within my parameter in my query using coldfusion. Here is what currently works:
<cfquery name="sample" datasource="database"><!---Take the query here--->
SELECT * <!---select all--->
FROM table <!---from the table "table"
WHERE
<cfloop from="1" to="#listLen(selectList1)#" index="i">
#ListGetAt(selectList1, i)# = <cfqueryparam cfsqltype="cf_sql_varchar" value="#ListGetAt(selectList2,i)#" /> <!---
search column name = query parameter
using the same index in both lists
(selectList1) (selectList2) --->
<cfif i neq listLen(selectList1)>AND</cfif> <!---append an "AND" if we are on any but
the very last element of the list (in that
case we don't need an "AND"--->
</cfloop>
</cfquery>
My goal is to get the code somewhere where I can type in a parameter like so (but it is not working currently - Error reads cannot execute query)
<cfquery name="sample" datasource="database"><!---Take the query here--->
SELECT * <!---select all--->
FROM table <!---from the table "table"
WHERE
<cfloop from="1" to="#listLen(selectList1)#" index="i">
#ListGetAt(selectList1, i)# LIKE <cfqueryparam cfsqltype="cf_sql_varchar" value="%#ListGetAt(selectList2,i)#%" /> <!---
search column name = query parameter
using the same index in both lists
(selectList1) (selectList2) --->
<cfif i neq listLen(selectList1)>AND</cfif> <!---append an "AND" if we are on any but
the very last element of the list (in that
case we don't need an "AND"--->
</cfloop>
</cfquery>
Your syntax looks fine. I use the same kind of logic in some of my code running against Microsoft SQL Server.
Try this to debug your code and see the SQL that is being generated.
<!--- Comment out your query tag to debug <cfquery name="sample" datasource="database"> --->
<cfoutput> <!--- add a cfoutput tag to "see" your generated code --->
SELECT *
FROM table
WHERE
<cfloop from="1" to="#listLen(selectList1)#" index="i">
#ListGetAt(selectList1, i)# LIKE <cfqueryparam cfsqltype="cf_sql_varchar" value="%#ListGetAt(selectList2,i)#%" />
<cfif i neq listLen(selectList1)>AND</cfif>
</cfloop>
</cfoutput> <!--- add a cfoutput tag to "see" your generated code --->
<!--- Comment out your query tag to debug </cfquery> --->
This will most likely break the rest of your code that is dependent on the query. I usually just stick a <cfabort> tag after the closing </cfoutput> tag to stop processing and just show me the SQL.
The purpose of this is to output the generated SQL code to your browser. Look it over and see if you can spot the error. You could also copy and paste the generated SQL into your query tool (query analyzer) and test it that way.
My error report told me that an error has occurred when an user tried uploading an empty file to my server (don't ask why the user did that - I don't know) and now I want to catch that exception which said "No data was received in the uploaded file". I wonder if there is a better way than putting a <CFTRY> around the <CFFILE action="upload"> like this:
<CFTRY>
<CFFILE action="upload" destination="#expandpath("upload")#" filefield="form.file" nameconflict="makeunique" />
<CFCATCH>
<!--- handle that error --->
</CFCATCH>
</CFTRY>
Try/Catch is the way I usually handle it.
<cftry>
<cffile action="upload" ...>
<cfcatch type="any">
<cfif Find("Saving empty (zero-length) files is prohibited", CFCatch.Detail) GT 0>
<!--- Create a zero length file on disk and continue processing as usual --->
<cffile action="write" file="..." output="">
<cfelse>
<cfrethrow>
</cfif>
</cfcatch>
</cftry>
I need to create a pdf file with several chart created by ggplot2 arranged in a A4 paper, and repeat it 20-30 times.
I export the ggplot2 chart into ps file, and try to PostScriptTrace it as instructed in grImport, but it just keep giving me error of Unrecoverable error, exit code 1.
I ignore the error and try to import and xml file generated into R object, give me another error:
attributes construct error
Couldn't find end of Start Tag text line 21
Premature end of data in tag picture line 3
Error: 1: attributes construct error
2: Couldn't find end of Start Tag text line 21
3: Premature end of data in tag picture line 3
What's wrong here?
Thanks!
If you have no time to deal with Sweave, you could also write a simple TeX document from R after generating the plots, which you could later compile to pdf.
E.g.:
ggsave(p, file=paste('filename', id, '.pdf'))
cat(paste('\\includegraphics{',
paste('filename', id, '.pdf'), '}', sep=''),
file='report.pdf')
Later, you could easily compile it to pdf with for example pdflatex.