private void FillTable(Aspose.Pdf.Generator.Table tab, DataTable dt)
        {
            NumberFormatInfo format = new NumberFormatInfo();

            format.CurrencyPositivePattern = 0;
            format.CurrencySymbol          = "$";

            tab.DefaultCellTextInfo.FontSize = 10;
            tab.ImportDataTable(dt, false, 1, 0);
            foreach (Row curRow in tab.Rows)
            {
                foreach (Cell curCell in curRow.Cells)
                {
                    curCell.Padding        = new MarginInfo();
                    curCell.Padding.Top    = 3;
                    curCell.Padding.Bottom = 3;
                }
                if (tab.Rows.IndexOf(curRow) > 0)
                {
                    ((Aspose.Pdf.Generator.Text)curRow.Cells[3].Paragraphs[0]).TextInfo.Alignment = AlignmentType.Right;
                    ((Aspose.Pdf.Generator.Text)curRow.Cells[1].Paragraphs[0]).TextInfo.Alignment = AlignmentType.Center;
                    double price = Convert.ToDouble(((Aspose.Pdf.Generator.Text)curRow.Cells[3].Paragraphs[0]).Segments[0].Content);
                    ((Aspose.Pdf.Generator.Text)curRow.Cells[3].Paragraphs[0]).Segments[0].Content = price.ToString("C", format);
                }
                ((Aspose.Pdf.Generator.Text)curRow.Cells[0].Paragraphs[0]).Segments[0].TextInfo.FontName = "Times-Bold";
            }
        }
        public Aspose.Pdf.Generator.Pdf GetCustomerLabels()
        {
            Aspose.Pdf.Generator.Pdf pdf = new Aspose.Pdf.Generator.Pdf();
            pdf.IsTruetypeFontMapCached = false;

            // If you have purchased a license,
            // Set license like this:
            // string licenseFile = MapPath("License") + "\\Aspose.Pdf.lic";
            // Aspose.Pdf.License lic = new Aspose.Pdf.License();
            // lic.SetLicense(licenseFile);

            string xmlFile = Server.MapPath("~/App_Data/xml/CustomerLabels.xml");

            pdf.BindXML(xmlFile, null);

            Section section = pdf.Sections["section1"];

            Aspose.Pdf.Generator.Table table1 = (Aspose.Pdf.Generator.Table)section.Paragraphs["table1"];

            IList <Customer> customersList = customerDao.GetAll();

            string[] strArr = new string[customersList.Count];

            for (int i = 0; i < customersList.Count; i++)
            {
                strArr[i] = customersList[0].CompanyName.ToString() + "#$NL" + customersList[1].Address.ToString() + "#$NL" +
                            customersList[2].City.ToString() + " " + (customersList[3].Region == null ? string.Empty : customersList[3].Region.ToString()) + " " +
                            customersList[4].PostalCode.ToString() + "#$NL" + customersList[5].Country.ToString();
            }

            table1.DefaultCellTextInfo.FontSize = 10;
            table1.ImportArray(strArr, 0, 0, false);

            foreach (Row cRow in table1.Rows)
            {
                foreach (Cell curCell in cRow.Cells)
                {
                    curCell.Padding     = new MarginInfo();
                    curCell.Padding.Top = 10;
                }
            }

            return(pdf);
        }
예제 #3
0
        private void AddRow(Aspose.Pdf.Generator.Pdf pdf, Aspose.Pdf.Generator.Table tabel, FlightInfo flightInfo)
        {
            //add a new row in order detail.
            Section section = pdf.Sections[0];

            Aspose.Pdf.Generator.TextInfo tf1 = new Aspose.Pdf.Generator.TextInfo();
            tf1.FontSize  = 10;
            tf1.Alignment = AlignmentType.Center;

            Row row1DetailTable = tabel.Rows.Add();

            row1DetailTable.Cells.Add("1", tf1);
            tf1.Alignment = AlignmentType.Left;
            row1DetailTable.Cells.Add("Ticket: " + flightInfo.DepartureLocation + " to " + flightInfo.Destination, tf1);
            tf1.Alignment = AlignmentType.Center;
            row1DetailTable.Cells.Add("1", tf1);
            row1DetailTable.Cells.Add(flightInfo.Fare.ToString("c", locale), tf1);
            row1DetailTable.Cells.Add("0" + "%", tf1);
            row1DetailTable.Cells.Add(flightInfo.Fare.ToString("c", locale), tf1);
        }
        public Aspose.Pdf.Generator.Pdf GetProductsByCategory()
        {
            IList <Product>  productsList = productDao.GetAll();
            IList <Category> CategoryList = categoryDao.GetAll();

            Aspose.Pdf.Generator.Pdf pdf = new Aspose.Pdf.Generator.Pdf();
            pdf.IsTruetypeFontMapCached = false;

            // If you have purchased a license,
            // Set license like this:
            // string licenseFile = MapPath("License") + "\\Aspose.Pdf.lic";
            // Aspose.Pdf.License lic = new Aspose.Pdf.License();
            // lic.SetLicense(licenseFile);

            string xmlFile = Server.MapPath("~/App_Data/xml/ProductsByCategory.xml");

            pdf.BindXML(xmlFile, null);

            Section section = pdf.Sections["section1"];

            Aspose.Pdf.Generator.Table table1 = new Aspose.Pdf.Generator.Table(section);
            section.Paragraphs.Add(table1);
            table1.ColumnWidths                 = "314 314 314";
            table1.Border                       = new BorderInfo((int)BorderSide.Top, 4, new Aspose.Pdf.Generator.Color(204));
            table1.IsRowBroken                  = false;
            table1.DefaultCellPadding.Top       = table1.DefaultCellPadding.Bottom = 15;
            table1.DefaultCellTextInfo.FontSize = 14;
            table1.Margin.Top                   = 10;

            int  j;
            Row  curRow  = null;
            Cell curCell = null;

            Aspose.Pdf.Generator.Table curSubTab = null;
            string[] names = new string[]
            { "Catagory: Beverages", "Catagory: Condiments", "Catagory: Confections",
              "Catagory: Dairy Products", "Catagory: Grains/Cereals", "Catagory: Meat/Poultry",
              "Catagory: Produce", "Catagory: Seafood" };

            for (j = 1; j <= 8; j++)
            {
                if (j == 1 || j == 4 || j == 7)
                {
                    curRow = table1.Rows.Add();
                }
                curCell   = curRow.Cells.Add();
                curSubTab = new Aspose.Pdf.Generator.Table(curCell);
                curSubTab.DefaultCellPadding.Top = curSubTab.DefaultCellPadding.Bottom = 3;
                curCell.Paragraphs.Add(curSubTab);
                curSubTab.ColumnWidths = "214 90";

                Row row0 = curSubTab.Rows.Add();
                Aspose.Pdf.Generator.TextInfo tf1 = new Aspose.Pdf.Generator.TextInfo();
                tf1.FontSize = 16;
                tf1.FontName = "Times-Bold";

                row0.Cells.Add(names[j - 1], tf1);

                IList <Product> filteredProductsList = (from productsTable in productsList
                                                        where (productsTable.Discontinued == false) && (productsTable.CategoryID == j)
                                                        orderby productsTable.ProductName
                                                        select productsTable).ToList <Product>();

                DataTable dataTable1 = ConvertToDataTable(filteredProductsList);

                curSubTab.ImportDataTable(dataTable1, true, 1, 0);

                curSubTab.Rows[1].Border = new BorderInfo((int)(BorderSide.Top | BorderSide.Bottom), 4, new Aspose.Pdf.Generator.Color(204));

                Row lastRow = curSubTab.Rows[curSubTab.Rows.Count - 1];
                foreach (Cell cCell in lastRow.Cells)
                {
                    cCell.Padding.Bottom = 20;
                }

                lastRow = curSubTab.Rows.Add();
                lastRow.Cells.Add("number of products:");
                lastRow.Cells.Add(dataTable1.Rows.Count.ToString());
                lastRow.Border = new BorderInfo((int)BorderSide.Top, new Aspose.Pdf.Generator.Color(204));
            }

            curRow.Cells.Add();
            return(pdf);
        }