Exemplo n.º 1
0
        /// <summary>
        /// Adds a new FormattedText object with the given text and font.
        /// </summary>
        public FormattedText AddFormattedText(string text, Font font)
        {
            FormattedText formattedText = AddFormattedText(font);

            formattedText.AddText(text);
            return(formattedText);
        }
Exemplo n.º 2
0
        /// <summary>
        /// Adds a new FormattedText with the given text.
        /// </summary>
        public FormattedText AddFormattedText(string text)
        {
            FormattedText formattedText = new FormattedText();

            formattedText.AddText(text);
            Add(formattedText);
            return(formattedText);
        }
        /// <summary>
        /// Renders <paramref name="control"/> to the <paramref name="document"/>.
        /// </summary>
        /// <param name="document">The PDF document.</param>
        /// <param name="control">The control to be rendered.</param>
        /// <param name="level">The depth down the control tree being rendered (affects indenting).</param>
        /// <param name="controlList">The complete control list.</param>
        protected override void DoRender(Document document, Control control, int level, ControlList controlList)
        {
            IControlWithOptions controlWithOptions = control as IControlWithOptions;
            string suffix = string.Format(" {0}", controlWithOptions.AllowMultipleSelect ? PdfResources.SelectAll : PdfResources.SelectOne);
            FormattedText formattedSuffix = new FormattedText
                                            {
                                                Style = StyleNames.Normal,
                                                Italic = true
                                            };
            formattedSuffix.AddText(suffix);
            this.Label.Add(formattedSuffix);

            foreach (var option in controlWithOptions.OptionValues ?? new ControlValueOptionList())
            {
                Paragraph paragraph = document.LastSection.AddParagraph();
                FormattedText checkboxText = this.CreateEmptyCheckbox(document.Styles[StyleNames.Normal]);
                paragraph.Format.LeftIndent = new Unit(PdfConstants.IndentMultiplier * level, UnitType.Millimeter);
                paragraph.Add(checkboxText);
                paragraph.AddText(option.Description);
            }
        }
        /// <summary>
        /// Renders <paramref name="control"/> to the <paramref name="document"/>.
        /// </summary>
        /// <param name="document">The PDF document.</param>
        /// <param name="control">The control to be rendered.</param>
        /// <param name="level">The depth down the control tree being rendered (affects indenting).</param>
        /// <param name="controlList">The complete control list.</param>
        protected override void DoRender(Document document, Control control, int level, ControlList controlList)
        {
            IControlWithOptions controlWithOptions = control as IControlWithOptions;
            string suffix = string.Format(" {0}", controlWithOptions.AllowMultipleSelect ? PdfResources.IndicateAll : PdfResources.IndicateOne);
            FormattedText formattedSuffix = new FormattedText
                                            {
                                                Style = StyleNames.Normal,
                                                Italic = true
                                            };
            formattedSuffix.AddText(suffix);
            this.Label.Add(formattedSuffix);

            RepeaterOptionSource optionSource = controlWithOptions.OptionSource as RepeaterOptionSource;
            RepeaterControl repeater = controlList.FindRecursive<RepeaterControl>(optionSource.RepeaterName);
            ControlList valueList = new ControlList();
            valueList.AddRange(optionSource.ValueFields.Select(valueField => repeater.Controls.FindRecursive<Control>(valueField)));

            for (int i = 1; i <= (repeater.MaximumCount ?? PdfConstants.DefaultRepeaterLength); i++)
            {
                this.ListRenderer.Render(valueList, this.Factory, level, controlList);
            }
        }
Exemplo n.º 5
0
        void FillContent(DataTable dt)
        {
            // Fill the address in the address text frame.
            var paragraph = addressFrame.AddParagraph();
            paragraph.AddText("Region Skåne Koncern");
            paragraph.AddLineBreak();
            paragraph.AddText("Malmö...");
            paragraph.AddLineBreak();
            paragraph.AddText("23651 Sverige");

            if (dt != null)
            {
                foreach (DataRow row in dt.Rows)
                {

                    // Each item fills two rows.
                    var row1 = this.table.AddRow();
                    var row2 = this.table.AddRow();
                    row1.TopPadding = 1.5;
                    row1.Cells[0].Shading.Color = TableGray;
                    row1.Cells[0].VerticalAlignment = VerticalAlignment.Center;
                    row1.Cells[0].MergeDown = 1;
                    row1.Cells[1].Format.Alignment = ParagraphAlignment.Left;
                    row1.Cells[1].MergeRight = 3;
                    row1.Cells[5].Shading.Color = TableGray;
                    row1.Cells[5].MergeDown = 1;

                    string apa = row["06Benämning 1"].ToString();

                    Console.WriteLine(apa + row[1].ToString());

                    row1.Cells[0].AddParagraph();
                    paragraph = row1.Cells[1].AddParagraph(apa);
                    var formattedText = new FormattedText() { Style = "Title" };
                    formattedText.AddText(row[1].ToString());
                    paragraph.Add(formattedText);
                    paragraph.AddFormattedText(" by ", TextFormat.Italic);
                    paragraph.AddText(row[2].ToString());

                    row2.Cells[1].AddParagraph(apa);
                    row2.Cells[2].AddParagraph(apa + " €");

                    row2.Cells[4].AddParagraph();
                    row2.Cells[5].AddParagraph(apa);

                    row1.Cells[5].AddParagraph(row["06Benämning 1"].ToString() + " €");
                    row1.Cells[5].VerticalAlignment = VerticalAlignment.Bottom;

                    table.SetEdge(0, table.Rows.Count - 2, 6, 2, Edge.Box, BorderStyle.Single, 0.75);

                    // Add an invisible row as a space line to the table.
                    var rows = table.AddRow();
                    rows.Borders.Visible = false;

                    rows = table.AddRow();
                    rows.Cells[0].Borders.Visible = false;
                    rows.Cells[0].AddParagraph(row["06Benämning 1"].ToString());
                    rows.Cells[5].AddParagraph(0.ToString("0.00") + " €");
                    rows.Cells[0].Format.Font.Bold = true;
                    rows.Cells[0].Format.Alignment = ParagraphAlignment.Right;
                    rows.Cells[0].MergeRight = 4;

                }
            }

            /*
            // Iterate the invoice items.
            double totalExtendedPrice = 0;
            var iter = _navigator.Select("/invoice/items/*");
            while (iter.MoveNext())
            {
                item = iter.Current;
                var quantity = GetValueAsDouble(item, "quantity");
                var price = GetValueAsDouble(item, "price");
                var discount = GetValueAsDouble(item, "discount");

                // Each item fills two rows.
                var row1 = this.table.AddRow();
                var row2 = this.table.AddRow();
                row1.TopPadding = 1.5;
                row1.Cells[0].Shading.Color = TableGray;
                row1.Cells[0].VerticalAlignment = VerticalAlignment.Center;
                row1.Cells[0].MergeDown = 1;
                row1.Cells[1].Format.Alignment = ParagraphAlignment.Left;
                row1.Cells[1].MergeRight = 3;
                row1.Cells[5].Shading.Color = TableGray;
                row1.Cells[5].MergeDown = 1;

                row1.Cells[0].AddParagraph(GetValue(item, "itemNumber"));
                paragraph = row1.Cells[1].AddParagraph();
                var formattedText = new FormattedText() { Style = "Title" };
                formattedText.AddText(GetValue(item, "title"));
                paragraph.Add(formattedText);
                paragraph.AddFormattedText(" by ", TextFormat.Italic);
                paragraph.AddText(GetValue(item, "author"));
                row2.Cells[1].AddParagraph(GetValue(item, "quantity"));
                row2.Cells[2].AddParagraph(price.ToString("0.00") + " €");
                if (discount > 0)
                    row2.Cells[3].AddParagraph(discount.ToString("0") + '%');
                row2.Cells[4].AddParagraph();
                row2.Cells[5].AddParagraph(price.ToString("0.00"));
                var extendedPrice = quantity * price;
                extendedPrice = extendedPrice * (100 - discount) / 100;
                row1.Cells[5].AddParagraph(extendedPrice.ToString("0.00") + " €");
                row1.Cells[5].VerticalAlignment = VerticalAlignment.Bottom;
                totalExtendedPrice += extendedPrice;

                _table.SetEdge(0, _table.Rows.Count - 2, 6, 2, Edge.Box, BorderStyle.Single, 0.75);
            }

            // Add an invisible row as a space line to the table.
            var row = _table.AddRow();
            row.Borders.Visible = false;

            // Add the total price row.
            row = _table.AddRow();
            row.Cells[0].Borders.Visible = false;
            row.Cells[0].AddParagraph("Total Price");
            row.Cells[0].Format.Font.Bold = true;
            row.Cells[0].Format.Alignment = ParagraphAlignment.Right;
            row.Cells[0].MergeRight = 4;
            row.Cells[5].AddParagraph(totalExtendedPrice.ToString("0.00") + " €");
            row.Cells[5].Format.Font.Name = "Segoe UI";

            // Add the VAT row.
            row = _table.AddRow();
            row.Cells[0].Borders.Visible = false;
            row.Cells[0].AddParagraph("VAT (7%)");
            row.Cells[0].Format.Font.Bold = true;
            row.Cells[0].Format.Alignment = ParagraphAlignment.Right;
            row.Cells[0].MergeRight = 4;
            row.Cells[5].AddParagraph((0.07 * totalExtendedPrice).ToString("0.00") + " €");

            // Add the additional fee row.
            row = _table.AddRow();
            row.Cells[0].Borders.Visible = false;
            row.Cells[0].AddParagraph("Shipping and Handling");
            row.Cells[5].AddParagraph(0.ToString("0.00") + " €");
            row.Cells[0].Format.Font.Bold = true;
            row.Cells[0].Format.Alignment = ParagraphAlignment.Right;
            row.Cells[0].MergeRight = 4;

            // Add the total due row.
            row = _table.AddRow();
            row.Cells[0].AddParagraph("Total Due");
            row.Cells[0].Borders.Visible = false;
            row.Cells[0].Format.Font.Bold = true;
            row.Cells[0].Format.Alignment = ParagraphAlignment.Right;
            row.Cells[0].MergeRight = 4;
            totalExtendedPrice += 0.19 * totalExtendedPrice;
            row.Cells[5].AddParagraph(totalExtendedPrice.ToString("0.00") + " €");
            row.Cells[5].Format.Font.Name = "Segoe UI";
            row.Cells[5].Format.Font.Bold = true;

            // Set the borders of the specified cell range.
            _table.SetEdge(5, _table.Rows.Count - 4, 1, 4, Edge.Box, BorderStyle.Single, 0.75);

            // Add the notes paragraph.
            paragraph = _document.LastSection.AddParagraph();
            paragraph.Format.Alignment = ParagraphAlignment.Center;
            paragraph.Format.SpaceBefore = "1cm";
            paragraph.Format.Borders.Width = 0.75;
            paragraph.Format.Borders.Distance = 3;
            paragraph.Format.Borders.Color = TableBorder;
            paragraph.Format.Shading.Color = TableGray;
            item = SelectItem("/invoice");
            paragraph.AddText(GetValue(item, "notes"));
            }
             * */
        }
 /// <summary>
 /// Adds a new FormattedText with the given text.
 /// </summary>
 public FormattedText AddFormattedText(string text)
 {
   FormattedText formattedText = new FormattedText();
   formattedText.AddText(text);
   this.Add(formattedText);
   return formattedText;
 }