The following Java code example assembles a PDF document
with unique page identifiers (bates numbering). Notice that the
name of the DDX document is shell_Bates.xml. The PDF document
that is returned from the Assembler service is saved as a PDF file
named AssemblerResultBatesPDF.pdf. (See Assembling Documents Using Bates Numbering.)
/**
* 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
*
* The following XML represents the DDX document used in this quick start:
* <?xml version="1.0" encoding="UTF-8"?>
* <DDX xmlns="http://ns.adobe.com/DDX/1.0/">
* <PDF result="out.pdf">
* <Header>
* <Center>
* <StyledText>
* <p font-size="20pt"><BatesNumber/></p>
* </StyledText>
* </Center>
* </Header>
* <PDF source="map.pdf" />
* <PDF source="directions.pdf" />
* </PDF>
* </DDX>
*/
import java.io.*;
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.MapItem;
import com.adobe.idp.services.*;
public class BatesNumberSWAref {
public static void main(String[] args){
try{
//Create an AssemblerServiceService object
AssemblerServiceService assembler = new AssemblerServiceService();
AssemblerService assembClient = assembler.getAssemblerService();
//Set connection values required to invoke LiveCycle
String url = "http://hiro-xp:8080/soap/services/AssemblerService?blob=swaRef";
String username = "administrator";
String password = "password";
((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 BLOBs that represents the input DDX file and PDF sources
String path1 = "C:\\shell_Bates.xml";
FileDataSource ds1 = new FileDataSource(path1);
DataHandler handler1 = new DataHandler(ds1);
BLOB ddxDoc = new BLOB();
ddxDoc.setSwaRef(handler1);
String path2 = "C:\\map.pdf";
FileDataSource ds2 = new FileDataSource(path2);
DataHandler handler2 = new DataHandler(ds2);
BLOB mapDoc = new BLOB();
mapDoc.setSwaRef(handler2);
String path3 = "C:\\directions.pdf";
FileDataSource ds3 = new FileDataSource(path3);
DataHandler handler3 = new DataHandler(ds3);
BLOB directionsDoc = new BLOB();
directionsDoc.setSwaRef(handler3);
// Create the map containing the PDF source documents
MyMapOfXsdStringToXsdAnyType inputMap = new MyMapOfXsdStringToXsdAnyType();
List<MyMapOfXsdStringToXsdAnyTypeItem> inputMapItemList = inputMap.getItem();
MyMapOfXsdStringToXsdAnyTypeItem mapItem = new MyMapOfXsdStringToXsdAnyTypeItem();
MyMapOfXsdStringToXsdAnyTypeItem directionsItem = new MyMapOfXsdStringToXsdAnyTypeItem();
mapItem.setKey("map.pdf");
mapItem.setValue(mapDoc);
directionsItem.setKey("directions.pdf");
directionsItem.setValue(directionsDoc);
inputMapItemList.add(mapItem);
inputMapItemList.add(directionsItem);
// Create an AssemblerOptionsSpec object
AssemblerOptionSpec assemblerSpec = new AssemblerOptionSpec();
assemblerSpec.setFailOnError(false);
//Set the initial number to 100
assemblerSpec.setFirstBatesNumber(100);
// Send the request to the Assembler Service
AssemblerResult result = assembClient.invoke(ddxDoc, inputMap, assemblerSpec);
// Extract the newly created PDF document from the returned map
BLOB outDoc = null;
List<MapItem> mapResult = result.getDocuments().getItem();
Iterator<MapItem> rit = mapResult.iterator();
while(rit.hasNext())
{
MapItem resultItem = rit.next();
String myKey = (String)(resultItem.getKey());
if (myKey.equals("out.pdf"))
{
outDoc = (BLOB)(resultItem.getValue());
}
}
//Populate a byte array with BLOB data
File f = new File("C:\\AssemblerResultBatesPDF.pdf");
BLOB outBlob = outDoc;
DataHandler handler4 = outBlob.getSwaRef();
//Get an InputStream from DataHandler and
//write to a file
InputStream inputStream = handler4.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();
System.out.println("The PDF document that contains Bates numbering was assembled.");
}
catch(Exception e)
{
e.printStackTrace();
}
}
}
|
|
|