Exactly right on var scoping which I always do on production code and great tip on the local scope! (although that came over from the code I was testing and I just haven't changed it yet) Anyway, the dump shows the method available:
object of com.hmc.CFWrapper.CFDocument *Methods:* convertToPDF (returns void) wait (returns void) wait (returns void) wait (returns void) hashCode (returns int) getClass (returns java.lang.Class) equals (returns boolean) toString (returns java.lang.String) notify (returns void) notifyAll (returns void) However, I still get this when I run the code: *struct* detail Method convertToPDF could not be found. Check you have correct method name, the method name casing matches that of the Java class and you've provided the correct number of arguments errorcode errorCode.runtimeError extendedinfo [empty string] message General Runtime Error tagcontext *array [empty]* type Object Thoughts? On Mon, Mar 9, 2009 at 1:06 PM, Chris Blackwell <[email protected]> wrote: > to see if its loaded it correctly after<cfset CFDocument = > Createobject("java","com.hmc.CFWrapper.CFDocument") /> > do <cfdump var=#cfdocument#""><cfabort> > you should get dump showing you the methods in your java class. > > on a side note, i'm assuming you've trimmed some code from your cffunction > so feel free to ignore the following.. you should var scope any variables > used inside it, and for future cross compatibility i'd avoid creating a > "local" struct inside functions (CF9 will introduce local as the > function-local scope) > > > 2009/3/9 Anthony Hixon, Jr. <[email protected]> > > Ok, this will semi-lengthy so I want to start by saying I'm not a Java >> programmer yet as I'm still learning. >> That said, I'm trying to get PDF generation working (sans cfpdf) using the >> methods shared in earlier posts with flying saucer. >> >> So, I took some the shared Java code and compiled into a jar in Eclipse >> (Hope I did it right): >> >> package com.hmc.CFWrapper; >> import java.io.*; >> import javax.xml.parsers.*; >> import org.xhtmlrenderer.pdf.ITextRenderer; >> import org.w3c.dom.Document; >> import org.xml.sax.*; >> /** >> * @author jeanbaptiste >> * >> */ >> public class CFDocument { >> public void convertToPDF(OutputStream os,String html) >> throws Exception { >> DocumentBuilder builder = >> DocumentBuilderFactory.newInstance().newDocumentBuilder(); >> StringReader reader = new StringReader(html); >> Document doc = builder.parse(new InputSource(reader)); >> ITextRenderer renderer = new ITextRenderer(); >> renderer.setDocument(doc, null); >> renderer.layout(); >> renderer.createPDF(os); >> } >> } >> >> I then dropped the produced jar in the main lib directory of the Ready2Run >> bundle, restarted Jetty, and proceeded to run this test code: >> >> <cfset test_pdf = "#expandpath('Resume.doc')#"> >> >> <cfset f.pdf = createobject("component","components.pdf") /> >> <cffile action="READ" file="#test_pdf#" variable="local.content" >> charset="iso-8859-1" /> >> <cfset f.pdf.encode(local.content,test_pdf) /> >> <cffile action="WRITE" file="#test_pdf#" output="#local.content#" >> charset="iso-8859-1" /> >> >> The pdf.cfc contains: >> >> <cfcomponent displayname="htmlToPdf" output="true"> >> <cffunction name="encode" access="public" output="true" returntype="void" >> > >> <cfargument name="content" type="string" required="true"> >> <cfargument name="pdffile" type="string" required="true"> >> <cfargument name="downloadFile" type="Boolean" required="false" >> default="0"> >> <cfset local.outputPath = GetDirectoryFromPath(arguments.pdffile)> >> <cfset local.outputFile = GetFileFromPath(arguments.pdffile)> >> <cfset local.outputFile = >> replace(arguments.pdffile,listLast(local.outputFile,'.'),'pdf','ALL')> >> <cfset CFDocument = Createobject("java","com.hmc.CFWrapper.CFDocument") >> /> >> <cfset objOutput = CreateObject("java", "java.io.FileOutputStream" >> ).Init(CreateObject("java", "java.io.File" ).Init(JavaCast("string", >> local.outputFile))) /> >> <cfset >> CFDocument.convertToPDF(objOutput,arguments.content,"#expandpath('.')#/") /> >> <cfif arguments.downloadFile> >> <cfcontent type="application/pdf" file="#local.outputFile#" >> reset="yes"> >> <cfheader name="Content-Disposition" >> value="filename=#getFileFromPath(local.outputFile)#"> >> </cfif> >> >> </cffunction> >> </cfcomponent> >> >> >> I get the error that the method convertToPDF cannot be found which I know >> lives in the jar (or should anyway). Now, does that mean that the jar loaded >> properly and it just can't access the method or the jar didn't load at all? >> Where can I look to troubleshoot this? I'm just not familiar enough with >> loading custom java classes to figure this one out without some help. >> >> Thanks! >> >> -- >> Anthony Hixon, Jr. >> Certified Advanced ColdFusion MX 7 Developer >> Mobile: (706) 639-3617 >> [email protected] >> >> >> > > > > -- Anthony Hixon, Jr. Certified Advanced ColdFusion MX 7 Developer Mobile: (706) 639-3617 [email protected] --~--~---------~--~----~------------~-------~--~----~ Open BlueDragon Public Mailing List http://groups.google.com/group/openbd?hl=en official site @ http://www.openbluedragon.org/ !! save a network - trim replies before posting !! -~----------~----~----~----~------~----~------~--~---
