Where is the error taking place? In Acrobat/Reader during submission? On the server? Other?
-----Original Message----- From: [email protected] [mailto:[email protected]] Sent: Wednesday, June 02, 2010 9:19 AM To: [email protected] Subject: [iText-questions] max number of comboboxes in a pdfform is 85? hi all, i ran into a problem regarding the max number of comboboxes a pdfform permits for an error-free submit via SUBMIT_HTML_FORMAT. following code consists of tree files: PdfForms.java - the test application i build after i ran into problems with the real application FieldCell.java - some of you know this code, insert a formfield in a table cell :) for a complete test scenario: get_post_vars.php - see the transmitted variables. will spool readable output to /tmp/vars.txt and a success .pdf to the sending acroreader. you'll need an additional "erfolg.pdf" in the same directory on your testing webserver. in PdfForms.java method addContent adds 85 textfields and comboboxes, if you increase this to 86 the .pdf will still be generated well but pressing the "push me" button on the end will give a "text/html" error and the php-script on the webserver will not catch any submitted variables whereas with 85 text/combo fields everything works fine. iv'e added two single method calls of addTextField and addComboBox after the 85 loop to see which field might cause the error.. combobox is it a "natural" restriction of adobe's pdf, a bug in itext or am i doing something really stupid? if nothing helps i've got to try the same amount+ checkbox-goups :/ PdfForms.java ################################################## package pdfforms_test; import com.itextpdf.text.BaseColor; import com.itextpdf.text.Document; import com.itextpdf.text.DocumentException; import com.itextpdf.text.Paragraph; import com.itextpdf.text.Rectangle; import com.itextpdf.text.pdf.PdfAction; import com.itextpdf.text.pdf.PdfAnnotation; import com.itextpdf.text.pdf.PdfFormField; import com.itextpdf.text.pdf.PdfName; import com.itextpdf.text.pdf.PdfPCell; import com.itextpdf.text.pdf.PdfPTable; import com.itextpdf.text.pdf.PdfWriter; import com.itextpdf.text.pdf.PushbuttonField; import java.io.FileNotFoundException; import java.io.FileOutputStream; import java.io.IOException; import java.util.logging.Level; import java.util.logging.Logger; public class PdfForms { private Document document; private PdfWriter writer; private static String pdfFile = System.getProperty("user.home") + "/pdfforms_test.pdf"; private static String cmd = "/opt/bin/acroread " + pdfFile; private static String httpAdress = "http://localhost/get_post_vars.php"; private PdfPTable table = new PdfPTable(1); private void addComboBox(String _fieldname) { String[] options = {"eins", "zwei", "drei", "vier"}; PdfFormField comboBox = PdfFormField.createCombo(writer, false, options, 0); comboBox.setWidget(new Rectangle(40, 780, 120, 800), PdfAnnotation.HIGHLIGHT_INVERT); comboBox.setFieldName(_fieldname); comboBox.setValueAsString("nix"); PdfPCell cell = new PdfPCell(); cell.setMinimumHeight(20); cell.setCellEvent(new FieldCell(comboBox, 20, writer)); table.addCell(cell); } private void addTextField(String _fieldname) { PdfFormField textField = PdfFormField.createTextField(writer, true, false, 500); textField.setWidget(new Rectangle(150, 600, 300, 700), PdfName._3D); textField.setFieldName(_fieldname); PdfPCell cell = new PdfPCell(); cell.setMinimumHeight(40); cell.setCellEvent(new FieldCell(textField, 40, writer)); table.addCell(cell); } private void addSendButton() { PushbuttonField pushButton = new PushbuttonField(writer, new Rectangle(150, 560, 200, 590), "pushButton"); pushButton.setBackgroundColor(BaseColor.LIGHT_GRAY); pushButton.setLayout(PushbuttonField.LAYOUT_ICON_TOP_LABEL_BOTTOM); pushButton.setOptions(PushbuttonField.VISIBLE_BUT_DOES_NOT_PRINT); pushButton.setText("push me"); try { PdfFormField submit = pushButton.getField(); submit.setAction(PdfAction.createSubmitForm(httpAdress, null, PdfAction.SUBMIT_HTML_FORMAT)); PdfPCell cell = new PdfPCell(); cell.setMinimumHeight(40); cell.setCellEvent(new FieldCell(submit, 40, writer)); table.addCell(cell); } catch (IOException ex) { Logger.getLogger(PdfForms.class.getName()).log(Level.SEVERE, null, ex); } catch (DocumentException ex) { Logger.getLogger(PdfForms.class.getName()).log(Level.SEVERE, null, ex); } } private void addContent() { for (int i = 0; i < 85; i++) { PdfPCell cell = new PdfPCell(new Paragraph("test")); table.addCell(cell); addTextField("text"+Integer.toString(i)); addComboBox("combo"+Integer.toString(i)); } // addTextField("a"); // addComboBox("b"); addSendButton(); try { document.add(table); } catch (DocumentException ex) { Logger.getLogger(PdfForms.class.getName()).log(Level.SEVERE, null, ex); } } private void showDocument() { try { Process p = Runtime.getRuntime().exec(cmd); p.waitFor(); } catch (InterruptedException ex) { Logger.getLogger(PdfForms.class.getName()).log(Level.SEVERE, null, ex); } catch (IOException ex) { Logger.getLogger(PdfForms.class.getName()).log(Level.SEVERE, null, ex); } } private void close() { this.document.close(); } public PdfForms() { try { this.document = new Document(); this.writer = PdfWriter.getInstance(document, new FileOutputStream(pdfFile)); this.document.open(); } catch (FileNotFoundException ex) { Logger.getLogger(PdfForms.class.getName()).log(Level.SEVERE, null, ex); } catch (DocumentException ex) { Logger.getLogger(PdfForms.class.getName()).log(Level.SEVERE, null, ex); } } public static void main(String[] args) { PdfForms p = new PdfForms(); p.addContent(); p.close(); p.showDocument(); System.exit(0); } } FieldCell.java ################################################# package pdfforms_test; import com.itextpdf.text.Rectangle; import com.itextpdf.text.pdf.PdfAnnotation; import com.itextpdf.text.pdf.PdfContentByte; import com.itextpdf.text.pdf.PdfFormField; import com.itextpdf.text.pdf.PdfPCell; import com.itextpdf.text.pdf.PdfPCellEvent; import com.itextpdf.text.pdf.PdfPTable; import com.itextpdf.text.pdf.PdfWriter; class FieldCell implements PdfPCellEvent { private PdfFormField formField; private PdfWriter writer; private int height; public FieldCell(PdfFormField _formField, int _height, PdfWriter _writer) { this.formField = _formField; this.height = _height; this.writer = _writer; } public void cellLayout(PdfPCell cell, Rectangle rect, PdfContentByte[] canvas) { try { PdfContentByte cb = canvas[PdfPTable.LINECANVAS]; //cb.reset(); formField.setWidget(new Rectangle(rect.getLeft(), rect.getTop()-height, rect.getRight(), rect.getTop()), PdfAnnotation.HIGHLIGHT_NONE); writer.addAnnotation(formField); } catch (Exception e) { System.out.println(e); } } } get_post_vars.php ############################################## <?php ob_start(); var_dump($_REQUEST); $vars = ob_get_contents(); ob_end_clean(); $f = fopen("/tmp/vars.txt","w"); fwrite($f,$vars); fclose($f); function ReadfileChunks($filename) { $chunksize = 1*(1024*1024); $chunksize = 512; $buffer = ''; $count = 0; $handle = fopen($filename, 'rb'); if ($handle === false) { return false; } while (!feof($handle)) { $buffer = fread($handle, $chunksize); echo $buffer; ob_flush(); flush(); } $status = fclose($handle); } $filename="erfolg.pdf"; header("Pragma: public"); header("Expires: 0"); header("Cache-Control: must-revalidate, post-check=0, pre-check=0"); header("Cache-Control: private", false); header("Content-Type: application/pdf"); header("Content-Disposition: attachment; filename=\"danke.pdf\""); header("Content-Transfer-Encoding: binary"); header("Content-Length: "....@filesize($filename)); ReadfileChunks($filename); ?> EOF ########################################################## ------------------------------------------------------------------------------ _______________________________________________ iText-questions mailing list [email protected] https://lists.sourceforge.net/lists/listinfo/itext-questions Buy the iText book: http://www.itextpdf.com/book/ Check the site with examples before you ask questions: http://www.1t3xt.info/examples/ You can also search the keywords list: http://1t3xt.info/tutorials/keywords/ ------------------------------------------------------------------------------ _______________________________________________ iText-questions mailing list [email protected] https://lists.sourceforge.net/lists/listinfo/itext-questions Buy the iText book: http://www.itextpdf.com/book/ Check the site with examples before you ask questions: http://www.1t3xt.info/examples/ You can also search the keywords list: http://1t3xt.info/tutorials/keywords/
