Exemplo n.º 1
0
        /// <summary>
        /// Add labeled TextBox rectangle into PDF document
        /// </summary>
        /// <param name="label">Label of the TextBox</param>
        /// <param name="currentY">Y position of the TextBox</param>
        /// <param name="textBoxHeight">TextBox height</param>
        /// <param name="lineWidth">TextBox border width</param>
        /// <param name="spacingAfterLabel">Size of the gap between label and TextBox</param>
        /// <param name="borderColor">Border color of the TextBox rectangle</param>
        /// <returns>Returns actual Y position in the PDF document</returns>
        internal float AddTextBox(string label, float currentY, float textBoxHeight, float lineWidth, float spacingAfterLabel, System.Drawing.Color borderColor)
        {
            //simulate the creation of columnText to get its height
            ColumnText ct = GetColumnText(new Paragraph(GetBoldText(label)), LX, currentY, true);

            //if there is no space for labeled TextBox, add new page to PDF document
            if (AddPage(currentY, spacingAfterLabel + (currentY - ct.YLine) + textBoxHeight))
            {
                currentY = NewPage();
            }
            ct       = GetColumnText(new Paragraph(GetBoldText(label)), LX, currentY, false);
            currentY = ct.YLine - spacingAfterLabel;

            ContentByte.SetLineWidth(lineWidth);
            ContentByte.SetColorStroke(new BaseColor(borderColor));
            ContentByte.Rectangle(LX, currentY, RX - RX / 3, -textBoxHeight);
            ContentByte.Stroke();
            currentY -= textBoxHeight;

            return(NewPage(currentY, 0));
        }
Exemplo n.º 2
0
        /// <summary>
        /// Add CheckBoxes into PDF document
        /// </summary>
        /// <param name="choices">CheckBox options</param>
        /// <param name="label">Label for the CheckBox group</param>
        /// <param name="note">Note for the CheckBox group</param>
        /// <param name="currentY">Y position of the upper left corner of the CheckBox group</param>
        /// <param name="size">Size of the CheckBox square</param>
        /// <param name="lineWidth">CheckBox square border width</param>
        /// <param name="spacingAfterLabel">Spacing between label and the CheckBox group</param>
        /// <param name="borderColor">Border color of the CheckBox square</param>
        /// <returns>Actual Y position in the PDF document</returns>
        internal float AddCheckBoxes(string[] choices, string label, string note, float currentY, float size, float lineWidth,
                                     float spacingAfterLabel, System.Drawing.Color borderColor)
        {
            //simulate the creation of columnText to get its height
            ColumnText ct = GetColumnText(new Paragraph(GetBoldText(label)), LX, currentY, true);

            //if there is no space for label and the first CheckBox, add new page to PDF document
            if (AddPage(currentY, spacingAfterLabel + (currentY - ct.YLine) + size))
            {
                currentY = NewPage();
            }

            ct       = GetColumnText(new Paragraph(GetBoldText(label)), LX, currentY, false);
            currentY = ct.YLine - spacingAfterLabel;

            ContentByte.SetLineWidth(lineWidth);
            ContentByte.SetColorStroke(new BaseColor(borderColor));

            foreach (var choice in choices)
            {
                currentY = NewPage(currentY, size + spacingAfterLabel);

                ContentByte.Rectangle(LX, currentY, size, -size);
                ContentByte.Stroke();

                ct        = GetColumnText(new Paragraph(GetCheckBoxText(choice)), LX + size + spacingAfterLabel, currentY + size - 4f, false);
                currentY -= (size + spacingAfterLabel);
            }

            ct = GetColumnText(new Paragraph(GetNoteText(note)), LX, currentY + size - 1.5f, true);
            if (AddPage(currentY, spacingAfterLabel + (currentY - ct.YLine)))
            {
                currentY = NewPage();
            }

            ct = GetColumnText(new Paragraph(GetNoteText(note)), LX, currentY + size - 1.5f, false);

            return(NewPage(currentY, 0));
        }