Posts in Category "ColdFusion"

Invoking Output Service (transformPDF) via SOAP

This tutorial provides a simple example of how to call a LiveCycle service from ColdFusion using SOAP. The article specifically calls the transFormPDF method of the OutputService, however provides the basics for calling any service.

Normally the preferred method of invoking LiveCycle services from ColdFusion is probably using the EJB, sometimes this can be difficult and SOAP provides a simple solution, although not the most robust.

Using the SOAP enoint requires knowledge of the specific WSDL file for the desired service. A list of WSDL file locations can be found here.

transformPDF.cfm
<!— Change OutputServiceURL to match your environment —>
< cfset OutputServiceURL = "http://127.0.0.1:8080/soap/services/OutputService?wsdl">

<!— Change SourceFileName to point to a PDF Form —>
<cfset SourceFileName = "C:\Temp\Test.pdf">

<!— Convert the PDF Form to Binary, BASE64 —>
<cffile action="READBINARY" file="#SourceFileName#" variable="sourcePDF">
<cfset binaryData = ToBase64(sourcePDF, "iso-8859-1")>

<cfoutput>
<CFSAVECONTENT VARIABLE="SoapRequestXML">
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<SOAP-ENV:Body>
<m:transformPDF xmlns:m="http://adobe.com/idp/services">
<m:inPdfDoc>
<m:contentType>String</m:contentType>
<m:binaryData>#binaryData#</m:binaryData>
<m:attachmentID>String</m:attachmentID>
<m:remoteURL>String</m:remoteURL>
</m:inPdfDoc>
<m:transformationFormat>PDF</m:transformationFormat>
<m:pdfaRevisionNumber>Revision_1</m:pdfaRevisionNumber>
<m:pdfaAmendment>String</m:pdfaAmendment>
<m:pdfaConformance>A</m:pdfaConformance>
</m:transformPDF>
v/SOAP-ENV:Body>
</SOAP-ENV:Envelope>
</CFSAVECONTENT>
</cfoutput>

<!— Invoke the Web Service —>
<cfhttp url="#OutputServiceURL#" method="POST" username="administrator" password="password">
<cfhttpparam type="CGI" name="SOAPAction" value="transformPDF">
<cfhttpparam type="XML" name="transformPDFRequest" value="#SoapRequestXML#">
</CFHTTP>

<!— Parse the Result —>
<cfset SoapResponseXML = #cfhttp.filecontent#>
<cfset SoapResponseXML = xmlParse(SoapResponseXML)>
<cfset theRoot = SoapResponseXML.XmlRoot>
<cfset readerEnabledPDF = ‘#theRoot.XmlChildren[1].XmlChildren[1].XmlChildren[1]["remoteURL"].XmlText#’>

<cfoutput>
<a href="#readerEnabledPDF#" target="_blank">Transformed PDF</a>
</cfoutput>

You can also download the source here Download Source

Invoking Output Service (transformPDF) via EJB

This sample provides the basics for invoking the transformPDF method of the LiveCycle OutputService.

This sample assumes you are using LiveCycle on Jboss. If you are using a different Java server, you will need to modify a few paramaters, but the basics are the same.

The transformPDF service transforms a interactive PDF (PDF Form) to a non-interactive PDF.

Environment Setup
1. Copy the following required jar files from your LiveCycle Installation to your {ColdFusion Install Directory}\wwwroot\WEB-INF\lib.
jbossall-client.jar [C:\Adobe\LiveCycle8\jboss\client]
adobe-utilities.jar [C:\Adobe\LiveCycle8\LiveCycle_ES_SDK\client-libs\jboss]
adobe-output-client [C:\Adobe\LiveCycle8\LiveCycle_ES_SDK\client-libs\common]
adobe-usermanager-client [C:\Adobe\LiveCycle8\LiveCycle_ES_SDK\client-libs\common]
adobe-livecycle-client [C:\Adobe\LiveCycle8\LiveCycle_ES_SDK\client-libs\common]

2. Restart ColdFusion Application Service

transformPDF_EJB.cfm
<!—
Modify these three variables to match your environment
** Be sure the fileInput is a PDF Form
—>
<cfset EJB_ENDPOINT = "jnp://68.175.120.115:1099">
<cfset fileInput = "C:\temp\test.pdf">
<cfset fileOutput = "C:\temp\output.pdf">

<cfscript>
// Create ServiceClientFactoryProperties
serviceClientFactoryProperties = CreateObject("java","com.adobe.idp.dsc.clientsdk.ServiceClientFactoryProperties");
connectionProps = CreateObject("java","java.util.Properties").init();
connectionProps.setProperty(serviceClientFactoryProperties.DSC_DEFAULT_EJB_ENDPOINT, EJB_ENDPOINT);
connectionProps.setProperty(serviceClientFactoryProperties.DSC_TRANSPORT_PROTOCOL, serviceClientFactoryProperties.DSC_EJB_PROTOCOL);
connectionProps.setProperty(serviceClientFactoryProperties.DSC_SERVER_TYPE, "Jboss");
connectionProps.setProperty(serviceClientFactoryProperties.DSC_CREDENTIAL_USERNAME, "administrator");
connectionProps.setProperty(serviceClientFactoryProperties.DSC_CREDENTIAL_PASSWORD, "password");
</cfscript>

<cfscript>
// Initialize ServiceClientFactory with serviceClientFactoryProperties
myFactory = CreateObject("java","com.adobe.idp.dsc.clientsdk.ServiceClientFactory").createInstance(connectionProps);

// Initialize FileInputStream with fileInput Variable
fileInputStream = CreateObject("java","java.io.FileInputStream").init(fileInput);

// Initialize OutputClient with ServiceClientFactory properties
outClient = CreateObject("java","com.adobe.livecycle.output.client.OutputClient").init(myFactory);

// Set inPDF Document
inPDF = CreateObject("java","com.adobe.idp.Document").init(fileInputStream);

// Set outPDF Document For Result Handling
outPDF = CreateObject("java","com.adobe.idp.Document");

// transformPDF Parameter Settings: You can avoid these properties and simply cast nulls as in the commented invoke below
TransformationFormat = CreateObject("java","com.adobe.livecycle.output.client.TransformationFormat");
PDFARevisionNumber = CreateObject("java","com.adobe.livecycle.output.client.PDFARevisionNumber");
PDFAConformance = CreateObject("java","com.adobe.livecycle.output.client.PDFAConformance");

// Initiate The transformPDF Method
outPDF = outClient.transformPDF(inPDF,TransformationFormat.PDF,PDFARevisionNumber.Revision_1,"",PDFAConformance.A);
// If you want to use null make sure you JavaCast
//outPDF = outClient.transformPDF(inPDF,TransformationFormat.PDF,JavaCast( "null", 0 ),"",JavaCast( "null", 0 ));

// Initialize FileOutputStream with fileOutput Variable
fileOutputStream = CreateObject("java","java.io.File").init(fileOutput);

// Write The File…
outPDF.copyToFile(fileOutputStream);
</cfscript>

You can also download the source here Download Source

Invoking Forms Service (renderPDFForm) via EJB

This sample provides the basics for invoking the renderPDFForm method of the LiveCycle FormsService.

This sample assumes you are using LiveCycle on Jboss. If you are using a different Java server, you will need to modify a few paramaters, but the basics are the same.

Environment Setup
1. Copy the following required jar files from your LiveCycle Installation to your {ColdFusion Install Directory}\wwwroot\WEB-INF\lib.
jbossall-client.jar [C:\Adobe\LiveCycle8\jboss\client]
adobe-utilities.jar [C:\Adobe\LiveCycle8\LiveCycle_ES_SDK\client-libs\jboss]
adobe-output-client [C:\Adobe\LiveCycle8\LiveCycle_ES_SDK\client-libs\common]
adobe-usermanager-client [C:\Adobe\LiveCycle8\LiveCycle_ES_SDK\client-libs\common]
adobe-livecycle-client [C:\Adobe\LiveCycle8\LiveCycle_ES_SDK\client-libs\common]
adobe-forms-client [C:\Adobe\LiveCycle8\LiveCycle_ES_SDK\client-libs\common]

2. Restart ColdFusion Application Service

renderForm_EJB.cfm
<!—
Modify these three variables to match your environment
** Be sure the fileInput is a PDF Form XDP
—>

<cfset EJB_ENDPOINT = "jnp://68.175.120.115:1099">

<!— Document Parameters —>
<cfset inXDP = "CAR.xdp"> <!– PDF Form File Name Source: Do Not Include Path Info —>
<cfset inXML = "C:\temp\CAR.xml">
<cfset outPDF = "C:\temp\CAR1.pdf">

<!— URLSpec Parameters —>
<cfset applicationWebRoot = ”>
<cfset targetURL = ”>
<cfset contentRootURI = ‘C:\Adobe\forms\’> <!— The Directory of the inXDP file located on the LiveCycle installed server —>
<cfset baseURL = ”>

<cfscript>
// Create ServiceClientFactoryProperties
serviceClientFactoryProperties = CreateObject("java","com.adobe.idp.dsc.clientsdk.ServiceClientFactoryProperties");
connectionProps = CreateObject("java","java.util.Properties").init();
connectionProps.setProperty(serviceClientFactoryProperties.DSC_DEFAULT_EJB_ENDPOINT, EJB_ENDPOINT);
connectionProps.setProperty(serviceClientFactoryProperties.DSC_TRANSPORT_PROTOCOL, serviceClientFactoryProperties.DSC_EJB_PROTOCOL);
connectionProps.setProperty(serviceClientFactoryProperties.DSC_SERVER_TYPE, "Jboss");
connectionProps.setProperty(serviceClientFactoryProperties.DSC_CREDENTIAL_USERNAME, "administrator");
connectionProps.setProperty(serviceClientFactoryProperties.DSC_CREDENTIAL_PASSWORD, "password");

// Initialize ServiceClientFactory with serviceClientFactoryProperties
myFactory = CreateObject("java","com.adobe.idp.dsc.clientsdk.ServiceClientFactory").createInstance(connectionProps);

// Initialize OutputClient with ServiceClientFactory properties
formsClient = CreateObject("java","com.adobe.livecycle.formsservice.client.FormsServiceClient").init(myFactory);

// Initialize FileInputStream with fileInput Variable
inXML_FileInputStream = CreateObject("java","java.io.FileInputStream").init(inXML);

// Set inPDF Document
inXML = CreateObject("java","com.adobe.idp.Document").init(inXML_FileInputStream);

PDFFormRenderSpec = CreateObject("java","com.adobe.livecycle.formsservice.client.PDFFormRenderSpec").init();
PDFVersion = CreateObject("java","com.adobe.livecycle.formsservice.client.PDFVersion");
PDFFormRenderSpec.setPDFVersion(PDFVersion.PDFVersion_1_5);

// Create URLSpec Object
URLSpec = CreateObject("java","com.adobe.livecycle.formsservice.client.URLSpec").init();
URLSpec.setApplicationWebRoot(applicationWebRoot);
URLSpec.setContentRootURI(contentRootURI);
URLSpec.setTargetURL(targetURL);

// Initiate The renderPDFForm Method
FormsResult = formsClient.renderPDFForm(inXDP,inXML,PDFFormRenderSpec,URLSpec,JavaCast( "null", "" ));

// Set outPDF Document For Result Handling
FormsResultPDF = FormsResult.getOutputContent();

// Initialize FileOutputStream with fileOutput Variable
fileOutputStream = CreateObject("java","java.io.File").init(outPDF);

FormsResultPDF.copyToFile(fileOutputStream);
</cfscript>

You can also download the source here Download Source