1 Reply Latest reply on May 24, 2007 11:03 AM by insuractive

    Return PDF file via webservice

    Hugo Sombreireiro Level 1
      Hi guys,

      A customer requested a webservice that, by inputing a SKU code, returns a PDF file with all data on that SKU.
      My question is, can I generate and return a PDF file directly from a CFC using binary? I already have the PDF creation part done using cfdocument. Would it be possible to send it back without writing to the disk?
      This may be kind of newbie but I'm not that familiar with this area of ColdFusion.

      Thanks in advance

      Hugo
        • 1. Re: Return PDF file via webservice
          insuractive Level 3
          <cfdocument> allows you to specify a variable (I think the attribute is "Name") in which to store the postscript code for the PDF. You could certainly return that value via a webservice, but the application that consumed the webservice would need to be able to set the correct mime type before displaying the postscript code to the browser.

          Something like this (the code is quick and dirty so there might be some errors, but it should give you a general idea):

          Your Webservice Component:
          ------------------------------------------------------
          <cffunction name="myTest" returntype="string" access="remote">
          <cfdocument name="psText">
          <b>This is a test</b>
          </cfdocument>

          <cfreturn psText>

          </cffuncion>


          Consume Webservice
          ----------------------------------------------
          <cfsetting enablecfoutputonly="Yes">
          <cfset objWS = CreateObject("webservice", " http://www.mysite.com/ws/mywebservice.cfc?wsdl")>
          <cfset sPDFText = objWS.myTest()>
          <cfcontent type="application/pdf"><cfoutput>#sPDFText #</cfoutput>