The Author Online Book Forums are Moving

The Author Online Book Forums will soon redirect to Manning's liveBook and liveVideo. All book forum content will migrate to liveBook's discussion forum and all video forum content will migrate to liveVideo. Log in to liveBook or liveVideo with your Manning credentials to join the discussion!

Thank you for your engagement in the AoF over the years! We look forward to offering you a more enhanced forum experience.

Sarah1 (12) [Avatar] Offline
#1
Hi,

The following is from your example RegisterForm1.java:
**************************************************************
PdfPTable table = new PdfPTable(2);
PdfPCell cell;
TextField field;

table.addCell("Your name:");
cell = new PdfPCell();

PDFTextField pdfTextField = new PDFTextField(writer);
pdfTextField.setFontSize(12);
pdfTextField.setFieldName("name");
field = pdfTextField.getTextField();

cell.setCellEvent(new RegisterForm1(parent, field.getTextField(), 1));
table.addCell(cell);
**********************************************************************

Can I directly add the PDFTextField to PdfPCell? Why I have to do cell.setCellEvent(PdfPCellEvent)?

I just want to create a simple form, do I have to wirte a class which must implement PdfPCellEvent?

Thanks.

Sarah
blowagie (284) [Avatar] Offline
#2
Re: add text field to PdfPCell problem
> Why I have to do cell.setCellEvent(PdfPCellEvent)?

Because that's the way it works.
You can create most of the other building blocks (Phrase, Paragraph, List,...) without specifying coordinates, but to construct annotations and fields, you need to pass a Rectangle defining the position of the element. That's done in a cell event.