  | Mailing List | | Home | | Forum Home | | JBoss - Java Application Server | | Tomcat - JSP/Servlet container | | Struts - A MVC web framework | | iText - An open source PDF Java Library | | JDOM - JDOM XML Parser | | J2EE - A mailing list for Java(tm) 2 Platform, Enterprise Edition | | J2EE Pattern - An interest list for Sun Java Center J2EE Pattern Catalog | | JSP - A mailing list about Java Server Pages specification and reference | | Servlet - A mailing list for discussion about Sun Microsystem's Java Servlet API Technology | |
Struts & Hibernate
|
|
|
  | | | PDF Form fields with relative position. | PDF Form fields with relative position. 2006-08-03 - By Juan Carrasco
Back Hi to all.
I'm trying to create form field in a PDF using iText. But I don't know the absolute position of this fields on the final document nor in the final page. I find a way to add Text Fields to a document relatively to the text added to it, but now I need to do the same with CheckBox, Radio Button, List and Combos.
To add Text Fields relatively to a text, I create a Chunk and asociate text field to the Chunk's annotation, following this : Chunk.setAnnotation (annotation). This works, but when I tried the same way with check boxes, the controls do not appear on the PDF.
Here is the source code than I try:
nuevo_elemento = new Chunk (""); // Chunk to set the relative position of the Check Box.
PdfFormField check1 = PdfFormField.createCheckBox(escritor);
Rectangle rect = new Rectangle(0, 0, 20, 20); // Position to set the widget
check1.setFieldName("tarjetaCredito");
check1.setValueAsName("Off");
check1.setWidget(rect, PdfAnnotation.HIGHLIGHT_INVERT);
check1.setAppearanceState("Off");
check1.setAppearance(PdfAnnotation.APPEARANCE_NORMAL, "Off", tpOff2);
check1.setAppearance(PdfAnnotation.APPEARANCE_NORMAL, "On", tpOn2);
nuevo_elemento.setAnnotation(check1); // Associate Check Box (check1) with his content Chunk (nuevo_elemento)
doc.add (nuevo_elemento);
<html xmlns:v="urn:schemas-microsoft-com:vml" xmlns:o="urn:schemas-microsoft -com:office:office" xmlns:w="urn:schemas-microsoft-com:office:word" xmlns="http: //www.w3.org/TR/REC-html40">
<head> <meta http-equiv=Content-Type content="text/html; charset=us-ascii"> <meta name=Generator content="Microsoft Word 11 (filtered medium)"> <style> <!-- /* Style Definitions */ p.MsoNormal, li.MsoNormal, div.MsoNormal {margin:0cm; margin-bottom:.0001pt; font-size:12.0pt; font-family:"Times New Roman";} a:link, span.MsoHyperlink {color:blue; text-decoration:underline;} a:visited, span.MsoHyperlinkFollowed {color:purple; text-decoration:underline;} p.parrafodescripcion, li.parrafodescripcion, div.parrafodescripcion {margin-top:0cm; margin-right:0cm; margin-bottom:6.0pt; margin-left:0cm; text-align:justify; text-indent:11.35pt; font-size:12.0pt; font-family:"Times New Roman";} span.EstiloCorreo18 {mso-style-type:personal-compose; font-family:Arial; color:windowtext;} @(protected) Section1 {size:595.3pt 841.9pt; margin:70.85pt 3.0cm 70.85pt 3.0cm;} div.Section1 {page:Section1;} --> </style> <!--[if gte mso 9]><xml> <o:shapedefaults v:ext="edit" spidmax="1026" /> </xml><![endif]--><!--[if gte mso 9]><xml> <o:shapelayout v:ext="edit"> <o:idmap v:ext="edit" data="1" /> </o:shapelayout></xml><![endif]--> </head>
<body lang=ES link=blue vlink=purple>
<div class=Section1>
<p class=MsoNormal><font size=2 face=Arial><span style='font-size:10.0pt; font-family:Arial'> Hi to all. <o:p></o:p></span></font></p>
<p class=MsoNormal><font size=2 face=Arial><span style='font-size:10.0pt; font-family:Arial'> I’m trying to create form field in a PDF using iText. But I don’t know the absolute position of this fields on the final document nor in the final page. I find a way to add Text Fields to a document relatively to the text added to it, but now I need to do the same with CheckBox, Radio Button, List and Combos.<o:p></o:p></span></font></p>
<p class=MsoNormal><font size=2 face=Arial><span style='font-size:10.0pt; font-family:Arial'><o:p> </o:p></span></font></p>
<p class=MsoNormal><font size=2 face=Arial><span style='font-size:10.0pt; font-family:Arial'> To add Text Fields relatively to a text, I create a Chunk and asociate text field to the Chunk’s annotation, following this : Chunk.setAnnotation (annotation). This works, but when I tried the same way with check boxes, the controls do not appear on the PDF.<o:p></o:p></span>< /font></p>
<p class=MsoNormal><font size=2 face=Arial><span style='font-size:10.0pt; font-family:Arial'><o:p> </o:p></span></font></p>
<p class=MsoNormal><font size=2 face=Arial><span style='font-size:10.0pt; font-family:Arial'> Here is the source code than I try:<o:p></o:p></span> </font></p>
<p class=MsoNormal><font size=2 face=Arial><span style='font-size:10.0pt; font-family:Arial'><o:p> </o:p></span></font></p>
<p class=MsoNormal style='margin-left:35.4pt'><font size=2 face=Arial><span style='font-size:10.0pt;font-family:Arial'>nuevo_elemento = new Chunk (“& #8221;); / / Chunk to set the relative position of the Check Box.<o:p></o:p></span></font>< /p>
<p class=MsoNormal><font size=2 face=Arial><span style='font-size:10.0pt; font-family:Arial'><o:p> </o:p></span></font></p>
<p class=MsoNormal><font size=2 face=Arial><span style='font-size:10.0pt; font-family:Arial'> PdfFormField check1 = PdfFormField.createCheckBox(escritor);<o:p></o:p></span></font></p>
<p class=MsoNormal><font size=2 face=Arial><span style='font-size:10.0pt; font-family:Arial'> Rectangle rect = new Rectangle(0, 0, 20, 20); // Position to set the widget<o:p></o:p></span></font></p>
<p class=MsoNormal><font size=2 face=Arial><span style='font-size:10.0pt; font-family:Arial'> check1.setFieldName("tarjetaCredito");<o:p></o:p></span></font> </p>
<p class=MsoNormal><font size=2 face=Arial><span style='font-size:10.0pt; font-family:Arial'> check1.setValueAsName("Off");<o:p></o:p></span></font></p>
<p class=MsoNormal><font size=2 face=Arial><span style='font-size:10.0pt; font-family:Arial'> check1.setWidget(rect, PdfAnnotation.HIGHLIGHT_INVERT);<o:p></o:p></span></font></p>
<p class=MsoNormal><font size=2 face=Arial><span style='font-size:10.0pt; font-family:Arial'> check1.setAppearanceState("Off");<o:p></o:p></span></font></p>
<p class=MsoNormal><font size=2 face=Arial><span style='font-size:10.0pt; font-family:Arial'> check1.setAppearance(PdfAnnotation.APPEARANCE_NORMAL, "Off", tpOff2);<o:p></o:p></span></font></p>
<p class=MsoNormal><font size=2 face=Arial><span style='font-size:10.0pt; font-family:Arial'> check1.setAppearance(PdfAnnotation.APPEARANCE_NORMAL, "On", tpOn2);<o:p></o:p></span></font></p>
<p class=MsoNormal><font size=2 face=Arial><span style='font-size:10.0pt; font-family:Arial'> nuevo_elemento.setAnnotation(check1); // Associate Check Box (check1) with his content Chunk (nuevo_elemento)<o:p></o:p> </span></font></p>
<p class=MsoNormal><font size=2 face=Arial><span style='font-size:10.0pt; font-family:Arial'> doc.add (nuevo_elemento);<o:p></o:p></span></font></p>
</div>
</body>
</html>
-- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ----- Take Surveys. Earn Cash. Influence the Future of IT Join SourceForge.net's Techsay panel and you'll get the chance to share your opinions on IT & business topics through brief surveys -- and earn cash http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV __ ____ ____ ____ ____ ____ ____ ____ ____ ____ iText-questions mailing list iText-questions@(protected) https://lists.sourceforge.net/lists/listinfo/itext-questions
|
|
 |