|
|
Quick Start: Converting a Microsoft Word document to a PDF document using LiveCycle Remoting<?xml version="1.0" encoding="utf-8"?><mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" xmlns="*"creationComplete="initializeChannelSet();"><mx:Script><![CDATA[import mx.rpc.livecycle.DocumentReference;import flash.net.FileReference;import flash.net.URLRequest;import flash.events.Event;import flash.events.DataEvent;import mx.messaging.ChannelSet;import mx.messaging.channels.AMFChannel;import mx.rpc.events.ResultEvent;import mx.collections.ArrayCollection;// Classes used in file retrievalprivate var fileRef:FileReference = new FileReference();private var docRef:DocumentReference = new DocumentReference();private var fName:String = new String();private var parentResourcePath:String = "/";private var serverPort:String = "servername:portnumber";private var now1:Date;// Holds information returned from LiveCycle[Bindable]public var progressList:ArrayCollection = new ArrayCollection();// Set up channel set to talk to LiveCycle.// This must be done before calling any service or process, but only// once for the entire application.// Note that this uses runtime configuration to configure the// destination correctly, so// no other setup is needed in remoting-config.xml.private function initializeChannelSet():void {var cs:ChannelSet= new ChannelSet();cs.addChannel(new AMFChannel("remoting-amf", "http://" + serverPort + "/remoting/messagebroker/amf"));PDFService.setCredentials("administrator", "password");PDFService.channelSet = cs;}// Call this method to upload the file.// This creates a file picker and lets the user select the file to upload.private function uploadFile():void {fileRef.addEventListener(Event.SELECT, selectHandler);fileRef.addEventListener(DataEvent.UPLOAD_COMPLETE_DATA,completeHandler);fileRef.browse();}// Gets called for selected file. Does the actual upload via the file upload servlet.private function selectHandler(event:Event):void {var request:URLRequest = new URLRequest("http://" + serverPort + "/remoting/lcfileupload");fName = fileRef.name;fileRef.upload(request);}// Called once the file is completely uploaded. Now it is safe to access// that object for other things.private function completeHandler(event:DataEvent):void {now1 = new Date();// At this point we can do whatever we want with the file that has been uploaded.// Our docRef variable has the object. Refer to the asdoc for// DocumentReference for methods and properties.docRef.url = event.data as String;docRef.referenceType=DocumentReference.REF_TYPE_URL;executeConvertToPDF();}// prepares parameters for conversion and makes the callpublic function executeConvertToPDF():void {var paramObject:Object = new Object();paramObject["inputDocument"] = docRef;paramObject["fileName"] = fileRef.name;paramObject["fileTypeSettings"] = "Standard";paramObject["pdfSettings"] = "Standard";paramObject["securitySettings"] = "No Security";PDFService.CreatePDF(paramObject);}// this method handles a successful createPDF invocationpublic function handleCreatePDF(event:ResultEvent):void{var progObject:Object = new Object();// LC Remoting always returns a map in event.result.// This method returns a map, too.var res:Object = event.result["Result"];// Within the Result map is another Map.var dr:DocumentReference = res["ConvertedDoc"] as DocumentReference;var now2:Date = new Date();// These fields map to columns in the DataGridprogObject.filename = fName;progObject.timing = (now2.time - now1.time).toString();progObject.state = "Success";now1 = new Date();progObject.link = "<a href='" + dr.url + "'>Right-click to open in new window</a>";progressList.addItem(progObject);}private function resultHandler(event:ResultEvent):void {// Do anything else here.}]]></mx:Script><mx:RemoteObject id="PDFService" destination="GeneratePDFService"result="resultHandler(event);"><mx:method name="CreatePDF" result="handleCreatePDF(event)"/></mx:RemoteObject><mx:Panel id="lcPanel" title="PDF Generation LiveCycle Remoting Example"height="30%" width="35%" paddingTop="10" paddingLeft="10" paddingRight="10"paddingBottom="10"><mx:Label width="100%" color="blue"text="Select a DOC file. This example automatically converts a Word doc to PDF."/><mx:DataGrid x="10" y="0" width="600" id="idProgress" editable="false"dataProvider="{progressList}" height="231" selectable="false" ><mx:columns><mx:DataGridColumn headerText="Filename" width="200" dataField="filename" editable="false"/><mx:DataGridColumn headerText="State" width="75" dataField="state" editable="false"/><mx:DataGridColumn headerText="Timing" width="75" dataField="timing" editable="false"/><mx:DataGridColumn dataField="link" editable="false" headerText="Click to Open"><mx:itemRenderer><mx:Component><mx:Text x="0" y="0" width="100%" htmlText="{data.link}"/></mx:Component></mx:itemRenderer></mx:DataGridColumn></mx:columns></mx:DataGrid><mx:Button label="Select File" click="uploadFile()" /></mx:Panel></mx:Application>
Send me an e-mail when comments are added to this page | Comment Report
Current page: http://livedocs.adobe.com/livecycle/es/sdkHelp/programmer/sdkHelp/quickStarts_GeneratePDF.11.4.html