Example #1
0
        // add combo box field for fields of the PDF document
        // with common parameters and default names.
        //
        public static PdfComboBox RenderComboBox(C1PdfDocument pdf, string[] list, int activeIndex, Font font, Rect rc, Color back, string toolTip)
        {
            // create
            string      name     = string.Format("ACFCLB{0}", _comboBoxCount + 1);
            PdfComboBox comboBox = new PdfComboBox();

            // default border
            comboBox.BorderWidth = FieldBorderWidth.Thin;
            comboBox.BorderStyle = FieldBorderStyle.Solid;
            comboBox.BorderColor = Colors.DarkGray;

            // array
            foreach (string text in list)
            {
                comboBox.Items.Add(text);
            }

            // parameters
            comboBox.Font         = font;
            comboBox.Name         = name;
            comboBox.DefaultValue = activeIndex;
            comboBox.Value        = activeIndex;
            comboBox.ToolTip      = string.IsNullOrEmpty(toolTip) ? string.Format("{0} ({1})", string.Format("Count = {0}", comboBox.Items.Count), name) : toolTip;
            if (back != Colors.Transparent)
            {
                comboBox.BackColor = back;
            }

            // add
            pdf.AddField(comboBox, rc);
            _comboBoxCount++;

            // done
            return(comboBox);
        }
Example #2
0
        public static void Main()
        {
            // NOTE:
            // When used in trial mode, the library imposes some restrictions.
            // Please visit http://bitmiracle.com/pdf-library/trial-restrictions.aspx
            // for more information.

            string pathToFile = "Comboboxes.pdf";

            using (PdfDocument pdf = new PdfDocument())
            {
                PdfPage page = pdf.Pages[0];

                PdfComboBox comboBox = page.AddComboBox(10, 50, 120, 15);
                comboBox.AddItem("First item");
                comboBox.AddItem("Second item");
                comboBox.AddItem("Third item");
                comboBox.Border.Color = new PdfRgbColor(255, 0, 0);
                comboBox.Text         = "Second item";

                PdfComboBox comboBox2 = page.AddComboBox(10, 80, 120, 15);
                comboBox2.AddItem("First item");
                comboBox2.AddItem("Second item");
                comboBox2.HasEditField = false;

                pdf.Save(pathToFile);
            }

            Console.WriteLine($"The output is located in {Environment.CurrentDirectory}");
        }
Example #3
0
 public static void Main()
 {
     using (PdfDocument document = new PdfDocument("DocumentName.pdf"))
     {
         PdfCollection <PdfWidget> widgets = document.Pages[0].Widgets;
         foreach (PdfWidget widget in widgets)
         {
             PdfComboBox comboBox = widget as PdfComboBox;
             if (comboBox != null)
             {
                 foreach (string item in comboBox.Items)
                 {
                     // do something with combo box option
                 }
             }
         }
     }
 }
        public static void Main()
        {
            // NOTE:
            // When used in trial mode, the library imposes some restrictions.
            // Please visit http://bitmiracle.com/pdf-library/trial-restrictions.aspx
            // for more information.

            using (PdfDocument pdf = new PdfDocument(@"..\Sample data\ComboBoxes.pdf"))
            {
                System.Text.StringBuilder sb = new System.Text.StringBuilder();
                foreach (PdfWidget widget in pdf.Pages[0].Widgets)
                {
                    PdfComboBox comboBox = widget as PdfComboBox;
                    if (comboBox != null)
                    {
                        sb.Append("Combobox '");
                        sb.Append(comboBox.Name);
                        sb.Append("' contains following items:\n");

                        foreach (PdfListItem item in comboBox.Items)
                        {
                            sb.Append(item);
                            sb.Append("\n");
                        }

                        sb.Append("\n");
                    }
                }

                if (sb.Length == 0)
                {
                    Console.WriteLine("No combo boxes found on first page");
                }
                else
                {
                    Console.WriteLine(sb.ToString());
                }
            }
        }
Example #5
0
        public static void CreateDocument(C1PdfDocument pdf)
        {
            // create pdf document
            pdf.Clear();
            //pdf.Compression = CompressionLevel.NoCompression;
            pdf.ConformanceLevel   = PdfAConformanceLevel.PdfA2b;
            pdf.DocumentInfo.Title = "PDF Acroform";

            // calculate page rect (discounting margins)
            var rcPage = GetPageRect(pdf);
            var rc     = rcPage;

            // add title
            Font titleFont = new Font("Tahoma", 24, PdfFontStyle.Bold);

            rc = RenderParagraph(pdf, pdf.DocumentInfo.Title, titleFont, rcPage, rc, false);

            // render acroforms
            rc = rcPage;
            Font fieldFont = new Font("Arial", 14, PdfFontStyle.Regular);

            // text box field
            rc = new Rect(rc.X, rc.Y + rc.Height / 10, rc.Width / 3, rc.Height / 30);
            PdfTextBox textBox1 = RenderTextBox(pdf, "TextBox Sample", fieldFont, rc);

            textBox1.BorderWidth = FieldBorderWidth.Thick;
            textBox1.BorderStyle = FieldBorderStyle.Inset;
            textBox1.BorderColor = Colors.Green;
            //textBox1.BackColor = Colors.Yellow;

            // first check box field
            rc = new Rect(rc.X, rc.Y + 2 * rc.Height, rc.Width, rc.Height);
            RenderCheckBox(pdf, true, "CheckBox 1 Sample", fieldFont, rc);

            // first radio button group
            rc = new Rect(rc.X, rc.Y + 2 * rc.Height, rc.Width, rc.Height);
            RenderRadioButton(pdf, false, "RadioGroup1", "RadioButton 1 Sample Group 1", fieldFont, rc);
            rc = new Rect(rc.X, rc.Y + 2 * rc.Height, rc.Width, rc.Height);
            RenderRadioButton(pdf, true, "RadioGroup1", "RadioButton 2 Sample Group 1", fieldFont, rc);
            rc = new Rect(rc.X, rc.Y + 2 * rc.Height, rc.Width, rc.Height);
            RenderRadioButton(pdf, false, "RadioGroup1", "RadioButton 3 Sample Group 1", fieldFont, rc);

            // second check box field
            rc = new Rect(rc.X, rc.Y + 2 * rc.Height, rc.Width, rc.Height);
            RenderCheckBox(pdf, false, "CheckBox 2 Sample", fieldFont, rc);

            // second radio button group
            rc = new Rect(rc.X, rc.Y + 2 * rc.Height, rc.Width, rc.Height);
            RenderRadioButton(pdf, true, "RadioGroup2", "RadioButton 1 Sample Group 2", fieldFont, rc);
            rc = new Rect(rc.X, rc.Y + 2 * rc.Height, rc.Width, rc.Height);
            RenderRadioButton(pdf, false, "RadioGroup2", "RadioButton 2 Sample Group 2", fieldFont, rc);

            // first combo box field
            rc = new Rect(rc.X, rc.Y + 2 * rc.Height, rc.Width, rc.Height);
            PdfComboBox comboBox1 = RenderComboBox(pdf, new string[] { "First", "Second", "Third" }, 2, fieldFont, rc);

            // first list box field
            var rclb = new Rect(rc.X, rc.Y + 2 * rc.Height, rc.Width, 3 * rc.Height);

            RenderListBox(pdf, new string[] { "First", "Second", "Third", "Fourth", "Fifth" }, 5, fieldFont, rclb);

            // load first icon
            Image icon = null;

            //using (Stream stream = GetManifestResource("phoenix.png"))
            //{
            //    icon = Image.FromStream(stream);
            //}

            // first push putton field
            rc = new Rect(rc.X, rc.Y + 6 * rc.Height, rc.Width, rc.Height);
            PdfPushButton button1 = RenderPushButton(pdf, "Submit", fieldFont, rc, icon, ButtonLayout.ImageLeftTextRight);

            button1.Actions.Released.Add(new PdfPushButton.Action(ButtonAction.CallMenu, "FullScreen"));
            button1.Actions.GotFocus.Add(new PdfPushButton.Action(ButtonAction.OpenFile, @"..\..\Program.cs"));
            button1.Actions.LostFocus.Add(new PdfPushButton.Action(ButtonAction.GotoPage, "2"));
            button1.Actions.Released.Add(new PdfPushButton.Action(ButtonAction.OpenUrl, "https://www.grapecity.com/en/componentone"));

            //// load second icon
            //using (Stream stream = GetManifestResource("download.png"))
            //{
            //    icon = Image.FromStream(stream);
            //}

            // second push putton field
            rc = new Rect(rc.X, rc.Y + 2 * rc.Height, rc.Width, 2 * rc.Height);
            PdfPushButton button2 = RenderPushButton(pdf, "Cancel", fieldFont, rc, icon, ButtonLayout.TextTopImageBottom);

            button2.Actions.Pressed.Add(new PdfPushButton.Action(ButtonAction.ClearFields));
            button2.Actions.Released.Add(new PdfPushButton.Action(ButtonAction.CallMenu, "Quit"));

            //// load second icon
            //using (Stream stream = GetManifestResource("top100.png"))
            //{
            //    icon = Image.FromStream(stream);
            //}

            // push putton only icon field
            rc = new Rect(rc.X + 1.5f * rc.Width, rc.Y, rc.Width / 2, rc.Height);
            PdfPushButton button3 = RenderPushButton(pdf, "", fieldFont, rc, icon, ButtonLayout.ImageOnly);

            button3.Actions.MouseEnter.Add(new PdfPushButton.Action(ButtonAction.HideField, button1.Name));
            button3.Actions.MouseLeave.Add(new PdfPushButton.Action(ButtonAction.ShowField, button1.Name));
            button3.Actions.Released.Add(new PdfPushButton.Action(ButtonAction.CallMenu, "ShowGrid"));
            button3.BorderWidth = FieldBorderWidth.Medium;
            button3.BorderStyle = FieldBorderStyle.Beveled;
            button3.BorderColor = Colors.Gray;

            // next page
            pdf.NewPage();

            // text for next page
            rc = rcPage;
            RenderParagraph(pdf, "Second page as bookmark", titleFont, rcPage, rc, false);

            // text box field
            //rc = rcPage;
            //rc = new Rect(rc.X, rc.Y + rc.Height / 10, rc.Width / 3, rc.Height / 30);
            //PdfTextBox textBox2 = RenderTextBox("TextSample 2", fieldFont, rc, Color.Yellow, "In 2 page");

            // second pass to number pages
            AddFooters(pdf);
        }
Example #6
0
        private void _btCreate_Click(object sender, EventArgs e)
        {
            // create pdf document
            _c1pdf.Clear();
            _c1pdf.DocumentInfo.Title = "PDF Acroform";
            _statusBar.Text           = "Creating pdf document...";

            // calculate page rect (discounting margins)
            RectangleF rcPage = GetPageRect();
            RectangleF rc     = rcPage;

            // add title
            Font titleFont = new Font("Tahoma", 24, FontStyle.Bold);

            rc = RenderParagraph(_c1pdf.DocumentInfo.Title, titleFont, rcPage, rc, false);

            // render acroforms
            rc = rcPage;
            Font fieldFont = new Font("Arial", 14, FontStyle.Regular);

            // text box field
            rc = new RectangleF(rc.X, rc.Y + rc.Height / 10, rc.Width / 3, rc.Height / 30);
            PdfTextBox textBox1 = RenderTextBox("TextBox Sample", fieldFont, rc);

            textBox1.BorderWidth = FieldBorderWidth.Thick;
            textBox1.BorderStyle = FieldBorderStyle.Inset;
            textBox1.BorderColor = Color.Green;
            //textBox1.BackColor = Color.Yellow;

            // first check box field
            rc = new RectangleF(rc.X, rc.Y + 2 * rc.Height, rc.Width, rc.Height);
            RenderCheckBox(true, "CheckBox 1 Sample", fieldFont, rc);

            // first radio button group
            rc = new RectangleF(rc.X, rc.Y + 2 * rc.Height, rc.Width, rc.Height);
            RenderRadioButton(false, "RadioGroup1", "RadioButton 1 Sample Group 1", fieldFont, rc);
            rc = new RectangleF(rc.X, rc.Y + 2 * rc.Height, rc.Width, rc.Height);
            RenderRadioButton(true, "RadioGroup1", "RadioButton 2 Sample Group 1", fieldFont, rc);
            rc = new RectangleF(rc.X, rc.Y + 2 * rc.Height, rc.Width, rc.Height);
            RenderRadioButton(false, "RadioGroup1", "RadioButton 3 Sample Group 1", fieldFont, rc);

            // second check box field
            rc = new RectangleF(rc.X, rc.Y + 2 * rc.Height, rc.Width, rc.Height);
            RenderCheckBox(false, "CheckBox 2 Sample", fieldFont, rc);

            // second radio button group
            rc = new RectangleF(rc.X, rc.Y + 2 * rc.Height, rc.Width, rc.Height);
            RenderRadioButton(true, "RadioGroup2", "RadioButton 1 Sample Group 2", fieldFont, rc);
            rc = new RectangleF(rc.X, rc.Y + 2 * rc.Height, rc.Width, rc.Height);
            RenderRadioButton(false, "RadioGroup2", "RadioButton 2 Sample Group 2", fieldFont, rc);

            // first combo box field
            rc = new RectangleF(rc.X, rc.Y + 2 * rc.Height, rc.Width, rc.Height);
            PdfComboBox comboBox1 = RenderComboBox(new string[] { "First", "Second", "Third" }, 2, fieldFont, rc);

            // first list box field
            RectangleF rclb = new RectangleF(rc.X, rc.Y + 2 * rc.Height, rc.Width, 3 * rc.Height);

            RenderListBox(new string[] { "First", "Second", "Third", "Fourth", "Fifth" }, 5, fieldFont, rclb);

            // load first icon
            Image icon = null;

            using (Stream stream = GetManifestResource("phoenix.png"))
            {
                icon = Image.FromStream(stream);
            }

            // first push putton field
            rc = new RectangleF(rc.X, rc.Y + 6 * rc.Height, rc.Width, rc.Height);
            PdfPushButton button1 = RenderPushButton("Submit", fieldFont, rc, icon, ButtonLayout.ImageLeftTextRight);

            button1.Actions.Released.Add(new PdfPushButton.Action(ButtonAction.CallMenu, "FullScreen"));
            button1.Actions.GotFocus.Add(new PdfPushButton.Action(ButtonAction.OpenFile, @"..\..\Program.cs"));
            button1.Actions.LostFocus.Add(new PdfPushButton.Action(ButtonAction.GotoPage, "2"));
            button1.Actions.Released.Add(new PdfPushButton.Action(ButtonAction.OpenUrl, "http://www.componentone.com/"));

            // load second icon
            using (Stream stream = GetManifestResource("download.png"))
            {
                icon = Image.FromStream(stream);
            }

            // second push putton field
            rc = new RectangleF(rc.X, rc.Y + 2 * rc.Height, rc.Width, 2 * rc.Height);
            PdfPushButton button2 = RenderPushButton("Cancel", fieldFont, rc, icon, ButtonLayout.TextTopImageBottom);

            button2.Actions.Pressed.Add(new PdfPushButton.Action(ButtonAction.ClearFields));
            button2.Actions.Released.Add(new PdfPushButton.Action(ButtonAction.CallMenu, "Quit"));

            // load second icon
            using (Stream stream = GetManifestResource("top100.png"))
            {
                icon = Image.FromStream(stream);
            }

            // push putton only icon field
            rc = new RectangleF(rc.X + 1.5f * rc.Width, rc.Y, rc.Width / 2, rc.Height);
            PdfPushButton button3 = RenderPushButton("", fieldFont, rc, icon, ButtonLayout.ImageOnly);

            button3.Actions.MouseEnter.Add(new PdfPushButton.Action(ButtonAction.HideField, button1.Name));
            button3.Actions.MouseLeave.Add(new PdfPushButton.Action(ButtonAction.ShowField, button1.Name));
            button3.Actions.Released.Add(new PdfPushButton.Action(ButtonAction.CallMenu, "ShowGrid"));
            button3.BorderWidth = FieldBorderWidth.Medium;
            button3.BorderStyle = FieldBorderStyle.Beveled;
            button3.BorderColor = Color.Gray;

            // next page
            _c1pdf.NewPage();

            // text for next page
            rc = rcPage;
            RenderParagraph("Second page as bookmark", titleFont, rcPage, rc, false);

            // text box field
            //rc = rcPage;
            //rc = new RectangleF(rc.X, rc.Y + rc.Height / 10, rc.Width / 3, rc.Height / 30);
            //PdfTextBox textBox2 = RenderTextBox("TextSample 2", fieldFont, rc, Color.Yellow, "In 2 page");

            // second pass to number pages
            AddFooters();

            // save to file and show it
            _statusBar.Text = "Saving pdf document...";
            string fileName = Path.GetDirectoryName(Application.ExecutablePath) + @"\PdfAcroForm.pdf";

            _c1pdf.Compression = CompressionEnum.None;
            _c1pdf.Save(fileName);
            Process.Start(fileName);
            _statusBar.Text = "Ready.";
        }
Example #7
0
        // add combo box field for fields of the PDF document
        // with common parameters and default names.
        //  
        internal PdfComboBox RenderComboBox(string[] list, int activeIndex, Font font, RectangleF rc, Color back, string toolTip)
        {
            // create
            string name = string.Format("ACFCLB{0}", _comboBoxCount + 1);
            PdfComboBox comboBox = new PdfComboBox();

            // default border
            comboBox.BorderWidth = FieldBorderWidth.Thin;
            comboBox.BorderStyle = FieldBorderStyle.Solid;
            comboBox.BorderColor = SystemColors.ControlDarkDark;

            // array
            foreach (string text in list)
            {
                comboBox.Items.Add(text);
            }

            // parameters
            comboBox.Font = font;
            comboBox.Name = name;
            comboBox.DefaultValue = activeIndex;
            comboBox.Value = activeIndex;
            comboBox.ToolTip = string.IsNullOrEmpty(toolTip) ? string.Format("{0} ({1})", string.Format("Count = {0}", comboBox.Items.Count), name) : toolTip;
            if (back != Color.Transparent && !back.IsEmpty)
            {
                comboBox.BackColor = back;
            }

            // add
            _c1pdf.AddField(comboBox, rc);
            _comboBoxCount++;

            // done
            return comboBox;
        }