示例#1
0
        public static void Run()
        {
            // ExStart:SetTableColumnsWidth
            // The path to the documents directory.
            string dataDir = RunExamples.GetDataDir_AsposePdfGenerator_TechnicalArticles();

            // Create Pdf Instance
            Aspose.Pdf.Generator.Pdf pdf = new Aspose.Pdf.Generator.Pdf();
            // Create section object and add it to pdf object
            Aspose.Pdf.Generator.Section sec1 = pdf.Sections.Add();

            // Create a table instance
            Aspose.Pdf.Generator.Table mytable = new Aspose.Pdf.Generator.Table();
            // Specify the default border for table object and set its color as Navy
            mytable.DefaultCellBorder = new Aspose.Pdf.Generator.BorderInfo((int)Aspose.Pdf.Generator.BorderSide.All, 1f, new Aspose.Pdf.Generator.Color("Navy"));
            // Specify the border information for table object
            mytable.Border = new Aspose.Pdf.Generator.BorderInfo((int)Aspose.Pdf.Generator.BorderSide.All, 1f, new Aspose.Pdf.Generator.Color("Navy"));
            // Define initial width information for table cells
            mytable.ColumnWidths = "100 100";
            // Create a row object and add it to table
            Aspose.Pdf.Generator.Row row1 = mytable.Rows.Add();
            // Create loop to add specify the number of columns to be added to table row
            for (int Column_Counter = 1; Column_Counter <= 7; Column_Counter++)
            {
                // Create a cell object and add it to table row
                Aspose.Pdf.Generator.Cell Cell = row1.Cells.Add("Cell (1," + Column_Counter.ToString() + ")");
            }
            // Define the variable to keep record of number of columns in table
            int TableColumn = 0;

            // Traverse through each table cell in row object
            foreach (Aspose.Pdf.Generator.Cell InnerCell in row1.Cells)
            {
                // Specify the width information for each column based on section objects margin and width values
                // Set the width value as, get the total width of section and subtract left and right margin and divide
                // It with total number of cells in a particular table row
                mytable.SetColumnWidth(TableColumn, (sec1.PageInfo.PageWidth - sec1.PageInfo.Margin.Left - sec1.PageInfo.Margin.Right) / row1.Cells.Count);
                // Increase the value of variable holding the column count information
                TableColumn += 1;
            }

            // Add table to paragraphs collection of section
            sec1.Paragraphs.Add(mytable);
            // Save the resultant PDF document
            pdf.Save(dataDir + "SetTableColumnsWidth_out.pdf");
            // ExEnd:SetTableColumnsWidth
        }
        public static void Run()
        {
            // ExStart:SetTableColumnsWidth
            // The path to the documents directory.
            string dataDir = RunExamples.GetDataDir_AsposePdfGenerator_TechnicalArticles();

            // Create Pdf Instance
            Aspose.Pdf.Generator.Pdf pdf = new Aspose.Pdf.Generator.Pdf();
            // Create section object and add it to pdf object
            Aspose.Pdf.Generator.Section sec1 = pdf.Sections.Add();

            // Create a table instance
            Aspose.Pdf.Generator.Table mytable = new Aspose.Pdf.Generator.Table();
            // Specify the default border for table object and set its color as Navy
            mytable.DefaultCellBorder = new Aspose.Pdf.Generator.BorderInfo((int)Aspose.Pdf.Generator.BorderSide.All, 1f, new Aspose.Pdf.Generator.Color("Navy"));
            // Specify the border information for table object
            mytable.Border = new Aspose.Pdf.Generator.BorderInfo((int)Aspose.Pdf.Generator.BorderSide.All, 1f, new Aspose.Pdf.Generator.Color("Navy"));
            // Define initial width information for table cells
            mytable.ColumnWidths = "100 100";
            // Create a row object and add it to table 
             Aspose.Pdf.Generator.Row row1 = mytable.Rows.Add();
            // Create loop to add specify the number of columns to be added to table row
            for (int Column_Counter = 1; Column_Counter <= 7; Column_Counter++)
            {
                // Create a cell object and add it to table row
                 Aspose.Pdf.Generator.Cell Cell = row1.Cells.Add("Cell (1," + Column_Counter.ToString() + ")");
            }
            // Define the variable to keep record of number of columns in table
            int TableColumn = 0;
            // Traverse through each table cell in row object
            foreach (Aspose.Pdf.Generator.Cell InnerCell in row1.Cells)
            {
                // Specify the width information for each column based on section objects margin and width values
                // Set the width value as, get the total width of section and subtract left and right margin and divide
                // It with total number of cells in a particular table row
                mytable.SetColumnWidth(TableColumn, (sec1.PageInfo.PageWidth - sec1.PageInfo.Margin.Left - sec1.PageInfo.Margin.Right) / row1.Cells.Count);
                // Increase the value of variable holding the column count information
                TableColumn += 1;
            }

            // Add table to paragraphs collection of section
            sec1.Paragraphs.Add(mytable);
            // Save the resultant PDF document
            pdf.Save(dataDir + "SetTableColumnsWidth_out.pdf");
            // ExEnd:SetTableColumnsWidth           
        }
        public static void Run()
        {
            // ExStart:TableMinimumColumnWidth
            // The path to the documents directory.
            string dataDir = RunExamples.GetDataDir_AsposePdfGenerator_AdvanceFeatures();

            // Instantiate Pdf instance by calling its empty constructor
            Aspose.Pdf.Generator.Pdf pdf1 = new Aspose.Pdf.Generator.Pdf();

            // Add a section in the Pdf
            Aspose.Pdf.Generator.Section sec1 = pdf1.Sections.Add();

            // Create a table object and add it to the paragraphs collection of the section
            Aspose.Pdf.Generator.Table tab1 = new Aspose.Pdf.Generator.Table();
            sec1.Paragraphs.Add(tab1);

            // Set the column widths and default cell border of the table
            tab1.ColumnWidths      = "60 100 100";
            tab1.DefaultCellBorder = new Aspose.Pdf.Generator.BorderInfo((int)Aspose.Pdf.Generator.BorderSide.All, 1F);

            // Prepare an array of string values to be added to table
            string[] darr = new string[]
            { "Owner/Marketing Assistant", "dhasf hh ddt", "dhaosdha djsd dsads",
              "dsd dajd", "hdsah jj jj jdj", "ddfa jjj jhdusa" };

            // Import the contents of the array created in above step
            tab1.ImportArray(darr, 0, 0, true);

            // Call GetMinColumnWidth and pass the column number whose minimum width is needed
            float width = tab1.GetMinColumnWidth(pdf1, 0);

            // Call SetColumnWidth and pass the column number with minimum width
            tab1.SetColumnWidth(0, width);

            dataDir = dataDir + "TableMinimumColumnWidth_out.pdf";
            // Save the Pdf
            pdf1.Save(dataDir);
            // ExEnd:TableMinimumColumnWidth
        }
        public static void Run()
        {
            // ExStart:TableMinimumColumnWidth
            // The path to the documents directory.
            string dataDir = RunExamples.GetDataDir_AsposePdfGenerator_AdvanceFeatures();

            // Instantiate Pdf instance by calling its empty constructor
            Aspose.Pdf.Generator.Pdf pdf1 = new Aspose.Pdf.Generator.Pdf();

            // Add a section in the Pdf
            Aspose.Pdf.Generator.Section sec1 = pdf1.Sections.Add();

            // Create a table object and add it to the paragraphs collection of the section        
            Aspose.Pdf.Generator.Table tab1 = new Aspose.Pdf.Generator.Table();
            sec1.Paragraphs.Add(tab1);

            // Set the column widths and default cell border of the table
            tab1.ColumnWidths = "60 100 100";
            tab1.DefaultCellBorder = new Aspose.Pdf.Generator.BorderInfo((int)Aspose.Pdf.Generator.BorderSide.All, 1F);

            // Prepare an array of string values to be added to table
            string[] darr = new string[]
        {"Owner/Marketing Assistant","dhasf hh ddt", "dhaosdha djsd dsads",
                "dsd dajd", "hdsah jj jj jdj", "ddfa jjj jhdusa"};

            // Import the contents of the array created in above step
            tab1.ImportArray(darr, 0, 0, true);

            // Call GetMinColumnWidth and pass the column number whose minimum width is needed
            float width = tab1.GetMinColumnWidth(pdf1, 0);

            // Call SetColumnWidth and pass the column number with minimum width
            tab1.SetColumnWidth(0, width);                                

            dataDir = dataDir + "TableMinimumColumnWidth_out.pdf";
            // Save the Pdf
            pdf1.Save(dataDir);
            // ExEnd:TableMinimumColumnWidth           
        }