Itext fill content with Rest using ByteArrayOutputStream and p:media

Posted: March 20, 2013 in web

Rest Service

public class DocumentRestService {

 public Response getContractDocument(@PathParam("carId") String carId) throws IOException, DocumentException {

//PDF Template
 PdfReader reader = new PdfReader("c:/work/test2.pdf");

ByteArrayOutputStream out = new ByteArrayOutputStream();

PdfStamper pdfStamper = new PdfStamper(reader, out);
 AcroFields acroFields = pdfStamper.getAcroFields();

//Settinge dummy field values on template pdf
 for (String field : acroFields.getFields().keySet()) {
 acroFields.setField(field, field);
 ResponseBuilder response = Response.ok(out.toByteArray());


<p:media value="http://localhost/car/rest/generate/12" player="pdf" width="100%" height="300px">
 Your browser can't display pdf.

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s