The following Java 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 Java proxy files that consume
* the Assembler services WSDL. You can use JAX-WS to create
* the proxy Java files.
*
* For information, see "Invoking LiveCycle using SwaRef" in Programming with LiveCycle.
*/
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.InputStream;
import java.io.OutputStream;
import java.util.Iterator;
import java.util.List;
import javax.activation.DataHandler;
import javax.activation.FileDataSource;
import javax.xml.ws.BindingProvider;
import org.apache.xml.xml_soap.Map;
import org.apache.xml.xml_soap.MapItem;
import com.adobe.idp.services.*;
public class CreatePDFPortfolioSwaRef {
public static void main(String[] args) {
try{
// Setting configurations to retrieve the Web service
String url = "http://hiro-xp:8080/soap/services/AssemblerService?blob=swaRef";
String username = "administrator";
String password = "password";
// Create the service Client objects needed
AssemblerServiceService assembler = new AssemblerServiceService();
AssemblerService assembClient = assembler.getAssemblerService();
// Retrieve the Web services from the LiveCycle Server.
((BindingProvider) assembClient).getRequestContext().put(BindingProvider.ENDPOINT_ADDRESS_PROPERTY, url);
((BindingProvider) assembClient).getRequestContext().put(BindingProvider.USERNAME_PROPERTY, username);
((BindingProvider) assembClient).getRequestContext().put(BindingProvider.PASSWORD_PROPERTY, password);
// //Create a FileInputStream object based on an existing DDX file
// FileInputStream myDDXFile = new FileInputStream("C:\\Adobe\portfolioAssembly.xml");
// FileInputStream myNavFile = new FileInputStream("C:\\Adobe\AdobeOnImage.nav");
//
// //Create a Document object based on the DDX file
// Document myDDX = new Document(myDDXFile);
// Document myNav = new Document(myNavFile);
//
// //Create a Map object to store PDF source documents
MyMapOfXsdStringToXsdAnyType input = new MyMapOfXsdStringToXsdAnyType();
// FileInputStream mySourceNavImage = new FileInputStream("C:\\Adobe\myImage.png");
// FileInputStream mySourceDog1 = new FileInputStream("C:\\Adobe\saint_bernard.jpg");
// FileInputStream mySourceDog2 = new FileInputStream("C:\\Adobe\greyhound.pdf");
//
// //Create a Document object based on the myImage.png source file
// Document myPDFNavImageSource = new Document(mySourceNavImage);
//
// //Create a Document object based on the MyFirstFile.pdf source file
// Document myPDFDog1Source = new Document(mySourceDog1);
//
// //Create a Document object based on the MySecondFile.txt source file
// Document myPDFDog2Source = new Document(mySourceDog2);
String path0 = "C:\\Adobe\portfolioAssembly.xml";
FileDataSource ds0 = new FileDataSource(path0);
DataHandler handler0 = new DataHandler(ds0);
BLOB myDDX = new BLOB();
myDDX.setSwaRef(handler0);
String path1 = "C:\\Adobe\AdobeOnImage.nav";
FileDataSource ds1 = new FileDataSource(path1);
DataHandler handler1 = new DataHandler(ds1);
BLOB myNav = new BLOB();
myNav.setSwaRef(handler1);
MyMapOfXsdStringToXsdAnyTypeItem myNav_mapItem = new MyMapOfXsdStringToXsdAnyTypeItem();
myNav_mapItem.setKey("myNavigator");
myNav_mapItem.setValue(myNav);
String path2 = "C:\\Adobe\myImage.png";
FileDataSource ds2 = new FileDataSource(path2);
DataHandler handler2 = new DataHandler(ds2);
BLOB myPDFNavImageSource = new BLOB();
myPDFNavImageSource.setSwaRef(handler2);
MyMapOfXsdStringToXsdAnyTypeItem myPDFNavImageSource_mapItem = new MyMapOfXsdStringToXsdAnyTypeItem();
myPDFNavImageSource_mapItem.setKey("myImage.png");
myPDFNavImageSource_mapItem.setValue(myPDFNavImageSource);
String path3 = "C:\\Adobe\saint_bernard.jpg";
FileDataSource ds3 = new FileDataSource(path3);
DataHandler handler3 = new DataHandler(ds3);
BLOB myPDFDog1Source = new BLOB();
myPDFDog1Source.setSwaRef(handler3);
MyMapOfXsdStringToXsdAnyTypeItem myPDFDog1Source_mapItem = new MyMapOfXsdStringToXsdAnyTypeItem();
myPDFDog1Source_mapItem.setKey("dog1");
myPDFDog1Source_mapItem.setValue(myPDFDog1Source);
String path4 = "C:\\Adobe\greyhound.pdf";
FileDataSource ds4 = new FileDataSource(path4);
DataHandler handler4 = new DataHandler(ds4);
BLOB myPDFDog2Source = new BLOB();
myPDFDog2Source.setSwaRef(handler4);
MyMapOfXsdStringToXsdAnyTypeItem myPDFDog2Source_mapItem = new MyMapOfXsdStringToXsdAnyTypeItem();
myPDFDog2Source_mapItem.setKey("dog2");
myPDFDog2Source_mapItem.setValue(myPDFDog2Source);
//Place two entries into the Map object
input.getItem().add(myNav_mapItem);
input.getItem().add(myPDFNavImageSource_mapItem);
input.getItem().add(myPDFDog1Source_mapItem);
input.getItem().add(myPDFDog2Source_mapItem);
//Create an AssemblerOptionsSpec object
AssemblerOptionSpec assemblerSpec = new AssemblerOptionSpec();
assemblerSpec.setFailOnError(false);
//Submit the job to Assembler service
AssemblerResult jobResult = assembClient.invoke(myDDX,input,assemblerSpec);
Map allDocs = jobResult.getDocuments();
//Retrieve the result PDF document from the Map object
// Extract the newly created PDF document from the returned map
BLOB outDoc = null;
List<MapItem> mapResult = allDocs.getItem();
Iterator<MapItem> rit = mapResult.iterator();
while(rit.hasNext())
{
MapItem resultItem = rit.next();
String myKey = (String)(resultItem.getKey());
if (myKey.equals("portfolio1.pdf"))
{
outDoc = (BLOB)(resultItem.getValue());
}
}
File f = new File("C:\\Adobe\AssemblerResultPortfolio.pdf");
BLOB outBlob = outDoc;
DataHandler handler5 = outBlob.getSwaRef();
//Get an InputStream from DataHandler and
//write to a file
InputStream inputStream = handler5.getInputStream();
OutputStream out = new FileOutputStream(f);
//Iterate through the buffer
byte buf[] = new byte[1024];
int len;
while ((len = inputStream.read(buf)) > 0)
out.write(buf, 0, len);
out.close();
inputStream.close();
}catch (Exception e) {
e.printStackTrace();
}
}
}
|
|
|