예제 #1
0
        public static void Run()
        {
            // ExStart:SetBorder
            // The path to the documents directory.
            string dataDir = RunExamples.GetDataDir_AsposePdf_Tables();

            // Instantiate Document object
            Document doc = new Document();
            // Add page to PDF document
            Page page = doc.Pages.Add();

            // Create BorderInfo object
            Aspose.Pdf.BorderInfo border = new Aspose.Pdf.BorderInfo(Aspose.Pdf.BorderSide.All);
            // Specify that Top border will be double
            border.Top.IsDoubled = true;
            // Specify that bottom border will be double
            border.Bottom.IsDoubled = true;
            // Instantiate Table object
            Aspose.Pdf.Table table = new Aspose.Pdf.Table();
            // Specify Columns width information
            table.ColumnWidths = "100";
            // Create Row object
            Aspose.Pdf.Row row = table.Rows.Add();
            // Add a Table cell to cells collection of row
            Aspose.Pdf.Cell cell = row.Cells.Add("some text");
            // Set the border for cell object (double border)
            cell.Border = border;
            // Add table to paragraphs collection of Page
            page.Paragraphs.Add(table);
            dataDir = dataDir + "TableBorderTest_out_.pdf";
            // Save the PDF document
            doc.Save(dataDir);
            // ExEnd:SetBorder
            Console.WriteLine("\nBorder setup successfully.\nFile saved at " + dataDir);
        }
예제 #2
0
        public static void Run()
        {
            // ExStart:AddTable
            // The path to the documents directory.
            string dataDir = RunExamples.GetDataDir_AsposePdf_Tables();

            // Load source PDF document
            Aspose.Pdf.Document doc = new Aspose.Pdf.Document(dataDir + "AddTable.pdf");
            // Initializes a new instance of the Table
            Aspose.Pdf.Table table = new Aspose.Pdf.Table();
            // Set the table border color as LightGray
            table.Border = new Aspose.Pdf.BorderInfo(Aspose.Pdf.BorderSide.All, .5f, Aspose.Pdf.Color.FromRgb(System.Drawing.Color.LightGray));
            // Set the border for table cells
            table.DefaultCellBorder = new Aspose.Pdf.BorderInfo(Aspose.Pdf.BorderSide.All, .5f, Aspose.Pdf.Color.FromRgb(System.Drawing.Color.LightGray));
            // Create a loop to add 10 rows
            for (int row_count = 1; row_count < 10; row_count++)
            {
                // Add row to table
                Aspose.Pdf.Row row = table.Rows.Add();
                // Add table cells
                row.Cells.Add("Column (" + row_count + ", 1)");
                row.Cells.Add("Column (" + row_count + ", 2)");
                row.Cells.Add("Column (" + row_count + ", 3)");
            }
            // Add table object to first page of input document
            doc.Pages[1].Paragraphs.Add(table);
            dataDir = dataDir + "document_with_table_out.pdf";
            // Save updated document containing table object
            doc.Save(dataDir);
            // ExEnd:AddTable
            Console.WriteLine("\nText added successfully to an existing pdf file.\nFile saved at " + dataDir);
        }
예제 #3
0
        public static void Main(string[] args)
        {
            // The path to the documents directory.
            string dataDir = Path.GetFullPath("../../../Data/");

            // Load source PDF document
            Aspose.Pdf.Document doc = new Aspose.Pdf.Document(dataDir + "input.pdf");
            // Initializes a new instance of the Table
            Aspose.Pdf.Table table = new Aspose.Pdf.Table();
            // Set the table border color as LightGray
            table.Border = new Aspose.Pdf.BorderInfo(Aspose.Pdf.BorderSide.All, .5f, Aspose.Pdf.Color.FromRgb(System.Drawing.Color.LightGray));
            // set the border for table cells
            table.DefaultCellBorder = new Aspose.Pdf.BorderInfo(Aspose.Pdf.BorderSide.All, .5f, Aspose.Pdf.Color.FromRgb(System.Drawing.Color.LightGray));
            // create a loop to add 10 rows
            for (int row_count = 1; row_count < 10; row_count++)
            {
                // add row to table
                Aspose.Pdf.Row row = table.Rows.Add();
                // add table cells
                row.Cells.Add("Column (" + row_count + ", 1)");
                row.Cells.Add("Column (" + row_count + ", 2)");
                row.Cells.Add("Column (" + row_count + ", 3)");
            }
            // Add table object to first page of input document
            doc.Pages[1].Paragraphs.Add(table);
            // Save updated document containing table object
            doc.Save(dataDir + "document_with_table.pdf");
        }
예제 #4
0
        public static void Main(string[] args)
        {
            // The path to the documents directory.
            string dataDir = Path.GetFullPath("../../../Data/");

            // Create directory if it is not already present.
            bool IsExists = System.IO.Directory.Exists(dataDir);

            if (!IsExists)
            {
                System.IO.Directory.CreateDirectory(dataDir);
            }


            Document doc      = new Document();
            PageInfo pageInfo = doc.PageInfo;

            Aspose.Pdf.MarginInfo marginInfo = pageInfo.Margin;

            marginInfo.Left   = 37;
            marginInfo.Right  = 37;
            marginInfo.Top    = 37;
            marginInfo.Bottom = 37;

            pageInfo.IsLandscape = true;

            Aspose.Pdf.Table table = new Aspose.Pdf.Table();
            table.ColumnWidths = "50 100";
            // Added page.
            Page curPage = doc.Pages.Add();

            for (int i = 1; i <= 120; i++)
            {
                Aspose.Pdf.Row row = table.Rows.Add();
                row.FixedRowHeight = 15;
                Aspose.Pdf.Cell cell1 = row.Cells.Add();
                cell1.Paragraphs.Add(new TextFragment("Content 1"));
                Aspose.Pdf.Cell cell2 = row.Cells.Add();
                cell2.Paragraphs.Add(new TextFragment("HHHHH"));
            }
            Aspose.Pdf.Paragraphs paragraphs = curPage.Paragraphs;
            paragraphs.Add(table);
            /********************************************/
            Aspose.Pdf.Table table1 = new Aspose.Pdf.Table();
            table.ColumnWidths = "100 100";
            for (int i = 1; i <= 10; i++)
            {
                Aspose.Pdf.Row  row   = table1.Rows.Add();
                Aspose.Pdf.Cell cell1 = row.Cells.Add();
                cell1.Paragraphs.Add(new TextFragment("LAAAAAAA"));
                Aspose.Pdf.Cell cell2 = row.Cells.Add();
                cell2.Paragraphs.Add(new TextFragment("LAAGGGGGG"));
            }
            table1.IsInNewPage = true;
            // I want to keep table 1 to next page please...
            paragraphs.Add(table1);

            doc.Save(dataDir + "IsNewPageProperty_Test.pdf");
        }
예제 #5
0
        public static void Main(string[] args)
        {
            // The path to the documents directory.
            string dataDir = Path.GetFullPath("../../../Data/");

            // Create directory if it is not already present.
            bool IsExists = System.IO.Directory.Exists(dataDir);

            if (!IsExists)
            {
                System.IO.Directory.CreateDirectory(dataDir);
            }


            //Instntiate the Document object by calling its empty constructor
            Document doc  = new Document();
            Page     page = doc.Pages.Add();

            //Instantiate a table object
            Aspose.Pdf.Table tab1 = new Aspose.Pdf.Table();
            //Add the table in paragraphs collection of the desired section
            page.Paragraphs.Add(tab1);
            //Set with column widths of the table
            tab1.ColumnWidths = "50 50 50";
            //Set default cell border using BorderInfo object
            tab1.DefaultCellBorder = new Aspose.Pdf.BorderInfo(Aspose.Pdf.BorderSide.All, 0.1F);
            //Set table border using another customized BorderInfo object
            tab1.Border = new Aspose.Pdf.BorderInfo(Aspose.Pdf.BorderSide.All, 1F);
            //Create MarginInfo object and set its left, bottom, right and top margins
            Aspose.Pdf.MarginInfo margin = new Aspose.Pdf.MarginInfo();
            margin.Top    = 5f;
            margin.Left   = 5f;
            margin.Right  = 5f;
            margin.Bottom = 5f;
            //Set the default cell padding to the MarginInfo object
            tab1.DefaultCellPadding = margin;
            //Create rows in the table and then cells in the rows
            Aspose.Pdf.Row row1 = tab1.Rows.Add();
            row1.Cells.Add("col1");
            row1.Cells.Add("col2");
            row1.Cells.Add();
            TextFragment mytext = new TextFragment("col3 with large text string");

            //row1.Cells.Add("col3 with large text string to be placed inside cell");
            row1.Cells[2].Paragraphs.Add(mytext);
            row1.Cells[2].IsWordWrapped = false;
            //row1.Cells[2].Paragraphs[0].FixedWidth= 80;
            Aspose.Pdf.Row row2 = tab1.Rows.Add();
            row2.Cells.Add("item1");
            row2.Cells.Add("item2");
            row2.Cells.Add("item3");
            //Save the Pdf
            doc.Save(dataDir + "output.pdf");
        }
예제 #6
0
        public static void Run()
        {
            // ExStart:RenderTable
            // The path to the documents directory.
            string dataDir = RunExamples.GetDataDir_AsposePdf_Tables();

            Document doc      = new Document();
            PageInfo pageInfo = doc.PageInfo;

            Aspose.Pdf.MarginInfo marginInfo = pageInfo.Margin;

            marginInfo.Left   = 37;
            marginInfo.Right  = 37;
            marginInfo.Top    = 37;
            marginInfo.Bottom = 37;

            pageInfo.IsLandscape = true;

            Aspose.Pdf.Table table = new Aspose.Pdf.Table();
            table.ColumnWidths = "50 100";
            // Added page.
            Page curPage = doc.Pages.Add();

            for (int i = 1; i <= 120; i++)
            {
                Aspose.Pdf.Row row = table.Rows.Add();
                row.FixedRowHeight = 15;
                Aspose.Pdf.Cell cell1 = row.Cells.Add();
                cell1.Paragraphs.Add(new TextFragment("Content 1"));
                Aspose.Pdf.Cell cell2 = row.Cells.Add();
                cell2.Paragraphs.Add(new TextFragment("HHHHH"));
            }
            Aspose.Pdf.Paragraphs paragraphs = curPage.Paragraphs;
            paragraphs.Add(table);
            /********************************************/
            Aspose.Pdf.Table table1 = new Aspose.Pdf.Table();
            table.ColumnWidths = "100 100";
            for (int i = 1; i <= 10; i++)
            {
                Aspose.Pdf.Row  row   = table1.Rows.Add();
                Aspose.Pdf.Cell cell1 = row.Cells.Add();
                cell1.Paragraphs.Add(new TextFragment("LAAAAAAA"));
                Aspose.Pdf.Cell cell2 = row.Cells.Add();
                cell2.Paragraphs.Add(new TextFragment("LAAGGGGGG"));
            }
            table1.IsInNewPage = true;
            // I want to keep table 1 to next page please...
            paragraphs.Add(table1);
            dataDir = dataDir + "IsNewPageProperty_Test_out.pdf";
            doc.Save(dataDir);
            // ExEnd:RenderTable
            Console.WriteLine("\nTable render successfully on a page.\nFile saved at " + dataDir);
        }
        public static void Run()
        {
            // ExStart:AutoFitToWindow
            // The path to the documents directory.
            string dataDir = RunExamples.GetDataDir_AsposePdf_Tables();

            // Instntiate the Pdf object by calling its empty constructor
            Document doc = new Document();
            // Create the section in the Pdf object
            Page sec1 = doc.Pages.Add();

            // Instantiate a table object
            Aspose.Pdf.Table tab1 = new Aspose.Pdf.Table();
            // Add the table in paragraphs collection of the desired section
            sec1.Paragraphs.Add(tab1);

            // Set with column widths of the table
            tab1.ColumnWidths     = "50 50 50";
            tab1.ColumnAdjustment = ColumnAdjustment.AutoFitToWindow;

            // Set default cell border using BorderInfo object
            tab1.DefaultCellBorder = new Aspose.Pdf.BorderInfo(Aspose.Pdf.BorderSide.All, 0.1F);

            // Set table border using another customized BorderInfo object
            tab1.Border = new Aspose.Pdf.BorderInfo(Aspose.Pdf.BorderSide.All, 1F);
            // Create MarginInfo object and set its left, bottom, right and top margins
            Aspose.Pdf.MarginInfo margin = new Aspose.Pdf.MarginInfo();
            margin.Top    = 5f;
            margin.Left   = 5f;
            margin.Right  = 5f;
            margin.Bottom = 5f;

            // Set the default cell padding to the MarginInfo object
            tab1.DefaultCellPadding = margin;

            // Create rows in the table and then cells in the rows
            Aspose.Pdf.Row row1 = tab1.Rows.Add();
            row1.Cells.Add("col1");
            row1.Cells.Add("col2");
            row1.Cells.Add("col3");
            Aspose.Pdf.Row row2 = tab1.Rows.Add();
            row2.Cells.Add("item1");
            row2.Cells.Add("item2");
            row2.Cells.Add("item3");

            dataDir = dataDir + "AutoFitToWindow_out.pdf";
            // Save updated document containing table object
            doc.Save(dataDir);
            // ExEnd:AutoFitToWindow
        }
예제 #8
0
        public static void Run()
        {
            // ExStart:MarginsOrPadding
            // The path to the documents directory.
            string dataDir = RunExamples.GetDataDir_AsposePdf_Tables();

            // Instntiate the Document object by calling its empty constructor
            Document doc  = new Document();
            Page     page = doc.Pages.Add();

            // Instantiate a table object
            Aspose.Pdf.Table tab1 = new Aspose.Pdf.Table();
            // Add the table in paragraphs collection of the desired section
            page.Paragraphs.Add(tab1);
            // Set with column widths of the table
            tab1.ColumnWidths = "50 50 50";
            // Set default cell border using BorderInfo object
            tab1.DefaultCellBorder = new Aspose.Pdf.BorderInfo(Aspose.Pdf.BorderSide.All, 0.1F);
            // Set table border using another customized BorderInfo object
            tab1.Border = new Aspose.Pdf.BorderInfo(Aspose.Pdf.BorderSide.All, 1F);
            // Create MarginInfo object and set its left, bottom, right and top margins
            Aspose.Pdf.MarginInfo margin = new Aspose.Pdf.MarginInfo();
            margin.Top    = 5f;
            margin.Left   = 5f;
            margin.Right  = 5f;
            margin.Bottom = 5f;
            // Set the default cell padding to the MarginInfo object
            tab1.DefaultCellPadding = margin;
            // Create rows in the table and then cells in the rows
            Aspose.Pdf.Row row1 = tab1.Rows.Add();
            row1.Cells.Add("col1");
            row1.Cells.Add("col2");
            row1.Cells.Add();
            TextFragment mytext = new TextFragment("col3 with large text string");

            // Row1.Cells.Add("col3 with large text string to be placed inside cell");
            row1.Cells[2].Paragraphs.Add(mytext);
            row1.Cells[2].IsWordWrapped = false;
            // Row1.Cells[2].Paragraphs[0].FixedWidth= 80;
            Aspose.Pdf.Row row2 = tab1.Rows.Add();
            row2.Cells.Add("item1");
            row2.Cells.Add("item2");
            row2.Cells.Add("item3");
            dataDir = dataDir + "MarginsOrPadding_out_.pdf";
            // Save the Pdf
            doc.Save(dataDir);
            // ExEnd:MarginsOrPadding
            Console.WriteLine("\nCell and table border width setup successfully.\nFile saved at " + dataDir);
        }
예제 #9
0
        public static void Run()
        {
            // ExStart:AddSVGObject
            // The path to the documents directory.
            string dataDir = RunExamples.GetDataDir_AsposePdf_Tables();

            // Instantiate Document object
            Document doc = new Document();

            // Create an image instance
            Aspose.Pdf.Image img = new Aspose.Pdf.Image();
            // Set image type as SVG
            img.FileType = Aspose.Pdf.ImageFileType.Svg;
            // Path for source file
            img.File = dataDir + "SVGToPDF.svg";
            // Set width for image instance
            img.FixWidth = 50;
            // Set height for image instance
            img.FixHeight = 50;
            // Create table instance
            Aspose.Pdf.Table table = new Aspose.Pdf.Table();
            // Set width for table cells
            table.ColumnWidths = "100 100";
            // Create row object and add it to table instance
            Aspose.Pdf.Row row = table.Rows.Add();
            // Create cell object and add it to row instance
            Aspose.Pdf.Cell cell = row.Cells.Add();
            // Add textfragment to paragraphs collection of cell object
            cell.Paragraphs.Add(new TextFragment("First cell"));
            // Add another cell to row object
            cell = row.Cells.Add();
            // Add SVG image to paragraphs collection of recently added cell instance
            cell.Paragraphs.Add(img);
            // Create page object and add it to pages collection of document instance
            Page page = doc.Pages.Add();

            // Add table to paragraphs collection of page object
            page.Paragraphs.Add(table);

            dataDir = dataDir + "AddSVGObject_out_.pdf";
            // Save PDF file
            doc.Save(dataDir);
            // ExEnd:AddSVGObject
            Console.WriteLine("\nSVG image added successfully inside a table cell.\nFile saved at " + dataDir);
        }
예제 #10
0
        public static void Run()
        {
            // ExStart:InsertPageBreak
            // The path to the documents directory.
            string dataDir = RunExamples.GetDataDir_AsposePdf_Tables();

            // Instantiate Document instance
            Document doc = new Document();

            // Add page to pages collection of PDF file
            doc.Pages.Add();
            // Create table instance
            Aspose.Pdf.Table tab = new Aspose.Pdf.Table();
            // Set border style for table
            tab.Border = new Aspose.Pdf.BorderInfo(Aspose.Pdf.BorderSide.All, Aspose.Pdf.Color.Red);
            // Set default border style for table with border color as Red
            tab.DefaultCellBorder = new Aspose.Pdf.BorderInfo(Aspose.Pdf.BorderSide.All, Aspose.Pdf.Color.Red);
            // Specify table columsn widht
            tab.ColumnWidths = "100 100";
            // Create a loop to add 200 rows for table
            for (int counter = 0; counter <= 200; counter++)
            {
                Aspose.Pdf.Row row = new Aspose.Pdf.Row();
                tab.Rows.Add(row);
                Aspose.Pdf.Cell cell1 = new Aspose.Pdf.Cell();
                cell1.Paragraphs.Add(new TextFragment("Cell " + counter + ", 0"));
                row.Cells.Add(cell1); Aspose.Pdf.Cell cell2 = new Aspose.Pdf.Cell();
                cell2.Paragraphs.Add(new TextFragment("Cell " + counter + ", 1"));
                row.Cells.Add(cell2);
                // When 10 rows are added, render new row in new page
                if (counter % 10 == 0 && counter != 0)
                {
                    row.IsInNewPage = true;
                }
            }
            // Add table to paragraphs collection of PDF file
            doc.Pages[1].Paragraphs.Add(tab);

            dataDir = dataDir + "InsertPageBreak_out_.pdf";
            // Save the PDF document
            doc.Save(dataDir);
            // ExEnd:InsertPageBreak
            Console.WriteLine("\nPage break inserted successfully.\nFile saved at " + dataDir);
        }
        public static void Run()
        {
            // ExStart:InsertPageBreak
            // The path to the documents directory.
            string dataDir = RunExamples.GetDataDir_AsposePdf_Tables();

            // Instantiate Document instance
            Document doc = new Document();
            // Add page to pages collection of PDF file
            doc.Pages.Add();
            // Create table instance
            Aspose.Pdf.Table tab = new Aspose.Pdf.Table();
            // Set border style for table
            tab.Border = new Aspose.Pdf.BorderInfo(Aspose.Pdf.BorderSide.All, Aspose.Pdf.Color.Red);
            // Set default border style for table with border color as Red
            tab.DefaultCellBorder = new Aspose.Pdf.BorderInfo(Aspose.Pdf.BorderSide.All, Aspose.Pdf.Color.Red);
            // Specify table columsn widht
            tab.ColumnWidths = "100 100";
            // Create a loop to add 200 rows for table
            for (int counter = 0; counter <= 200; counter++)
            {
                Aspose.Pdf.Row row = new Aspose.Pdf.Row();
                tab.Rows.Add(row);
                Aspose.Pdf.Cell cell1 = new Aspose.Pdf.Cell();
                cell1.Paragraphs.Add(new TextFragment("Cell " + counter + ", 0"));
                row.Cells.Add(cell1); Aspose.Pdf.Cell cell2 = new Aspose.Pdf.Cell();
                cell2.Paragraphs.Add(new TextFragment("Cell " + counter + ", 1"));
                row.Cells.Add(cell2);
                // When 10 rows are added, render new row in new page
                if (counter % 10 == 0 && counter != 0) row.IsInNewPage = true;
            }
            // Add table to paragraphs collection of PDF file
            doc.Pages[1].Paragraphs.Add(tab);

            dataDir = dataDir + "InsertPageBreak_out.pdf";
            // Save the PDF document
            doc.Save(dataDir);
            // ExEnd:InsertPageBreak
            Console.WriteLine("\nPage break inserted successfully.\nFile saved at " + dataDir);
            
        }
예제 #12
0
        public static void Main(string[] args)
        {
            // The path to the documents directory.
            string dataDir = Path.GetFullPath("../../../Data/");
            // Create directory if it is not already present.
            bool IsExists = System.IO.Directory.Exists(dataDir);

            if (!IsExists)
            {
                System.IO.Directory.CreateDirectory(dataDir);
            }


            // instantiate Document object
            Document doc = new Document();
            // add page to PDF document
            Page page = doc.Pages.Add();

            // create BorderInfo object
            Aspose.Pdf.BorderInfo border = new Aspose.Pdf.BorderInfo(Aspose.Pdf.BorderSide.All);
            // specify that Top border will be double
            border.Top.IsDoubled = true;
            // specify that bottom border will be double
            border.Bottom.IsDoubled = true;
            // instantiate Table object
            Aspose.Pdf.Table table = new Aspose.Pdf.Table();
            // specify Columns width information
            table.ColumnWidths = "100";
            // create Row object
            Aspose.Pdf.Row row = table.Rows.Add();
            // add a Table cell to cells collection of row
            Aspose.Pdf.Cell cell = row.Cells.Add("some text");
            // set the border for cell object (double border)
            cell.Border = border;
            // add table to paragraphs collection of Page
            page.Paragraphs.Add(table);
            // save the PDF document
            doc.Save(dataDir + "TableBorderTest.pdf");
        }
예제 #13
0
        public static void Run()
        {
            // ExStart:DetermineTableBreak
            // The path to the documents directory.
            string dataDir = RunExamples.GetDataDir_AsposePdf_Tables();

            // Instantiate an object PDF class
            Document pdf = new Document();

            // Add the section to PDF document sections collection
            Aspose.Pdf.Page page = pdf.Pages.Add();
            // Instantiate a table object
            Aspose.Pdf.Table table1 = new Aspose.Pdf.Table();
            table1.Margin.Top = 300;
            // Add the table in paragraphs collection of the desired section
            page.Paragraphs.Add(table1);
            // Set with column widths of the table
            table1.ColumnWidths = "100 100 100";
            // Set default cell border using BorderInfo object
            table1.DefaultCellBorder = new Aspose.Pdf.BorderInfo(Aspose.Pdf.BorderSide.All, 0.1F);
            // Set table border using another customized BorderInfo object
            table1.Border = new Aspose.Pdf.BorderInfo(Aspose.Pdf.BorderSide.All, 1F);
            // Create MarginInfo object and set its left, bottom, right and top margins
            Aspose.Pdf.MarginInfo margin = new Aspose.Pdf.MarginInfo();
            margin.Top    = 5f;
            margin.Left   = 5f;
            margin.Right  = 5f;
            margin.Bottom = 5f;
            // Set the default cell padding to the MarginInfo object
            table1.DefaultCellPadding = margin;
            // If you increase the counter to 17, table will break
            // Because it cannot be accommodated any more over this page
            for (int RowCounter = 0; RowCounter <= 16; RowCounter++)
            {
                // Create rows in the table and then cells in the rows
                Aspose.Pdf.Row row1 = table1.Rows.Add();
                row1.Cells.Add("col " + RowCounter.ToString() + ", 1");
                row1.Cells.Add("col " + RowCounter.ToString() + ", 2");
                row1.Cells.Add("col " + RowCounter.ToString() + ", 3");
            }
            // Get the Page Height information
            float PageHeight = (float)pdf.PageInfo.Height;
            // Get the total height information of Page Top & Bottom margin,
            // Table Top margin and table height.
            float TotalObjectsHeight = (float)page.PageInfo.Margin.Top + (float)page.PageInfo.Margin.Bottom + (float)table1.Margin.Top + (float)table1.GetHeight();

            // Display Page Height, Table Height, table Top margin and Page Top
            // And Bottom margin information
            Console.WriteLine("PDF document Height = " + pdf.PageInfo.Height.ToString() + "\nTop Margin Info = " + page.PageInfo.Margin.Top.ToString() + "\nBottom Margin Info = " + page.PageInfo.Margin.Bottom.ToString() + "\n\nTable-Top Margin Info = " + table1.Margin.Top.ToString() + "\nAverage Row Height = " + table1.Rows[0].MinRowHeight.ToString() + " \nTable height " + table1.GetHeight().ToString() + "\n ----------------------------------------" + "\nTotal Page Height =" + PageHeight.ToString() + "\nCummulative height including Table =" + TotalObjectsHeight.ToString());

            // Check if we deduct the sume of Page top margin + Page Bottom margin
            // + Table Top margin and table height from Page height and its less
            // Than 10 (an average row can be greater than 10)
            if ((PageHeight - TotalObjectsHeight) <= 10)
            {
                // If the value is less than 10, then display the message.
                // Which shows that another row can not be placed and if we add new
                // Row, table will break. It depends upon the row height value.
                Console.WriteLine("Page Height - Objects Height < 10, so table will break");
            }


            dataDir = dataDir + "DetermineTableBreak_out.pdf";
            // Save the pdf document
            pdf.Save(dataDir);
            // ExEnd:DetermineTableBreak
            Console.WriteLine("\nTable break determined successfully.\nFile saved at " + dataDir);
        }
예제 #14
0
        protected void btnSave_Click(object sender, EventArgs e)
        {
            try
            {

                //Creating new document
                Document doc = new Document();
                //add a new page in the document...
                Aspose.Pdf.Page page = doc.Pages.Add();

                //add header and footer in the document
                AddHeaderFooter(doc, "Online Application Form - Dated: " + DateTime.Now.Date.ToString("MM-dd-yyyy"), "");

                //crearing new table
                Aspose.Pdf.Table table = new Aspose.Pdf.Table();
                page.Paragraphs.Add(table);
                table.Alignment = Aspose.Pdf.HorizontalAlignment.Center;
                table.DefaultColumnWidth = "500";
                //create a new row in the table...
                Aspose.Pdf.Row row = new Aspose.Pdf.Row();
                table.Rows.Add(row);
                //create a new cell in the row...
                Aspose.Pdf.Cell cell = new Aspose.Pdf.Cell();
                row.Cells.Add(cell);

                cell.Alignment = Aspose.Pdf.HorizontalAlignment.Center;

                //create main heading of the page
                TextFragment txtFragmanet = new TextFragment("Online Application Form");

                txtFragmanet.TextState.FontSize = 15;
                txtFragmanet.TextState.FontStyle = FontStyles.Bold;
                cell.Paragraphs.Add(txtFragmanet);

                //============================ Section of personal information Starts======================
                // Add a new heading ...
                AddHeading(page, "Applied for Position: " + txtPosition.Text, 8, false);

                // Add a new heading ...
                AddHeading(page, "Personal Information:", 10, true);

                // create table for personal information
                Aspose.Pdf.Table tblPersonalInfo = new Aspose.Pdf.Table();
                page.Paragraphs.Add(tblPersonalInfo);
                tblPersonalInfo.DefaultCellTextState.FontSize = 6;
                //set columns width...
                tblPersonalInfo.ColumnWidths = "100 400";

                //adding personal details ...
                AddRow(tblPersonalInfo, "Name:", txtName.Text);
                AddRow(tblPersonalInfo, "Date of Birth:", txtDOB.Text);
                AddRow(tblPersonalInfo, "Email:", txtEmail.Text);
                AddRow(tblPersonalInfo, "Phone:", txtPhone.Text);
                AddRow(tblPersonalInfo, "Address:", txtAddress.Text);
                foreach (Aspose.Pdf.Row rw in tblPersonalInfo.Rows)
                {
                    rw.MinRowHeight = 20;
                }
                //=========================== End of Personal Information Section ================================================
                //=========================== Skills Starts ===============================================================
                //add new heading...
                AddHeading(page, "Skills:", 10, true);
                // add text fragment...
                TextFragment txtFragSkills = new TextFragment();
                txtFragSkills.TextState.Font = FontRepository.FindFont("Calibri");
                txtFragSkills.TextState.FontSize = 8;
                txtFragSkills.Text = txtSkills.Text;
                txtFragSkills.TextState.LineSpacing = 5;
                //add text fragment in pagae paragraph...
                page.Paragraphs.Add(txtFragSkills);

                //=========================== End of Objective Statement Section ====================================================
                //============================ Section of Educational information Starts======================
                // Add a new heading ...
                AddHeading(page, "Educational Details:", 10, true);

                //create datatable...
                DataTable dtEducationalDetails = new DataTable();
                dtEducationalDetails.Columns.Add("Degree", typeof(string));
                dtEducationalDetails.Columns.Add("Total Marks/GPA", typeof(string));
                dtEducationalDetails.Columns.Add("Obtained Marks/CGPA", typeof(string));
                dtEducationalDetails.Columns.Add("Institute", typeof(string));

                //get data from the gridview and store in datatable...
                foreach (GridViewRow grow in gvEducationalDetails.Rows)
                {

                    TextBox txtDegree = grow.FindControl("txtDegree") as TextBox;
                    TextBox txtTotalMarks = grow.FindControl("txtTotalMarks") as TextBox;
                    TextBox txtObtainedMarks = grow.FindControl("txtObtainedMarks") as TextBox;
                    TextBox txtInstitute = grow.FindControl("txtInstitute") as TextBox;
                    if (txtDegree.Text.Trim() != "" && txtTotalMarks.Text.Trim() != "" && txtObtainedMarks.Text.Trim() != "" && txtInstitute.Text.Trim() != "")
                    {
                        DataRow drow = dtEducationalDetails.NewRow();
                        drow[0] = txtDegree.Text;
                        drow[1] = txtTotalMarks.Text;
                        drow[2] = txtObtainedMarks.Text;
                        drow[3] = txtInstitute.Text;
                        dtEducationalDetails.Rows.Add(drow);
                    }
                }

                //create table for personal information
                Aspose.Pdf.Table tblEducationalInfo = new Aspose.Pdf.Table();

                tblEducationalInfo.ColumnWidths = "100 100 100 100";
                //add table to the dataset
                DataSet ds = new DataSet();
                ds.Tables.Add(dtEducationalDetails);

                tblEducationalInfo.DefaultCellTextState.FontSize = 8;
                tblEducationalInfo.DefaultCellTextState.Font = FontRepository.FindFont("Calibri");

                //Set the border style of the table...
                tblEducationalInfo.Border = new Aspose.Pdf.BorderInfo(Aspose.Pdf.BorderSide.All, .5f, Aspose.Pdf.Color.FromRgb(System.Drawing.Color.Black));
                // Set default cell border...
                tblEducationalInfo.DefaultCellBorder = new Aspose.Pdf.BorderInfo(Aspose.Pdf.BorderSide.All, .5f, Aspose.Pdf.Color.FromRgb(System.Drawing.Color.Black));
                // Set data source of the table...
                tblEducationalInfo.ImportDataTable(ds.Tables[0], true, 0, 0, ds.Tables[0].Rows.Count, 4);
                //Add table in paragraph...
                page.Paragraphs.Add(tblEducationalInfo);
                // Set the style of head row of the table...
                tblEducationalInfo.Rows[0].DefaultCellTextState.FontStyle = FontStyles.Bold;
                tblEducationalInfo.Rows[0].BackgroundColor = Aspose.Pdf.Color.LightGray;
                //set the min height of the rows...
                foreach (Aspose.Pdf.Row rw in tblEducationalInfo.Rows)
                {
                    rw.Cells[3].IsWordWrapped = false;
                    rw.MinRowHeight = 15;
                }
                //=========================== End of Educational Information Section ================================================

                //============================ Section of Professional Experience Starts======================
                // Add a new heading ...
                AddHeading(page, "Employment History:", 10, true);

                //create a new datatbale to store the data...
                DataTable dtExperience = new DataTable();
                dtExperience.Columns.Add("Designation", typeof(string));
                dtExperience.Columns.Add("Duration", typeof(string));
                dtExperience.Columns.Add("Organization", typeof(string));

                // get the data from the grid view into datatable...
                foreach (GridViewRow grow in gvExperience.Rows)
                {

                    TextBox txtDesignation = grow.FindControl("txtDesignation") as TextBox;
                    TextBox txtDuration = grow.FindControl("txtDuration") as TextBox;
                    TextBox txtOrganization = grow.FindControl("txtOrganization") as TextBox;
                    if (txtDesignation.Text.Trim() != "" && txtDuration.Text.Trim() != "" && txtOrganization.Text.Trim() != "")
                    {
                        DataRow drow = dtExperience.NewRow();
                        drow[0] = txtDesignation.Text;
                        drow[1] = txtDuration.Text;
                        drow[2] = txtOrganization.Text;

                        dtExperience.Rows.Add(drow);
                    }
                }

                //create table for personal information
                Aspose.Pdf.Table tblExperience = new Aspose.Pdf.Table();

               //set width of the columns...
                tblExperience.ColumnWidths = "100 100 200";
                //add table to the dataset
                ds = new DataSet();
                ds.Tables.Add(dtExperience);

                //set the font properties...
                tblExperience.DefaultCellTextState.FontSize = 8;
                tblExperience.DefaultCellTextState.Font = FontRepository.FindFont("Calibri");
                //Set the border style of the table...
                tblExperience.Border = new Aspose.Pdf.BorderInfo(Aspose.Pdf.BorderSide.All, .5f, Aspose.Pdf.Color.FromRgb(System.Drawing.Color.Black));
                // Set default cell border...
                tblExperience.DefaultCellBorder = new Aspose.Pdf.BorderInfo(Aspose.Pdf.BorderSide.All, .5f, Aspose.Pdf.Color.FromRgb(System.Drawing.Color.Black));
                // Set data source of the table...
                tblExperience.ImportDataTable(ds.Tables[0], true, 0, 0, ds.Tables[0].Rows.Count, 3);
                //Add table in paragraph...
                page.Paragraphs.Add(tblExperience);
                // Set the style of head row of the table...
                tblExperience.Rows[0].DefaultCellTextState.FontStyle = FontStyles.Bold;
                tblExperience.Rows[0].BackgroundColor = Aspose.Pdf.Color.LightGray;
                foreach (Aspose.Pdf.Row rw in tblExperience.Rows)
                {
                    rw.Cells[2].IsWordWrapped = false;
                    rw.MinRowHeight = 15;
                }
                //=========================== End of Professional Experience Section ================================================

                //=========================== Cover Letter Starts ===============================================================
                AddHeading(page, "Cover Letter:", 10, true);
                TextFragment txtFragCoverLetter = new TextFragment();
                txtFragCoverLetter.TextState.Font = FontRepository.FindFont("Calibri");
                txtFragCoverLetter.TextState.FontSize = 8;
                txtFragCoverLetter.Text = txtCoverLetter.Text;
                txtFragCoverLetter.TextState.LineSpacing = 5;
                page.Paragraphs.Add(txtFragCoverLetter);

                //=========================== End of Cover Letter Section ====================================================

                //Add watermark in the document...
                foreach (Aspose.Pdf.Page pg in doc.Pages)
                {
                    AddWaterMark(pg);
                }

                string path = Server.MapPath("~/Uploads/Application_" + DateTime.Now.ToString("dd_MM_yy HH_mm_ss") + ".pdf");
                doc.Save(path);
                msg.Text = "<div class='alert alert-success'><button data-dismiss='alert' class='close' type='button'>×</button>Your application has been submitted successfully.</div>";
                //show message "Your application has been submitted successfully."

            }
            catch(Exception exp)
            {
                msg.Text = "<div class='alert alert-danger'><button data-dismiss='alert' class='close' type='button'>×</button>Exception Occured:" + exp.Message + "</div>";
            }
        }
예제 #15
0
        public ActionResult ExportPdf(List <GetTimeSheetModel> model)
        {
            List <List <TimeSheetModel> > timeSheets = new List <List <TimeSheetModel> >();

            Aspose.Pdf.Document pdfDocument = new Aspose.Pdf.Document();

            Page page = pdfDocument.Pages.Add();

            page.PageInfo.IsLandscape = true;

            TextState tstate = new TextState();

            tstate.FontSize = 10;
            page.PageInfo.DefaultTextState = tstate;



            MarginInfo marginInfo = new MarginInfo();

            marginInfo.Left      = 35;
            marginInfo.Right     = 28;
            marginInfo.Top       = 28;
            marginInfo.Bottom    = 28;
            page.PageInfo.Margin = marginInfo;



            TextFragment text = new TextFragment("Time Sheets");

            text.HorizontalAlignment = Aspose.Pdf.HorizontalAlignment.Center;
            text.TextState.FontSize  = 16;
            text.Margin.Bottom       = 20;
            page.Paragraphs.Add(text);


            List <Table> tableList = new List <Table>();

            foreach (var item in model)
            {
                Table table = new Table
                {
                    ColumnWidths       = "80, 50, 65, 65, 60, 65, 50, 65, 50, 50, 65, 50",
                    DefaultCellPadding = new MarginInfo(10, 5, 10, 5),
                    Border             = new BorderInfo(BorderSide.All, .5f, Color.Black),
                    DefaultCellBorder  = new BorderInfo(BorderSide.All, .2f, Color.Black),
                };

                Aspose.Pdf.Row row1 = table.Rows.Add();

                row1.Cells.Add("Time Sheet Key");
                row1.Cells.Add("Type");
                row1.Cells.Add("Start Time");
                row1.Cells.Add("End Time");
                row1.Cells.Add("Breaks");
                row1.Cells.Add("Work Time");
                row1.Cells.Add("m3");
                row1.Cells.Add("Km - Stand");
                row1.Cells.Add("Privat");
                row1.Cells.Add("Fuel");
                row1.Cells.Add("Ad Blue");
                row1.Cells.Add("Notes");

                foreach (var sheet in GetTimeSheetsByEmployeeIdAndDate(item))
                {
                    if (sheet.startTime != "-1" || sheet.endTime != "-1" || sheet.breaks != "-1")
                    {
                        Aspose.Pdf.Row row = table.Rows.Add();
                        row.Cells.Add(sheet.timeSheetKey == "-1" ? "" : sheet.timeSheetKey);
                        row.Cells.Add(sheet.type == "-1" ? "" : sheet.type);
                        row.Cells.Add(sheet.startTime == "-1" ? "" : sheet.startTime);
                        row.Cells.Add(sheet.endTime == "-1" ? "" : sheet.endTime);
                        row.Cells.Add(sheet.breaks == "-1" ? "" : sheet.breaks);
                        row.Cells.Add(sheet.workTime == "-1" ? "" : sheet.workTime);
                        row.Cells.Add(Convert.ToString(sheet.m3 == -1 ? 0 : sheet.m3));
                        row.Cells.Add(Convert.ToString(sheet.kmStand == -1 ? 0 : sheet.kmStand));
                        row.Cells.Add(Convert.ToString(sheet.privat == -1 ? 0 : sheet.privat));
                        row.Cells.Add(Convert.ToString(sheet.fuel == -1 ? 0 : sheet.fuel));
                        row.Cells.Add(Convert.ToString(sheet.adblue == -1 ? 0 : sheet.adblue));
                        row.Cells.Add(sheet.notes == "-1" ? "" : sheet.notes);
                    }
                }
                tableList.Add(table);
                timeSheets.Add(GetTimeSheetsByEmployeeIdAndDate(item));
            }

            foreach (var table in tableList)
            {
                pdfDocument.Pages[1].Paragraphs.Add(table);

                text = new TextFragment("");

                text.HorizontalAlignment = Aspose.Pdf.HorizontalAlignment.Center;
                text.TextState.FontSize  = 16;
                text.Margin.Bottom       = 20;
                page.Paragraphs.Add(text);
            }

            using (var streamOut = new MemoryStream())
            {
                pdfDocument.Save(streamOut);
                return(new FileContentResult(streamOut.ToArray(), "application/pdf"));
            }
        }