API Quick Starts (Code Examples) > Assembler Service API Quick Starts > Quick Start: Assembling PDF Documents with Bookmarks using the web service API

Quick Start: Assembling PDF Documents with Bookmarks using the web service API
The C# Java code example assembles a PDF document that contains bookmarks. The name of the DDX document is bookmarkDDX.xml. The name of the bookmark XML document that describes the bookmarks to add to the PDF document is bookmarks.xml. The result PDF document is saved as a PDF file named AssemblerResultBookmarks.pdf. For information about the bookmarkDDX.xml or the bookmarks.xml files that are used in this code example, see Assembling PDF Documents with Bookmarks.
/*
 * 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;
 
namespace AssemblerPDFWithBookmarks
{
    class AssemblerTest
    {
        [STAThread]
        static void Main(string[] args)
        {
            try
            {
                // Create an AssemblerServiceService object
                AssemblerServiceService asOb = new AssemblerServiceService();
 
                // Provide authentication credentials to the service
                asOb.Credentials = new System.Net.NetworkCredential(
                    "administrator",
                    "password"
                    );
 
                // Create BLOBs that represents the input DDX file and input documents
                BLOB ddxDoc = new BLOB();
                BLOB pdfDoc = new BLOB();
                BLOB bookMarkDoc = new BLOB();
 
                // Get the input DDX document, input PDF source file
                //and the Bookmark XML document
                string ddxFileName = "C:\\bookmarkDDX.xml";
                FileStream ddxFs = new FileStream(ddxFileName, FileMode.Open);
                string pdfFile = "C:\\Loan.pdf";
                FileStream pdfFileFs = new FileStream(pdfFile, FileMode.Open);
                string bookmarkInfo = "C:\\bookmarks.xml";
                FileStream bookmarkInfoFs = new FileStream(bookmarkInfo, FileMode.Open);
 
                // Get the lengths of the file streams and create byte arrays
                int ddxLen = (int)ddxFs.Length;
                byte[] ddxByteArray = new byte[ddxLen];
                int pdfLen = (int)pdfFileFs.Length;
                byte[] pdfByteArray = new byte[pdfLen];
                int bookMarkLen = (int)bookmarkInfoFs.Length;
                byte[] bookMarkByteArray = new byte[bookMarkLen];
 
                // Populate the byte arrays with the contents of the file streams
                ddxFs.Read(ddxByteArray, 0, ddxLen);
                pdfFileFs.Read(pdfByteArray, 0, pdfLen);
                bookmarkInfoFs.Read(bookMarkByteArray, 0, bookMarkLen);
 
                // Populate the BLOB objects
                ddxDoc.binaryData = ddxByteArray;
                pdfDoc.binaryData = pdfByteArray;
                bookMarkDoc.binaryData = bookMarkByteArray;
 
                //Create the map containing the input files
                mapItem[] inputMap = new mapItem[2];
                inputMap[0] = new mapItem();
                inputMap[1] = new mapItem();
                inputMap[0].key = "Loan.pdf";
                inputMap[0].value = pdfDoc;
                inputMap[1].key = "doc2";
                inputMap[1].value = bookMarkDoc;
 
                //Create an AssemblerOptionsSpec object
                AssemblerOptionSpec assemblerSpec = new AssemblerOptionSpec();
                assemblerSpec.failOnError = false;
 
                //Send the request to the Assembler Service
                AssemblerResult result = asOb.invoke(ddxDoc, inputMap, assemblerSpec);
 
                //Extract the newly created PDF document from the returned map
                BLOB outDoc = null;
                mapItem[] mapResult = result.documents;
                for (int i = 0; i < mapResult.Length; i++)
                {
                    String myKey = (String)(mapResult[i].key);
                    if (myKey == "FinalDoc.pdf")
                    {
                        outDoc = (BLOB)(mapResult[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:\\AssemblerResultBookmarks.pdf";
                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 containing bookmarks was assembled.");
            }
 
            catch (Exception ee)
            {
                Console.WriteLine("An unexpected exception was encountered: " + ee.Message + "\n" + ee.StackTrace);
            }
        }
    }
}

API Quick Starts (Code Examples) > Assembler Service API Quick Starts > Quick Start: Assembling PDF Documents with Bookmarks 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/001484_3.html