Quick Start: Converting a Microsoft Word document to a PDF document using the web service APIThe following C# .NET example converts a Word file named Loan.doc to a PDF document named Loan.pdf. (See Converting from Native File Formats to PDF.)/** Ensure that you create a .NET client assembly that uses* base64 encoding. This is required to populate a BLOB* object with data or retrieve data from a BLOB object.** For information, see "Invoking LiveCycle ES using Base64 Encoding"* in Programming with LiveCycle ES*/using System;using System.Collections;using System.ComponentModel;using System.Data;using System.IO;using System.Web.Services;namespace GeneratePdfWSApp{class GeneratePdf_CreatePDF{[STAThread]static void Main(string[] args){try{// Create a GeneratePDFServiceServiceWse object (since DIME attachments are used)GeneratePDFServiceService svc = new GeneratePDFServiceService();// Provide authentication credentials to the servicesvc.Credentials = new System.Net.NetworkCredential("administrator","password");// Create a BLOB that represents the input Microsoft Word fileBLOB inDoc = new BLOB();inDoc.attachmentID = "test";String path = "C:\\Adobe\\Loan.doc";FileStream fs = new FileStream(path, FileMode.Open);//Get the length of the file streamint len = (int)fs.Length;byte[] ByteArray=new byte[len];//Populate the byte array with the contents of the FileStream objectfs.Read(ByteArray, 0, len);inDoc.binaryData = ByteArray;// Specify the PDF and security settingsString adobePDFSettings = "Standard";String securitySettings = "No Security";String fileTypeSettings = "Standard";//Convert the Word file to a PDF documentmapItem[] createPDFResults = svc.CreatePDF(inDoc,path,fileTypeSettings,adobePDFSettings,securitySettings,null,null);//Obtain the converted PDF documentfor (int count = 0; count < createPDFResults.Length; ++count){//Get an item from the mapmapItem mapEntry = createPDFResults[count];String mapKey = mapEntry.key as String;//The new PDF will always have the map key "ConvertedDoc"if (mapKey.Equals("ConvertedDoc")){BLOB resultBlob = mapEntry.value as BLOB;byte[] binaryFile = resultBlob.binaryData;string FILE_NAME = "C:\\Adobe\\Loan.pdf" ;FileStream fs2 = new FileStream(FILE_NAME, FileMode.OpenOrCreate);//Create a BinaryWriter objectBinaryWriter w = new BinaryWriter(fs2);w.Write(binaryFile);w.Close();fs2.Close();}}}catch (Exception ee){Console.WriteLine("An unexpected exception was encountered: " + ee.Message + "\n" +ee.StackTrace);}}}}
| Programming with LiveCycle ES (LiveDocs) |
| Adobe LiveCycle ES Update 1 |
Send me an e-mail when comments are added to this page | Comment Report
Current page: http://livedocs.adobe.com/livecycle/8.2/programLC/programmer/help/000090.html