6 Replies Latest reply: May 4, 2009 4:10 PM by 807575 RSS

    I did it again! Itext (PDF Files), JSchart VWP with NetBeans 5.5 !

    807575
      Hello people, recently i took the challenge to work with NetBeans 5.5 and integrate Itext library to generate PDF files on the fly using servlets, JSchart components to generate reports, and java applets if anyone have some trouble with this, maybe i can help you, just post your question!.

      Belthazor.
        • 1. Re: I did it again! Itext (PDF Files), JSchart VWP with NetBeans 5.5 !
          807575
          Its great to know you were able to accomplish this. Please do share your learnings with the community for everyones benefit.

          Thanks, great job!
          K
          • 2. Re: I did it again! Itext (PDF Files), JSchart VWP with NetBeans 5.5 !
            807575
            hi mate

            can you please tell me how to check/uncheck the checkbox and radio buttons in pdf using iText. Please see the code below i am trying to do :

            ============================
            PdfReader reader = new PdfReader(PDF_TEMPLATE);
            // filling in the form
            PdfStamper stamp1 = new PdfStamper(reader, new FileOutputStream(PDF_RESULT));
            AcroFields form1 = stamp1.getAcroFields();
            form1.setField("checkBoxName", "On");

            stamp1.setFormFlattening(true);
            stamp1.close();

            ==========================
            But when i open the result pdf, the checkbox is yet unchecked or vic-e-versa.
            Am i missing something ? is this right way to check/uncheck a checkbox ?

            I need this to be working asap.
            Can you help ?

            -Thanks
            • 3. Re: I did it again! Itext (PDF Files), JSchart VWP with NetBeans 5.5 !
              807575
              Hello.

              Im not sure what do you want to do, but here is a more detailed code which u can see how to check or uncheck a radio button using itext:

              try {

              PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream("radiobutton.pdf"));

              document.open();


              PdfContentByte cb = writer.getDirectContent();
              cb.moveTo(0, 0);
              PdfFormField radio = PdfFormField.createRadioButton(writer, true);
              PdfAppearance tpOff = cb.createAppearance(20, 20);
              PdfAppearance tpOn = cb.createAppearance(20, 20);

              tpOff.circle(10, 10, 9);
              tpOff.stroke();

              tpOn.circle(10, 10, 9);
              tpOn.stroke();
              tpOn.circle(10, 10, 3);
              tpOn.fillStroke();

              radio.setFieldName("CreditCard");
              radio.setValueAsName("MasterCard");

              PdfFormField radio1 = PdfFormField.createEmpty(writer);
              radio1.setWidget(new Rectangle(100, 700, 120, 720), PdfAnnotation.HIGHLIGHT_INVERT);
              radio1.setAppearanceState("MasterCard");
              radio1.setAppearance(PdfAnnotation.APPEARANCE_NORMAL, "Off", tpOff);
              radio1.setAppearance(PdfAnnotation.APPEARANCE_NORMAL, "MasterCard", tpOn);
              radio.addKid(radio1);

              PdfFormField radio2 = PdfFormField.createEmpty(writer);
              radio2.setWidget(new Rectangle(100, 660, 120, 680), PdfAnnotation.HIGHLIGHT_INVERT);
              radio2.setAppearanceState("Off");
              radio2.setAppearance(PdfAnnotation.APPEARANCE_NORMAL, "Off", tpOff);
              radio2.setAppearance(PdfAnnotation.APPEARANCE_NORMAL, "Visa", tpOn);
              radio.addKid(radio2);

              PdfFormField radio3 = PdfFormField.createEmpty(writer);
              radio3.setWidget(new Rectangle(100, 620, 120, 640), PdfAnnotation.HIGHLIGHT_INVERT);
              radio3.setAppearanceState("Off");
              radio3.setAppearance(PdfAnnotation.APPEARANCE_NORMAL, "Off", tpOff);
              radio3.setAppearance(PdfAnnotation.APPEARANCE_NORMAL, "American", tpOn);
              radio.addKid(radio3);

              writer.addAnnotation(radio);

              }
              catch(DocumentException de) {
              System.err.println(de.getMessage());
              }
              catch(IOException ioe) {
              System.err.println(ioe.getMessage());
              }

              this is just a way to do it, if this not what do you want to do, just post again!

              Belthazor
              • 4. Re: I did it again! Itext (PDF Files), JSchart VWP with NetBeans 5.5 !
                807575
                Hello I am also facing the similar problem .... can anyone help!

                can you please tell me how to check/uncheck the checkbox and radio buttons in pdf using iText. Please see the code below i am trying to do :

                ============================
                PdfReader reader = new PdfReader(PDF_TEMPLATE);
                // filling in the form
                PdfStamper stamp1 = new PdfStamper(reader, new FileOutputStream(PDF_RESULT));
                AcroFields form1 = stamp1.getAcroFields();
                form1.setField("checkBoxName", "On");

                stamp1.setFormFlattening(true);
                stamp1.close();

                ==========================
                But when i open the result pdf, the checkbox is yet unchecked or vic-e-versa.
                Am i missing something ? is this right way to check/uncheck a checkbox ?

                I need this to be working asap.
                Can you help ?

                -Thanks
                • 5. Re: I did it again! Itext (PDF Files), JSchart VWP with NetBeans 5.5 !
                  807575
                  I'm trying to use iText with JSF and JDK 1.5 in NetBeans. I've compiled iText and I've got a new iText.jar for java 1.5. When I execute the document.close() instruction I get the following error:

                  HTTP Status 500 -

                  --------------------------------------------------------------------------------

                  type Exception report

                  message

                  descriptionThe server encountered an internal error () that prevented it from fulfilling this request.

                  exception

                  javax.servlet.ServletException: #{pedidos.pedidosPDF}: ExceptionConverter: java.io.IOException: The document has no pages.
                  root cause

                  javax.faces.FacesException: #{pedidos.pedidosPDF}: ExceptionConverter: java.io.IOException: The document has no pages.
                  root cause

                  javax.faces.el.EvaluationException: ExceptionConverter: java.io.IOException: The document has no pages.
                  root cause

                  ExceptionConverter: java.io.IOException: The document has no pages.

                  Any idea about where to investigate. Is my iText.jar incorrect? Is it impossible to use iText with JSF?
                  • 6. Re: I did it again! Itext (PDF Files), JSchart VWP with NetBeans 5.5 !
                    807575
                    hi everyone,

                    I am new to netbeans and iText. I have to do a project using them, so any one can help me about how to use iText in NetBeans, means how can I configure NetBeans for iText. I have downloaded iText.jar file from iText website.

                    Thanks in advance