Spire.Doc is a professional Word .NET library specifically designed for developers to create, read, write, convert and print Word document files. Get free and professional technical support for Spire.Doc for .NET, Java, Android, C++, Python.

Mon Aug 23, 2021 9:37 am

Im trying to render a html checkbox however it's not visible. My code is like below
Code: Select all
                        Section workingSection = _agendaDocument.Sections[0];
                        Table table = workingSection.AddTable(false);
                        table.ResetCells(1, 2);

                        Paragraph cellOnePara = table.Rows[0].Cells[0].AddParagraph();
                        table.Rows[0].Cells[0].CellFormat.VerticalAlignment = VerticalAlignment.Top;
                        table.Rows[0].Cells[0].Width = 50;
                        cellOnePara.Text = "Title";
                        cellOnePara.ApplyStyle("HeadingStyle");
                        cellOnePara.Format.BeforeAutoSpacing = false;
                        cellOnePara.Format.BeforeSpacing = 0;
                        cellOnePara.Format.AfterAutoSpacing = false;
                        cellOnePara.Format.AfterSpacing = 5;

                        //Add checkbox content control
                       
                        Paragraph cellTwoPara = table.Rows[0].Cells[1].AddParagraph();
                        table.Rows[0].Cells[1].CellFormat.VerticalAlignment = VerticalAlignment.Top;

                        string checkBoxHtml = @"<input type=""checkbox"" checked=""Checked"">";

                        cellTwoPara.AppendHTML(checkBoxHtml);


I have a another piece of code that works but the check box style is not according to our requirement. i just need to have a look of simple html checkbox ( both check and unchecked )

below is my working code that the look of the checkbox is not acceptable.

Code: Select all
                        Section workingSection = _agendaDocument.Sections[0];
                        Table table = workingSection.AddTable(false);
                        table.ResetCells(1, 2);

                        Paragraph cellOnePara = table.Rows[0].Cells[0].AddParagraph();
                        table.Rows[0].Cells[0].CellFormat.VerticalAlignment = VerticalAlignment.Top;
                        table.Rows[0].Cells[0].Width = 50;
                        cellOnePara.Text = "Title";
                        cellOnePara.ApplyStyle("HeadingStyle");
                        cellOnePara.Format.BeforeAutoSpacing = false;
                        cellOnePara.Format.BeforeSpacing = 0;
                        cellOnePara.Format.AfterAutoSpacing = false;
                        cellOnePara.Format.AfterSpacing = 5;

                        //Add checkbox content control
                        StructureDocumentTagInline sdt = new StructureDocumentTagInline(_agendaDocument);
                        Paragraph cellTwoPara = table.Rows[0].Cells[1].AddParagraph();
                        table.Rows[0].Cells[1].CellFormat.VerticalAlignment = VerticalAlignment.Top;
                        sdt = new StructureDocumentTagInline(_agendaDocument);
                        cellTwoPara.ChildObjects.Add(sdt);
                        sdt.SDTProperties.SDTType = SdtType.CheckBox;
                        SdtCheckBox scb = new SdtCheckBox();
                        sdt.SDTProperties.ControlProperties = scb;
                        TextRange tr = new TextRange(_agendaDocument);
                        //tr.CharacterFormat.FontName = "MS Gothic";
                        //tr.CharacterFormat.FontSize = 20;
                        sdt.ChildObjects.Add(tr);
                        scb.Checked = true;
                        sdt.SDTProperties.Alias = "CheckoBox";
                        sdt.SDTProperties.Tag = "Checkbox";


Can you please advice me how to achive simple html looking checkbox ( please note that output type of the document is PDF )

infra
 
Posts: 18
Joined: Tue Apr 03, 2018 12:05 pm

Tue Aug 24, 2021 6:26 am

Hello

Thanks for your inquiry.

Regarding the first method you used, I’m sorry that our Spire.Doc doesn’t currently support converting html checkbox to Word checkbox.

As for the another piece of code you used, when the checkbox is checked, the symbol displayed is “×”, do you want to display a tick (√)? If so, our Spire.Doc supports setting the checkbox style through the following code.
Code: Select all
            StructureDocumentTagInline sdt = new StructureDocumentTagInline(document);

            paragraph.ChildObjects.Add(sdt);

            sdt.SDTProperties.SDTType = SdtType.CheckBox;

            SdtCheckBox scb = new SdtCheckBox();
            sdt.SDTProperties.ControlProperties = scb;

            scb.CheckedStateFontName = "Wingdings 2";
            scb.UnCheckedStateFontName = "Wingdings 2";
            scb.CheckedStateCharacterCode = 82;
            scb.UnCheckedStateCharacterCode = 163;
            TextRange tr = new TextRange(document);
            tr.CharacterFormat.FontName = "Wingdings 2";
            tr.CharacterFormat.FontSize = 12;

            sdt.ChildObjects.Add(tr);
            scb.Checked = true;



Sincerely,
Brian
E-iceblue support team
User avatar

Brian.Li
 
Posts: 1271
Joined: Mon Oct 19, 2020 3:04 am

Wed Sep 08, 2021 2:20 am

Hello,

Greetings from E-iceblue!
How is your issue now? Could you please give us some feedback at your convenience?

Sincerely,
Brian
E-iceblue support team
User avatar

Brian.Li
 
Posts: 1271
Joined: Mon Oct 19, 2020 3:04 am

Return to Spire.Doc