示例#1
0
        public void CreatePdf(String filename)
        {
            // step 1: Create a Document
            Document document = new Document();
            // step 2: Create a PdfWriter
            PdfWriter writer = PdfWriter.GetInstance(document, new FileStream(filename, FileMode.Create));

            // step 3: Open the Document
            document.Open();
            // step 4: Add content
            document.Add(new Paragraph("Hello World!"));
            // create a signature form field
            PdfFormField field = PdfFormField.CreateSignature(writer);

            field.FieldName = SIGNAME;
            // set the widget properties
            field.SetPage();
            field.SetWidget(new Rectangle(72, 732, 144, 780), PdfAnnotation.HIGHLIGHT_INVERT);
            field.Flags = PdfAnnotation.FLAGS_PRINT;
            // add it as an annotation
            writer.AddAnnotation(field);
            // maybe you want to define an appearance
            PdfAppearance tp = PdfAppearance.CreateAppearance(writer, 72, 48);

            tp.SetColorStroke(BaseColor.BLUE);
            tp.SetColorFill(BaseColor.LIGHT_GRAY);
            tp.Rectangle(0.5f, 0.5f, 71.5f, 47.5f);
            tp.FillStroke();
            tp.SetColorFill(BaseColor.BLUE);
            ColumnText.ShowTextAligned(tp, Element.ALIGN_CENTER, new Phrase("SIGN HERE"), 36, 24, 25);
            field.SetAppearance(PdfAnnotation.APPEARANCE_NORMAL, tp);
            // step 5: Close the Document
            document.Close();
        }
            public override void Draw(DrawContext context)
            {
                int          pageNumber = GetOccupiedArea().GetPageNumber();
                Rectangle    bbox       = GetInnerAreaBBox();
                PdfDocument  pdf        = context.GetDocument();
                PdfAcroForm  form       = PdfAcroForm.GetAcroForm(pdf, true);
                PdfFormField chk        = PdfFormField.CreateRadioButton(pdf, bbox, _group, _value, PdfAConformanceLevel.PDF_A_1B
                                                                         );

                chk.SetPage(pageNumber);
                chk.SetValue("Off");
                chk.RegenerateField();
                chk.SetVisibility(PdfFormField.VISIBLE);
                chk.SetBorderColor(ColorConstants.BLACK);
                chk.SetBackgroundColor(ColorConstants.WHITE);
                chk.SetReadOnly(true);
                PdfFormXObject appearance = new PdfFormXObject(bbox);
                PdfCanvas      canvas     = new PdfCanvas(appearance, pdf);

                canvas.SaveState().MoveTo(bbox.GetLeft(), bbox.GetBottom()).LineTo(bbox.GetRight(), bbox.GetBottom()).LineTo
                    (bbox.GetRight(), bbox.GetTop()).LineTo(bbox.GetLeft(), bbox.GetTop()).LineTo(bbox.GetLeft(), bbox.GetBottom
                                                                                                      ()).SetLineWidth(1f).Stroke().RestoreState();
                form.AddFieldAppearanceToPage(chk, pdf.GetPage(pageNumber));
                chk.SetAppearance(PdfName.N, "v1".Equals(_value) ? _value : "Off", appearance.GetPdfObject());
            }
示例#3
0
        // ---------------------------------------------------------------------------

        /**
         * Create a pushbutton for a key
         * @param writer the PdfWriter
         * @param rect the position of the key
         * @param btn the label for the key
         * @param script the script to be executed when the button is pushed
         */
        public void AddPushButton(PdfWriter writer, Rectangle rect,
                                  String btn, String script)
        {
            float        w          = rect.Width;
            float        h          = rect.Height;
            PdfFormField pushbutton = PdfFormField.CreatePushButton(writer);

            pushbutton.FieldName = "btn_" + btn;
            pushbutton.SetWidget(rect, PdfAnnotation.HIGHLIGHT_PUSH);
            PdfContentByte cb = writer.DirectContent;

            pushbutton.SetAppearance(
                PdfAnnotation.APPEARANCE_NORMAL,
                CreateAppearance(cb, btn, BaseColor.GRAY, w, h)
                );
            pushbutton.SetAppearance(
                PdfAnnotation.APPEARANCE_ROLLOVER,
                CreateAppearance(cb, btn, BaseColor.RED, w, h)
                );
            pushbutton.SetAppearance(
                PdfAnnotation.APPEARANCE_DOWN,
                CreateAppearance(cb, btn, BaseColor.BLUE, w, h)
                );
            pushbutton.SetAdditionalActions(
                PdfName.U,
                PdfAction.JavaScript(script, writer)
                );
            pushbutton.SetAdditionalActions(
                PdfName.E, PdfAction.JavaScript(
                    "this.showMove('" + btn + "');", writer
                    )
                );
            pushbutton.SetAdditionalActions(
                PdfName.X, PdfAction.JavaScript(
                    "this.showMove(' ');", writer
                    )
                );
            writer.AddAnnotation(pushbutton);
        }