Java Mailing List Archive

http://www.junlu.com/

Home » Home (12/2007) » iText »

Re: [iText-questions] Add submit button to writer.

Andrea Fantechi

2005-06-27

Replies:

Thanks.
In the mean time I partially resolved using a PdfWriter instead of
PdfStamper.
I resume my purpose: what I'm trying to do is a PDF document obtained
filling the form fields and, at the end, adding a submit button which
submits the entire document.
The resulting document must be signed by the end user.
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
PdfReader filledTemplateReader = new PdfReader(new
ByteArrayInputStream(filledTemplateOutputStream.toByteArray()));
Document outputDocument = new Document(filledTemplateReader.getPageSize(1));
setupResponse(response, nomeFile);
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
outputWriter = PdfWriter.getInstance(outputDocument, outputStream);
outputDocument.open();
PdfContentByte directContent = outputWriter.getDirectContent();
for (int i = 1; i < filledTemplateReader.getNumberOfPages(); i++) {
  outputDocument.newPage();
  PdfImportedPage page =
outputWriter.getImportedPage(filledTemplateReader, i);
  directContent.addTemplate(page, 0, 0);
  if (i == 1) {
    addSubmitButton(outputWriter);
    addJavascript(outputWriter);
  }
}
outputDocument.close();
writeToResponse(response, outputStream);
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Greetings
  Andrea


Patrick Lee wrote:

>I had a similar problem. Here's the high level code of
>how I got around it... we're serving the pdfs out
>through a bog standard servlet.
>
>ServletOutputStream out = resp.getOutputStream();
>ByteArrayOutputStream baos = new
>ByteArrayOutputStream();
>PdfReader inputPDF = new PdfReader(docBytes);      
>PdfStamper stamp = new PdfStamper(inputPDF, baos);
>PdfWriter writer = stamp.getWriter();
>writer.setViewerPreferences(PdfWriter.HideMenubar |
>PdfWriter.PageModeUseNone|PdfWriter.CenterWindow
>|PdfWriter.NonFullScreenPageModeUseNone);
>String nextIdList = calculateNextIdList(ids);    
>getButtonCreator().createEditButtons(inputPDF, writer,
>stamp, nextIdList, String.valueOf(ids[0]));
>getDocumentHelper().populatePreviouslySavedValues(ids[0],
>stamp, true);
>stamp.close();      
>resp.setContentLength(baos.size());
>resp.setContentType("application/pdf");
>out.write(baos.toByteArray());
>resp.flushBuffer();  
>out.flush();  
>out.close();            
>
>
>Hope this helps.... my
>getButtonCreator().createEditButtons does the actual
>drawing of the buttons.
>
>
>

Attachment: a.fantechi.vcf
©2008 junlu.com - Jax Systems, LLC, U.S.A.