API Quick Starts (Code Examples) > Generate PDF Service API Quick Starts > Quick Start: Converting a PDF document to an RTF file using the web service API

Quick Start: Converting a PDF document to an RTF file using the web service API
The following C# .NET example converts a PDF document named Loan.pdf to an RTF document named Loan.rtf. (See Converting HTML Documents to PDF Documents.)
/*
 * 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_ExportPDF
    {
        [STAThread]
        static void Main(string[] args)
        {
            try
            {
                // Create a GeneratePDFServiceServicee object 
                GeneratePDFServiceService svc = new GeneratePDFServiceService();
 
                // Provide authentication credentials to the service
                svc.Credentials = new System.Net.NetworkCredential(
                        "administrator",
                        "password"
                        );
 
                //Create a BLOB that stores the PDF document to convert
                BLOB inDoc = new BLOB();
 
                //Specify the location of the PDF document
                string inPath = "C:\\Adobe\\Loan.pdf";
                FileStream fs = new FileStream(inPath, FileMode.Open);
 
                //Get the length of the file stream 
                int lenFS = (int)fs.Length;
                byte[] byteArray = new byte[lenFS];
 
                //Populate the byte array with the contents of the FileStream object
                fs.Read(byteArray, 0, lenFS);
                inDoc.binaryData = byteArray;
 
                //Convert the PDF document to a RTF document
                mapItem[] exportPDFResults = svc.ExportPDF(
                    inDoc,
                    inPath,
                    "RTF",
                    null
                    );
 
                //Extract the newly created RTF document
                BLOB outDoc = null;
                for (int i = 0; i < exportPDFResults.Length; i++)
                {
                    String myKey = (String)(exportPDFResults[i].key);
                    if (myKey == "ConvertedDoc")
                    {
                        outDoc = (BLOB)(exportPDFResults[i].value);
                    }
                }
 
                //Populate a byte array with the BLOB
                byte[] outByteArray = outDoc.binaryData;
 
                //Create a new file containing the returned PDF document
                string FILE_NAME = "C:\\Adobe\\Loan.rtf";
                FileStream fs2 = new FileStream(FILE_NAME, FileMode.OpenOrCreate);
                BinaryWriter w = new BinaryWriter(fs2);
                w.Write(outByteArray);
                w.Close();
                fs2.Close();
 
                Console.WriteLine("The PDF file was converted to a RTF document.");
            }
 
            catch (Exception ee)
            {
                Console.WriteLine(
                    "An unexpected exception was encountered: " +
                    ee.Message +
                    "\n" +
                    ee.StackTrace
                    );
            }
        }
    }
}
 
 
 

API Quick Starts (Code Examples) > Generate PDF Service API Quick Starts > Quick Start: Converting a PDF document to an RTF file using the web service API

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/000096.html