Exemple #1
0
        public void CreatePDF(Stream stream)
        {
            var doc  = new GcPdfDocument();
            var page = doc.NewPage();

            var rc = Common.Util.AddNote(
                "In this sample the Submit button is associated with the ActionSubmitForm action, " +
                "with the URL pointing to a POST handler running on our sample server. " +
                "When the form is submitted, that handler receives a collection of form field names " +
                "and field values from the filled form, and sends it back in a simple HTML page. " +
                "If you download this sample, to successfully run it you will need to set up your own " +
                "handler, and change the Submit button action's URL to point to that handler.",
                page);

            var        g  = page.Graphics;
            TextFormat tf = new TextFormat()
            {
                Font = StandardFonts.Times, FontSize = 14
            };
            PointF ip        = new PointF(72, rc.Bottom + 36);
            float  fldOffset = 72 * 2 + 46;
            float  fldHeight = tf.FontSize * 1.2f;
            float  dY        = 32;

            // Text field:
            g.DrawString("First name:", tf, ip);
            var fldFirstName = new TextField()
            {
                Name = "FirstName", Value = "John"
            };

            fldFirstName.Widget.Page                = page;
            fldFirstName.Widget.Rect                = new RectangleF(ip.X + fldOffset, ip.Y, 72 * 3, fldHeight);
            fldFirstName.Widget.TextFormat.Font     = tf.Font;
            fldFirstName.Widget.TextFormat.FontSize = tf.FontSize;
            doc.AcroForm.Fields.Add(fldFirstName);
            ip.Y += dY;

            // Text field:
            g.DrawString("Last name:", tf, ip);
            var fldLastName = new TextField()
            {
                Name = "LastName", Value = "Smith"
            };

            fldLastName.Widget.Page                = page;
            fldLastName.Widget.Rect                = new RectangleF(ip.X + fldOffset, ip.Y, 72 * 3, fldHeight);
            fldLastName.Widget.TextFormat.Font     = tf.Font;
            fldLastName.Widget.TextFormat.FontSize = tf.FontSize;
            doc.AcroForm.Fields.Add(fldLastName);
            ip.Y += dY;

            // Checkbox:
            g.DrawString("Subscribe to Mailing List:", tf, ip);
            var fldCheckbox = new CheckBoxField()
            {
                Name = "Subscribe", Value = true
            };

            fldCheckbox.Widget.Page = page;
            fldCheckbox.Widget.Rect = new RectangleF(ip.X + fldOffset, ip.Y, fldHeight, fldHeight);
            doc.AcroForm.Fields.Add(fldCheckbox);
            ip.Y += dY;

            // Multiline TextBox:
            g.DrawString("Additional information:", tf, ip);
            var fldAdditionalInfo = new TextField()
            {
                Name = "AdditionalInfo", Multiline = true
            };

            fldAdditionalInfo.Widget.Page                = page;
            fldAdditionalInfo.Widget.Rect                = new RectangleF(ip.X + fldOffset, ip.Y, 72 * 3, fldHeight * 2);
            fldAdditionalInfo.Widget.TextFormat.Font     = tf.Font;
            fldAdditionalInfo.Widget.TextFormat.FontSize = tf.FontSize;
            doc.AcroForm.Fields.Add(fldAdditionalInfo);
            ip.Y += dY * 2;

            // Submit form button:
            var btnSubmit = new PushButtonField();

            btnSubmit.Widget.Rect = new RectangleF(ip.X + fldOffset, ip.Y, 72, fldHeight);
            btnSubmit.Widget.ButtonAppearance.Caption = "Submit";
            btnSubmit.Widget.Highlighting             = HighlightingMode.Invert;
            btnSubmit.Widget.Page = page;

            // The URL for the submission:
            btnSubmit.Widget.Events.Activate = new ActionSubmitForm("/Samples/HandleFormSubmitFields");
            doc.AcroForm.Fields.Add(btnSubmit);

            // Reset form button:
            var btnReset = new PushButtonField();

            btnReset.Widget.Rect = new RectangleF(ip.X + fldOffset + 72 * 1.5f, ip.Y, 72, fldHeight);
            btnReset.Widget.ButtonAppearance.Caption = "Reset";
            btnReset.Widget.Highlighting             = HighlightingMode.Invert;
            btnReset.Widget.Page            = page;
            btnReset.Widget.Events.Activate = new ActionResetForm();
            doc.AcroForm.Fields.Add(btnReset);
            ip.Y += dY;

            // Done:
            doc.Save(stream);
        }
Exemple #2
0
        public void CreatePDF(Stream stream)
        {
            var        doc  = new GcPdfDocument();
            var        page = doc.NewPage();
            var        g    = page.Graphics;
            TextFormat tf   = new TextFormat();

            tf.Font     = StandardFonts.Times;
            tf.FontSize = 14;
            PointF ip        = new PointF(72, 72);
            float  fldOffset = 72 * 2;
            float  fldHeight = tf.FontSize * 1.2f;
            float  dY        = 32;

            // Text field:
            g.DrawString("Text field:", tf, ip);
            var fldText = new TextField();

            fldText.Value                      = "Initial TextField value";
            fldText.Widget.Page                = page;
            fldText.Widget.Rect                = new RectangleF(ip.X + fldOffset, ip.Y, 72 * 3, fldHeight);
            fldText.Widget.TextFormat.Font     = tf.Font;
            fldText.Widget.TextFormat.FontSize = tf.FontSize;
            doc.AcroForm.Fields.Add(fldText);
            ip.Y += dY;

            // Checkbox:
            g.DrawString("Checkbox:", tf, ip);
            var fldCheckbox = new CheckBoxField();

            fldCheckbox.Value       = true;
            fldCheckbox.Widget.Page = page;
            fldCheckbox.Widget.Rect = new RectangleF(ip.X + fldOffset, ip.Y, fldHeight, fldHeight);
            doc.AcroForm.Fields.Add(fldCheckbox);
            ip.Y += dY;

            // Radio button:
            g.DrawString("Radio button:", tf, ip);
            var fldRadio = new RadioButtonField();

            fldRadio.Value = 1;
            fldRadio.Widgets.Add(new WidgetAnnotation(page, new RectangleF(ip.X + fldOffset, ip.Y, fldHeight, fldHeight)));
            fldRadio.Widgets.Add(new WidgetAnnotation(page, new RectangleF(ip.X + fldOffset, ip.Y + fldHeight * 1.2f, fldHeight, fldHeight)));
            fldRadio.Widgets.Add(new WidgetAnnotation(page, new RectangleF(ip.X + fldOffset, ip.Y + (fldHeight * 1.2f) * 2, fldHeight, fldHeight)));
            doc.AcroForm.Fields.Add(fldRadio);
            ip.Y = fldRadio.Widgets[fldRadio.Widgets.Count - 1].Rect.Y + dY;

            // CombTextField:
            g.DrawString("CombText field:", tf, ip);
            var fldCombText = new CombTextField();

            fldCombText.Value = "123";
            fldCombText.Widget.TextFormat.FontSize = 12;
            fldCombText.Widget.Rect = new RectangleF(ip.X + fldOffset, ip.Y, 72 * 3, fldHeight);
            fldCombText.Widget.Page = page;
            doc.AcroForm.Fields.Add(fldCombText);
            ip.Y += dY;

            // Combo-box:
            g.DrawString("Combo box:", tf, ip);
            var fldComboBox = new ComboBoxField();

            fldComboBox.Items.Add(new ChoiceFieldItem("ComboBox Choice 1"));
            fldComboBox.Items.Add(new ChoiceFieldItem("ComboBox Choice 2"));
            fldComboBox.Items.Add(new ChoiceFieldItem("ComboBox Choice 3"));
            fldComboBox.SelectedIndex = 1;
            fldComboBox.Widget.Rect   = new RectangleF(ip.X + fldOffset, ip.Y, 72 * 3, fldHeight);
            fldComboBox.Widget.Page   = page;
            doc.AcroForm.Fields.Add(fldComboBox);
            ip.Y += dY;

            // List box:
            g.DrawString("List box:", tf, ip);
            ListBoxField fldListBox = new ListBoxField();

            fldListBox.Items.Add(new ChoiceFieldItem("ListBox Choice 1"));
            fldListBox.Items.Add(new ChoiceFieldItem("ListBox Choice 2"));
            fldListBox.Items.Add(new ChoiceFieldItem("ListBox Choice 3"));
            fldListBox.SelectedIndexes   = new int[] { 0, 2 };
            fldListBox.MultiSelect       = true;
            fldListBox.CommitOnSelChange = true;
            fldListBox.Widget.Rect       = new RectangleF(ip.X + fldOffset, ip.Y, 100, 50);
            fldListBox.Widget.Page       = page;
            doc.AcroForm.Fields.Add(fldListBox);
            ip.Y = fldListBox.Widget.Rect.Bottom - fldHeight + dY;

            // Signature field:
            g.DrawString("Signature field:", tf, ip);
            var fldSignature = new SignatureField();

            fldSignature.AlternateName = "All fields locked when the document is signed";
            fldSignature.LockedFields  = new SignatureLockedFields();
            fldSignature.Widget.Rect   = new RectangleF(ip.X + fldOffset, ip.Y, 72 * 2, 72 - dY);
            fldSignature.Widget.TextFormat.FontSize      = 8;
            fldSignature.Widget.ButtonAppearance.Caption = "Click to sign";
            fldSignature.Widget.Border = new Border()
            {
                Width = 0.5f, Color = Color.DarkSeaGreen
            };
            fldSignature.Widget.Page = page;
            doc.AcroForm.Fields.Add(fldSignature);
            ip.Y += 72 - fldHeight;

            // Buttons:
            g.DrawString("Push buttons:", tf, ip);

            // Submit form button:
            var btnSubmit = new PushButtonField();

            btnSubmit.Widget.Rect = new RectangleF(ip.X + fldOffset, ip.Y, 72, fldHeight);
            btnSubmit.Widget.ButtonAppearance.Caption = "Submit";
            btnSubmit.Widget.Highlighting             = HighlightingMode.Invert;
            btnSubmit.Widget.Events.Activate          = new ActionSubmitForm("Sample Form Submit URI");
            btnSubmit.Widget.Page = page;
            doc.AcroForm.Fields.Add(btnSubmit);
            // ip.Y += dY;

            // Reset form button:
            var btnReset = new PushButtonField();

            btnReset.Widget.Rect = new RectangleF(ip.X + fldOffset + 72 * 1.5f, ip.Y, 72, fldHeight);
            btnReset.Widget.ButtonAppearance.Caption = "Reset";
            btnReset.Widget.Highlighting             = HighlightingMode.Invert;
            btnReset.Widget.Events.Activate          = new ActionResetForm();
            btnReset.Widget.Page = page;
            doc.AcroForm.Fields.Add(btnReset);
            ip.Y += dY;

            // Done:
            doc.Save(stream);
        }
Exemple #3
0
        private static void DrawPageWithWidgets(RadFixedDocument document)
        {
            RadFixedPage page = document.Pages.AddPage();

            FixedContentEditor editor = new FixedContentEditor(page);

            using (editor.SaveGraphicProperties())
            {
                editor.GraphicProperties.IsFilled        = true;
                editor.GraphicProperties.IsStroked       = false;
                editor.GraphicProperties.StrokeThickness = 0;
                editor.GraphicProperties.FillColor       = new RgbColor(209, 178, 234);
                editor.DrawRectangle(new Rect(50, 50, editor.Root.Size.Width - 100, editor.Root.Size.Height - 100));
            }

            editor.Position.Translate(100, 100);
            Size widgetDimensions = new Size(200, 30);

            foreach (FormField field in document.AcroForm.FormFields)
            {
                switch (field.FieldType)
                {
                case FormFieldType.CheckBox:
                    CheckBoxField check = (CheckBoxField)field;
                    DrawNextWidgetWithDescription(editor, "CheckBox", (e) => e.DrawWidget(check, widgetDimensions));
                    break;

                case FormFieldType.ComboBox:
                    ComboBoxField combo = (ComboBoxField)field;
                    DrawNextWidgetWithDescription(editor, "ComboBox", (e) => e.DrawWidget(combo, widgetDimensions));
                    break;

                case FormFieldType.CombTextBox:
                    CombTextBoxField comb = (CombTextBoxField)field;
                    DrawNextWidgetWithDescription(editor, "Comb TextBox", (e) => e.DrawWidget(comb, widgetDimensions));
                    break;

                case FormFieldType.ListBox:
                    ListBoxField list = (ListBoxField)field;
                    DrawNextWidgetWithDescription(editor, "ListBox", (e) => e.DrawWidget(list, new Size(widgetDimensions.Width, widgetDimensions.Width)));
                    break;

                case FormFieldType.PushButton:
                    PushButtonField push = (PushButtonField)field;
                    DrawNextWidgetWithDescription(editor, "Button", (e) => e.DrawWidget(push, widgetDimensions));
                    break;

                case FormFieldType.RadioButton:
                    RadioButtonField radio = (RadioButtonField)field;
                    foreach (RadioOption option in radio.Options)
                    {
                        DrawNextWidgetWithDescription(editor, option.Value, (e) => e.DrawWidget(radio, option, widgetDimensions));
                    }
                    break;

                case FormFieldType.Signature:
                    SignatureField signature = (SignatureField)field;
                    DrawNextWidgetWithDescription(editor, "Signature", (e) => e.DrawWidget(signature, widgetDimensions));
                    break;

                case FormFieldType.TextBox:
                    TextBoxField textBox = (TextBoxField)field;
                    DrawNextWidgetWithDescription(editor, "TextBox", (e) => e.DrawWidget(textBox, widgetDimensions));
                    break;
                }
            }
        }
Exemple #4
0
        public void CreatePDF(Stream stream)
        {
            var doc  = new GcPdfDocument();
            var page = doc.NewPage();

            var rc = Common.Util.AddNote(
                "Fill the fields in the form and click 'Submit' to send it back to the server. " +
                "The sample server will use the GcPdfDocument.ImportFormDataFromCollection() method " +
                "to import the submitted data into a different but compatible PDF form, " +
                "and the filled form will be sent back to your browser. " +
                "Note that the filled form is opened in the browser's default PDF viewer, " +
                "and does not have the 'Submit' and 'Reset' buttons.",
                page);

            var        g  = page.Graphics;
            TextFormat tf = new TextFormat()
            {
                Font = StandardFonts.Times, FontSize = 14
            };
            PointF ip        = new PointF(72, rc.Bottom + 36);
            float  fldOffset = 72 * 2 + 46;
            float  fldHeight = tf.FontSize * 1.2f;
            float  dY        = 32;

            // Text field:
            g.DrawString("First name:", tf, ip);
            var fldFirstName = new TextField()
            {
                Name = "FirstName", Value = "John"
            };

            fldFirstName.Widget.Page                = page;
            fldFirstName.Widget.Rect                = new RectangleF(ip.X + fldOffset, ip.Y, 72 * 3, fldHeight);
            fldFirstName.Widget.TextFormat.Font     = tf.Font;
            fldFirstName.Widget.TextFormat.FontSize = tf.FontSize;
            doc.AcroForm.Fields.Add(fldFirstName);
            ip.Y += dY;

            // Text field:
            g.DrawString("Last name:", tf, ip);
            var fldLastName = new TextField()
            {
                Name = "LastName", Value = "Smith"
            };

            fldLastName.Widget.Page                = page;
            fldLastName.Widget.Rect                = new RectangleF(ip.X + fldOffset, ip.Y, 72 * 3, fldHeight);
            fldLastName.Widget.TextFormat.Font     = tf.Font;
            fldLastName.Widget.TextFormat.FontSize = tf.FontSize;
            doc.AcroForm.Fields.Add(fldLastName);
            ip.Y += dY;

            // Checkbox:
            g.DrawString("Subscribe to Mailing List:", tf, ip);
            var fldCheckbox = new CheckBoxField()
            {
                Name = "Subscribe", Value = true
            };

            fldCheckbox.Widget.Page = page;
            fldCheckbox.Widget.Rect = new RectangleF(ip.X + fldOffset, ip.Y, fldHeight, fldHeight);
            doc.AcroForm.Fields.Add(fldCheckbox);
            ip.Y += dY;

            // Multiline TextBox:
            g.DrawString("Additional information:", tf, ip);
            var fldAdditionalInfo = new TextField()
            {
                Name = "AdditionalInfo", Multiline = true
            };

            fldAdditionalInfo.Widget.Page                = page;
            fldAdditionalInfo.Widget.Rect                = new RectangleF(ip.X + fldOffset, ip.Y, 72 * 3, fldHeight * 2);
            fldAdditionalInfo.Widget.TextFormat.Font     = tf.Font;
            fldAdditionalInfo.Widget.TextFormat.FontSize = tf.FontSize;
            doc.AcroForm.Fields.Add(fldAdditionalInfo);
            ip.Y += dY * 2;

            // Submit form button:
            var btnSubmit = new PushButtonField();

            btnSubmit.Widget.Rect = new RectangleF(ip.X + fldOffset, ip.Y, 72, fldHeight);
            btnSubmit.Widget.ButtonAppearance.Caption = "Submit";
            btnSubmit.Widget.Highlighting             = HighlightingMode.Invert;
            btnSubmit.Widget.Page = page;

            // The URL for the submission:
            btnSubmit.Widget.Events.Activate = new ActionSubmitForm("/Samples/HandleFormDataSubmit");
            doc.AcroForm.Fields.Add(btnSubmit);

            // Reset form button:
            var btnReset = new PushButtonField();

            btnReset.Widget.Rect = new RectangleF(ip.X + fldOffset + 72 * 1.5f, ip.Y, 72, fldHeight);
            btnReset.Widget.ButtonAppearance.Caption = "Reset";
            btnReset.Widget.Highlighting             = HighlightingMode.Invert;
            btnReset.Widget.Page            = page;
            btnReset.Widget.Events.Activate = new ActionResetForm();
            doc.AcroForm.Fields.Add(btnReset);
            ip.Y += dY;

            // Done:
            doc.Save(stream);
        }