Beispiel #1
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 = "TextFields.pdf";

            using (PdfDocument pdf = new PdfDocument())
            {
                PdfPage    page    = pdf.Pages[0];
                PdfTextBox textBox = page.AddTextBox(10, 50, 100, 30);
                textBox.Text = "Hello";

                PdfTextBox textBoxWithMaxLength = page.AddTextBox(10, 90, 100, 30);
                textBoxWithMaxLength.MaxLength = 5;

                PdfTextBox passwordTextBox = page.AddTextBox(10, 130, 100, 30);
                passwordTextBox.Text          = "Secret password";
                passwordTextBox.PasswordField = true;

                pdf.Save(pathToFile);
            }

            Console.WriteLine($"The output is located in {Environment.CurrentDirectory}");
        }
Beispiel #2
0
        // add text box field for fields of the PDF document
        // with common parameters and default names.
        //
        static PdfTextBox RenderTextBox(C1PdfDocument pdf, string text, Font font, Rect rc, Color back, string toolTip)
        {
            // create
            string     name    = string.Format("ACFTB{0}", _textBoxCount + 1);
            PdfTextBox textBox = new PdfTextBox();

            // default border
            //textBox.BorderWidth = 3f / 4;
            textBox.BorderStyle = FieldBorderStyle.Solid;
            textBox.BorderColor = Colors.DarkGray;

            // parameters
            textBox.Font        = font;
            textBox.Name        = name;
            textBox.DefaultText = text;
            textBox.Text        = text;
            textBox.ToolTip     = string.IsNullOrEmpty(toolTip) ? string.Format("{0} ({1})", text, name) : toolTip;
            if (back != Colors.Transparent)
            {
                textBox.BackColor = back;
            }

            // add
            pdf.AddField(textBox, rc);
            _textBoxCount++;

            // done
            return(textBox);
        }
Beispiel #3
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.

            using (PdfDocument pdf = new PdfDocument())
            {
                PdfPoint       startPoint           = new PdfPoint(10, 10);
                PdfSize        size                 = new PdfSize(100, 100);
                float          distance             = 30.0f;
                PdfTextAlign[] horizontalAlignments = { PdfTextAlign.Left, PdfTextAlign.Center, PdfTextAlign.Right };

                PdfPage page = pdf.Pages[0];
                for (int h = 0; h < horizontalAlignments.Length; ++h)
                {
                    PdfTextBox textBox = page.AddTextBox(
                        startPoint.X + h * (size.Width + distance),
                        startPoint.Y,
                        size.Width,
                        size.Height
                        );
                    textBox.Multiline = true;
                    textBox.TextAlign = horizontalAlignments[h];
                    textBox.Text      = "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Vestibulum eu ligula ligula, sit amet tempor odio.";
                }

                string pathToFile = "TextFieldAlignment.pdf";
                pdf.Save(pathToFile);
                Console.WriteLine($"The output is located in {Environment.CurrentDirectory}");
            }
        }
Beispiel #4
0
        // add text box field for fields of the PDF document
        // with common parameters and default names.
        //
        internal PdfTextBox RenderTextBox(string text, Font font, RectangleF rc, Color back, string toolTip)
        {
            // create
            string     name    = string.Format("ACFTB{0}", _textBoxCount + 1);
            PdfTextBox textBox = new PdfTextBox();

            // default border
            //textBox.BorderWidth = 3f / 4;
            textBox.BorderStyle = FieldBorderStyle.Solid;
            textBox.BorderColor = SystemColors.ControlDarkDark;

            // parameters
            textBox.Font        = font;
            textBox.Name        = name;
            textBox.DefaultText = text;
            textBox.Text        = text;
            textBox.ToolTip     = string.IsNullOrEmpty(toolTip) ? string.Format("{0} ({1})", text, name) : toolTip;
            if (back != Color.Transparent && !back.IsEmpty)
            {
                textBox.BackColor = back;
            }

            // add
            _c1pdf.AddField(textBox, rc);
            _textBoxCount++;

            // done
            return(textBox);
        }
Beispiel #5
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 = "FillForm.pdf";

            using (PdfDocument pdf = new PdfDocument(@"..\Sample data\form.pdf"))
            {
                foreach (PdfControl control in pdf.GetControls())
                {
                    switch (control.Name)
                    {
                    case "login":
                        ((PdfTextBox)control).Text = "Some Name";
                        break;

                    case "passwd":
                    case "passwd2":
                        PdfTextBox password = (PdfTextBox)control;
                        password.Text          = "Password";
                        password.PasswordField = true;
                        break;

                    case "email":
                        ((PdfTextBox)control).Text = "*****@*****.**";
                        break;

                    case "user_viewemail":
                        ((PdfCheckBox)control).Checked = false;
                        break;

                    case "user_sorttopics":
                        // Check the radio button "Show new topics first"
                        PdfRadioButton sortTopics = (PdfRadioButton)control;
                        if (sortTopics.ExportValue == "user_not_sorttopics")
                        {
                            sortTopics.Checked = true;
                        }

                        break;

                    case "BtnRegister":
                        ((PdfButton)control).ReadOnly = true;
                        break;
                    }
                }

                pdf.Save(pathToFile);
            }

            Console.WriteLine($"The output is located in {Environment.CurrentDirectory}");
        }
        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 = "SubmitResetFormActions.pdf";

            using (PdfDocument pdf = new PdfDocument())
            {
                PdfPage    page    = pdf.Pages[0];
                PdfTextBox textBox = page.AddTextBox("sample_textbox", 10, 50, 100, 15);
                textBox.Text = "Hello";

                PdfCheckBox checkBox = page.AddCheckBox("sample_checkbox", 10, 70, 100, 15, "Check me");
                checkBox.Checked = true;

                PdfRadioButton radioButton = page.AddRadioButton("radio", 10, 90, 100, 15, "Select me!");
                radioButton.ExportValue = "radio1";
                radioButton.Checked     = true;

                PdfRadioButton radioButton2 = page.AddRadioButton("radio", 10, 110, 100, 15, "No, select me!");
                radioButton2.ExportValue = "radio2";
                radioButton2.Checked     = false;

                PdfButton submitButton = page.AddButton(10, 130, 45, 20);
                submitButton.Text = "Submit";
                PdfSubmitFormAction submitAction = pdf.CreateSubmitFormAction(new Uri("http://bitmiracle.com/login.php"));
                submitAction.SubmitFormat = PdfSubmitFormat.Html;
                submitAction.SubmitMethod = PdfSubmitMethod.Get;
                submitAction.AddControl(textBox);
                submitAction.AddControl(checkBox);
                submitAction.AddControl(radioButton);
                submitAction.AddControl(radioButton2);
                submitButton.OnMouseDown = submitAction;

                PdfButton resetButton = page.AddButton(65, 130, 45, 20);
                resetButton.Text = "Reset";
                PdfResetFormAction resetAction = pdf.CreateResetFormAction();
                resetAction.AddControl(textBox);
                resetAction.AddControl(checkBox);
                resetAction.AddControl(radioButton);
                resetAction.AddControl(radioButton2);
                resetButton.OnMouseDown = resetAction;

                pdf.Save(pathToFile);
            }

            Process.Start(pathToFile);
        }
Beispiel #7
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.

            const string pathToFile = "FindControlByName.pdf";

            using (PdfDocument pdf = new PdfDocument(@"..\Sample Data\form.pdf"))
            {
                PdfTextBox emailTextBox = pdf.GetControl("email") as PdfTextBox;
                Debug.Assert(emailTextBox != null);

                emailTextBox.Text = "*****@*****.**";

                pdf.Save(pathToFile);
            }

            Console.WriteLine($"The output is located in {Environment.CurrentDirectory}");
        }
        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.

            const string pathToFile = "FindControlByName.pdf";

            using (PdfDocument pdf = new PdfDocument(@"Sample Data\form.pdf"))
            {
                PdfTextBox emailTextBox = pdf.GetControl("email") as PdfTextBox;
                Debug.Assert(emailTextBox != null);

                emailTextBox.Text = "*****@*****.**";

                pdf.Save(pathToFile);
            }

            Process.Start(pathToFile);
        }
        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 = "HideAction.pdf";

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

                PdfButton hideeButton = page.AddButton(45, 85, 70, 25);
                hideeButton.Text = "Button";

                PdfTextBox hideeTextBox = page.AddTextBox(45, 120, 70, 25);
                hideeTextBox.Text = "TextBox";

                PdfHideAction hideAction = pdf.CreateHideAction(true);
                hideAction.AddControl(hideeButton);
                hideAction.AddControl(hideeTextBox);

                PdfHideAction showAction = pdf.CreateHideAction(false);
                showAction.AddControl(hideeButton);
                showAction.AddControl(hideeTextBox);

                PdfButton showButton = page.AddButton("showBtn", 10, 50, 70, 25);
                showButton.Text      = "Show controls";
                showButton.OnMouseUp = showAction;

                PdfButton hideButton = page.AddButton("hideBtn", 90, 50, 70, 25);
                hideButton.Text      = "Hide controls";
                hideButton.OnMouseUp = hideAction;

                pdf.Save(pathToFile);
            }

            Console.WriteLine($"The output is located in {Environment.CurrentDirectory}");
        }
Beispiel #10
0
        public static void Main()
        {
            StringBuilder validationJavascript = new StringBuilder();

            validationJavascript.AppendLine("function validateNumeric(event) {");
            validationJavascript.AppendLine("    var validCharacters = \"0123456789\";");
            validationJavascript.AppendLine("    for (var i = 0; i < event.change.length; i++) {");
            validationJavascript.AppendLine("        if (validCharacters.indexOf(event.change.charAt(i)) == -1) {");
            validationJavascript.AppendLine("            app.beep(0);");
            validationJavascript.AppendLine("            event.rc = false;");
            validationJavascript.AppendLine("            break;");
            validationJavascript.AppendLine("        }");
            validationJavascript.AppendLine("    }");
            validationJavascript.AppendLine("}");

            // 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 = "NumericTextField.pdf";

            using (PdfDocument pdf = new PdfDocument())
            {
                pdf.SharedScripts.Add(
                    pdf.CreateJavaScriptAction(validationJavascript.ToString())
                    );

                PdfTextBox textBox = pdf.Pages[0].AddTextBox(20, 50, 100, 20);
                textBox.OnKeyPress = pdf.CreateJavaScriptAction("validateNumeric(event);");

                pdf.Save(pathToFile);
            }

            Console.WriteLine($"The output is located in {Environment.CurrentDirectory}");
        }
Beispiel #11
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);
        }
Beispiel #12
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.";
        }
Beispiel #13
0
        public static void CreateClassroomParticipantsForm(List <Classroom> classrooms)
        {
            foreach (var classroom in classrooms)
            {
                using (PdfDocument pdf = new PdfDocument("Sample Data/classroomm.pdf")) // doldurulabilir boş form pdf'i
                {
                    List <PdfControl> controls = pdf.GetControls().ToList();

                    PdfCanvas canvas    = pdf.Pages[0].Canvas;
                    double    axisy     = 87.5;
                    int       examGroup = 0;
                    int       k         = 1;



                    PdfTextBox classNoTBox = pdf.GetControl("classNo") as PdfTextBox;
                    classNoTBox.FontSize = 20;
                    Debug.Assert(classNoTBox != null);
                    classNoTBox.Text = classroom.Name.ToUpper();

                    for (int i = 0; i < classroom.ExamDeskCount; i++)
                    {
                        using (Bitmap bitmap =
                                   new Bitmap($"Outputs/Photos/{classroom.ApplicantStudents[i].IdentityNo}.jpg"))
                        {
                            PdfImage image2;

                            image2 = pdf.AddImage(bitmap);

                            if (i < 10)
                            {
                                canvas.DrawImage(image2, 32, axisy, 52, 64, 0);
                                axisy += 66.5;
                                if (i == 9)
                                {
                                    axisy = 87.5;
                                }
                            }
                            else
                            {
                                canvas.DrawImage(image2, 311, axisy, 46.5, 64.5, 0);
                                axisy += 66.5;
                            }
                        }

                        string cname = String.Empty;


                        for (int j = 0; j < classroom.ExamDeskCount; j++)
                        {
                            cname = $"p{k.ToString()}name";
                            PdfTextBox nameTextBox = pdf.GetControl(cname) as PdfTextBox;
                            nameTextBox.FontSize = 6;
                            Debug.Assert(nameTextBox != null);
                            nameTextBox.Text = classroom.ApplicantStudents[i].Name.ToUpper();

                            cname = $"p{k.ToString()}surname";
                            PdfTextBox surnameTextBox = pdf.GetControl(cname) as PdfTextBox;
                            surnameTextBox.FontSize = 6;
                            Debug.Assert(surnameTextBox != null);
                            surnameTextBox.Text = classroom.ApplicantStudents[i].Surname.ToUpper();

                            cname = $"p{k.ToString()}id";
                            PdfTextBox idTextBox = pdf.GetControl(cname) as PdfTextBox;
                            idTextBox.FontSize = 6;
                            Debug.Assert(idTextBox != null);
                            idTextBox.Text = classroom.ApplicantStudents[i].IdentityNo.ToString().ToUpper();

                            cname = $"p{k.ToString()}classNo";
                            PdfTextBox classNoTextBox = pdf.GetControl(cname) as PdfTextBox;
                            classNoTextBox.FontSize = 6;
                            Debug.Assert(classNoTextBox != null);
                            classNoTextBox.Text = classroom.Name.ToUpper();

                            cname = $"p{k.ToString()}deskNo";
                            PdfTextBox deskNoTextBox = pdf.GetControl(cname) as PdfTextBox;
                            deskNoTextBox.FontSize = 6;
                            Debug.Assert(deskNoTextBox != null);
                            deskNoTextBox.Text = classroom.ApplicantStudents[i].ExamDeskNo.ToString();

                            if (k < classroom.ExamDeskCount)
                            {
                                k++;
                                break;
                            }
                        }
                    }
                    string pathToFile = $"Outputs/{classroom.Building} {classroom.Name}.pdf";
                    pdf.ReplaceDuplicateObjects();
                    pdf.SaveOptions.Compression             = PdfCompression.Flate;
                    pdf.SaveOptions.UseObjectStreams        = true;
                    pdf.SaveOptions.RemoveUnusedObjects     = true;
                    pdf.SaveOptions.OptimizeIndirectObjects = true;
                    pdf.SaveOptions.WriteWithoutFormatting  = true;
                    pdf.RemoveStructureInformation();
                    pdf.Metadata.Basic.Clear();
                    pdf.Metadata.DublinCore.Clear();
                    pdf.Metadata.MediaManagement.Clear();
                    pdf.Metadata.Pdf.Clear();
                    pdf.Metadata.RightsManagement.Clear();
                    pdf.Metadata.Custom.Properties.Clear();
                    foreach (XmpSchema schema in pdf.Metadata.Schemas)
                    {
                        schema.Properties.Clear();
                    }
                    pdf.Info.Clear(false);
                    unembedFonts(pdf);
                    pdf.RemoveUnusedResources();
                    pdf.RemovePieceInfo();
                    pdf.FlattenControls();
                    pdf.Save(pathToFile);
                }
            }
        }
Beispiel #14
0
        // add text box field for fields of the PDF document
        // with common parameters and default names.
        //  
        internal PdfTextBox RenderTextBox(string text, Font font, RectangleF rc, Color back, string toolTip, bool multiline)
        {
            //  create
            string name = string.Format("ACFTB{0}", _textBoxCount + 1);
            PdfTextBox textBox = new PdfTextBox();

            //  default border
            // textBox.BorderWidth = 3f / 4;
            textBox.BorderStyle = FieldBorderStyle.Solid;
            textBox.BorderColor = SystemColors.ControlDarkDark;

            // parameters
            textBox.Font = font;
            textBox.Name = name;
            textBox.DefaultText = text;
            textBox.Text = text;
            textBox.ToolTip = string.IsNullOrEmpty(toolTip) ? string.Format("{0} ({1})", text, name) : toolTip;
            if (back != Color.Transparent && !back.IsEmpty)
            {
                textBox.BackColor = back;
            }
            textBox.IsMultiline = multiline;
            // add
            _c1pdf.AddField(textBox, rc);
            _textBoxCount++;

            // done
            return textBox;
        }