In your CFDocument class you need to define the method convertToPDF() as static as shown below:
public void static convertToPDF(...) Either that or in your CFML code you need to call init() on the object. Paul From: [email protected] [mailto:[email protected]] On Behalf Of Anthony Hixon, Jr. Sent: Monday, March 09, 2009 1:51 PM To: openbd Subject: [OpenBD] PDF Question 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]<mailto:[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 !! -~----------~----~----~----~------~----~------~--~---
