The following C# code example creates a PDF portfolio.
The PDF portfolio is saved as a PDF file named AssemblerResultPortfolio.pdf.
(See Assembling PDF Portfolios.)
???/**
* Ensure that you create a .NET project that uses
* MS Visual Studio 2008 and version 3.5 of the .NET
* framework. This is required to invoke a
* LiveCycle service using MTOM.
*
* For information, see "Invoking LiveCycle using MTOM" in Programming with LiveCycle
*
* This is the DDX file is used to create a PDF portfolio:
* <DDX xmlns="http://ns.adobe.com/DDX/1.0/">
* <PDF result="portfolio1.pdf">
* <Portfolio>
* <Navigator source="myNavigator">
* <Resource name="navigator/image.xxx" source="myImage.png"/>
* </Navigator>
* </Portfolio>
* <PackageFiles source="dog1" >
* <FieldData name="X">72</FieldData>
* <FieldData name="Y">72</FieldData>
* <File filename="saint_bernard.jpg" mimetype="image/jpeg"/>
* </PackageFiles>
* <PackageFiles source="dog2" >
* <FieldData name="X">120</FieldData>
* <FieldData name="Y">216</FieldData>
* <File filename="greyhound.pdf"/>
* </PackageFiles>
* </PDF>
* </DDX>
*
*/
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.ServiceModel;
using System.IO;
using CreatePDFPortfolio.ServiceReference1;
namespace CreatePDFPortfolio
{
class Program
{
static void Main(string[] args)
{
try
{
//Create an AssemblerServiceClient object
AssemblerServiceClient assembleClient = new AssemblerServiceClient();
assembleClient.Endpoint.Address = new System.ServiceModel.EndpointAddress("http://hiro-xp:8080/soap/services/AssemblerService?blob=mtom");
//Enable BASIC HTTP authentication
BasicHttpBinding b = (BasicHttpBinding)assembleClient.Endpoint.Binding;
b.MessageEncoding = WSMessageEncoding.Mtom;
assembleClient.ClientCredentials.UserName.UserName = "administrator";
assembleClient.ClientCredentials.UserName.Password = "password";
b.Security.Transport.ClientCredentialType = HttpClientCredentialType.Basic;
b.Security.Mode = BasicHttpSecurityMode.TransportCredentialOnly;
b.MaxReceivedMessageSize = 4000000;
b.MaxBufferSize = 4000000;
b.ReaderQuotas.MaxArrayLength = 4000000;
// Create BLOBs that represents the input files required to create a PDF Portfolio
BLOB myDDX = new BLOB();
BLOB myNav = new BLOB();
BLOB myPDFNavImageSource = new BLOB();
BLOB myPDFDog1Source = new BLOB();
BLOB myPDFDog2Source = new BLOB();
// Get the input DDX document and input PDF sources
string ddxFileName = "C:\\Adobe\portfolioAssembly.xml";
FileStream ddxFs = new FileStream(ddxFileName, FileMode.Open);
string myNav2 = "C:\\Adobe\AdobeOnImage.nav";
FileStream myNavFile = new FileStream(myNav2, FileMode.Open);
string pdfImageSource = "C:\\Adobe\myImage.png";
FileStream mySourceNavImage = new FileStream(pdfImageSource, FileMode.Open);
string image1 = "C:\\Adobe\saint_bernard.jpg";
FileStream mySourceDog1 = new FileStream(image1, FileMode.Open);
string image2 = "C:\\Adobe\greyhound.pdf";
FileStream mySourceDog2 = new FileStream(image2, FileMode.Open);
// Get the lengths of the file streams and create byte arrays
int ddxLen = (int)ddxFs.Length;
byte[] ddxByteArray = new byte[ddxLen];
int myNavFileLen = (int)myNavFile.Length;
byte[] myNavFileLenByteArray = new byte[myNavFileLen];
int mySourceNavImageLen = (int)mySourceNavImage.Length;
byte[] mySourceNavImageByteArray = new byte[mySourceNavImageLen];
int image1Len = (int)mySourceDog1.Length;
byte[] image1ByteArray = new byte[image1Len];
int image2Len = (int)mySourceDog2.Length;
byte[] image2ByteArray = new byte[image2Len];
// Populate the byte arrays with the contents of the file streams
ddxFs.Read(ddxByteArray, 0, ddxLen);
myNavFile.Read(myNavFileLenByteArray, 0, myNavFileLen);
mySourceNavImage.Read(mySourceNavImageByteArray, 0, mySourceNavImageLen);
mySourceDog1.Read(image1ByteArray, 0, image1Len);
mySourceDog2.Read(image2ByteArray, 0, image2Len);
// Populate the BLOB objects
myDDX.MTOM = ddxByteArray;
myNav.MTOM = myNavFileLenByteArray;
myPDFNavImageSource.MTOM = mySourceNavImageByteArray;
myPDFDog1Source.MTOM = image1ByteArray;
myPDFDog2Source.MTOM = image2ByteArray;
// Create the map containing the PDF source documents
MyMapOf_xsd_string_To_xsd_anyType inputMap = new MyMapOf_xsd_string_To_xsd_anyType();
MyMapOf_xsd_string_To_xsd_anyType_Item inNavDoc = new MyMapOf_xsd_string_To_xsd_anyType_Item();
inNavDoc.key = "myNavigator";
inNavDoc.value = myNav;
MyMapOf_xsd_string_To_xsd_anyType_Item inNavImageSource = new MyMapOf_xsd_string_To_xsd_anyType_Item();
inNavImageSource.key = "myImage.png";
inNavImageSource.value = myPDFNavImageSource;
MyMapOf_xsd_string_To_xsd_anyType_Item inPDFDog1Source = new MyMapOf_xsd_string_To_xsd_anyType_Item();
inPDFDog1Source.key = "dog1";
inPDFDog1Source.value = myPDFDog1Source;
MyMapOf_xsd_string_To_xsd_anyType_Item inPDFDog2Source = new MyMapOf_xsd_string_To_xsd_anyType_Item();
inPDFDog2Source.key = "dog2";
inPDFDog2Source.value = myPDFDog2Source;
//Add all elements to the collection
inputMap.Add(inNavDoc);
inputMap.Add(inNavImageSource);
inputMap.Add(inPDFDog1Source);
inputMap.Add(inPDFDog2Source);
// Create an AssemblerOptionsSpec object
AssemblerOptionSpec assemblerSpec = new AssemblerOptionSpec();
assemblerSpec.failOnError = false;
// Send the request to the Assembler Service
AssemblerResult result = assembleClient.invoke(myDDX, inputMap, assemblerSpec);
// Extract the newly created PDF document from the returned map
BLOB outDoc = null;
CreatePDFPortfolio.ServiceReference1.Map mapResult = result.documents;
for (int i = 0; i < mapResult.Count; i++)
{
String myKey = (String)(mapResult[i].key);
if (myKey == "portfolio1.pdf")
{
outDoc = (BLOB)(mapResult[i].value);
}
}
//Populate a byte array with the BLOB
byte[] outByteArray = outDoc.MTOM;
//Create a new file containing the returned PDF document
string FILE_NAME = "C:\\AssemblerResultPortfolio.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 portfolio document was created.");
}
catch (Exception ee)
{
Console.WriteLine("An unexpected exception was encountered: " + ee.Message + "\n" + ee.StackTrace);
}
}
}
}
|
|
|