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

            // Instantiate a Document object
            Document pdfDocument = new Document();
            // Create a page in the pdf document
            Page sec1 = pdfDocument.Pages.Add();

            // Instantiate a table object
            Aspose.Pdf.Table tab1 = new Aspose.Pdf.Table();
            // Add the table in paragraphs collection of the desired page
            sec1.Paragraphs.Add(tab1);
            // Set default cell border using BorderInfo object
            tab1.DefaultCellBorder = new Aspose.Pdf.BorderInfo(Aspose.Pdf.BorderSide.All, 0.1F);
            // Set with column widths of the table
            tab1.ColumnWidths = "100 100 120";
            Aspose.Pdf.Image img = new Aspose.Pdf.Image();
            img.File = dataDir + "aspose.jpg";
            // Create rows in the table and then cells in the rows
            Aspose.Pdf.Row row1 = tab1.Rows.Add();
            row1.Cells.Add("Sample text in cell");
            // Add the cell which holds the image
            Aspose.Pdf.Cell cell2 = row1.Cells.Add();
            // Add the image to the table cell
            cell2.Paragraphs.Add(img);
            row1.Cells.Add("Previous cell with image");
            row1.Cells[2].VerticalAlignment = Aspose.Pdf.VerticalAlignment.Center;
            // Save the Document
            pdfDocument.Save(dataDir + "AddImageInTableCell_out.pdf");
            // ExEnd:AddImageinATableCell
        }
        public static void Run()
        {
            // ExStart:1
            // The path to the documents directory.
            string dataDir = RunExamples.GetDataDir_AsposePdf_StampsWatermarks();

            // Instantiate Document instance by calling empty constructor
            Aspose.Pdf.Document pdfDocument = new Aspose.Pdf.Document();
            // Create a page in the pdf document
            Aspose.Pdf.Page page = pdfDocument.Pages.Add();

            // Create a Header Section of the PDF file
            Aspose.Pdf.HeaderFooter header = new Aspose.Pdf.HeaderFooter();
            // Set the Odd Header for the PDF file
            page.Header = header;
            // Set the top margin for the header section
            header.Margin.Top = 20;

            // Instantiate a table object
            Aspose.Pdf.Table tab1 = new Aspose.Pdf.Table();
            // Add the table in paragraphs collection of the desired section
            header.Paragraphs.Add(tab1);
            // Set default cell border using BorderInfo object
            tab1.DefaultCellBorder = new Aspose.Pdf.BorderInfo(Aspose.Pdf.BorderSide.All, 0.1F);
            // Set with column widths of the table
            tab1.ColumnWidths = "60 300";

            Aspose.Pdf.Image img = new Aspose.Pdf.Image();
            img.File = dataDir + "aspose-logo.jpg";

            // Create rows in the table and then cells in the rows
            Aspose.Pdf.Row row1 = tab1.Rows.Add();

            row1.Cells.Add("Table in Header Section");
            row1.BackgroundColor = Color.Gray;
            // Set the row span value for first row as 2
            tab1.Rows[0].Cells[0].ColSpan = 2;
            tab1.Rows[0].Cells[0].DefaultCellTextState.ForegroundColor = Color.Cyan;
            tab1.Rows[0].Cells[0].DefaultCellTextState.Font            = FontRepository.FindFont("Helvetica");
            // Create rows in the table and then cells in the rows
            Aspose.Pdf.Row row2 = tab1.Rows.Add();
            // Set the background color for Row2
            row2.BackgroundColor = Color.White;
            // Add the cell which holds the image
            Aspose.Pdf.Cell cell2 = row2.Cells.Add();
            // Set the image width to 60
            img.FixWidth = 60;

            // Add the image to the table cell
            cell2.Paragraphs.Add(img);
            row2.Cells.Add("Logo is looking fine !");
            row2.Cells[1].DefaultCellTextState.Font = FontRepository.FindFont("Helvetica");
            // Set the vertical allignment of the text as center alligned
            row2.Cells[1].VerticalAlignment = Aspose.Pdf.VerticalAlignment.Center;
            row2.Cells[1].Alignment         = Aspose.Pdf.HorizontalAlignment.Center;

            // Save the Pdf file
            pdfDocument.Save(dataDir + "TableInHeaderFooterSection_out.pdf");
            // ExEnd:1
        }
        public static void Run()
        {
            //ExStart: TextAlignmentForTableRowContent
            var dataDir = RunExamples.GetDataDir_AsposePdf_Tables();

            // Create PDF document
            Aspose.Pdf.Document doc = new Aspose.Pdf.Document();
            // 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 = 0; row_count < 10; row_count++)
            {
                // add row to table
                Aspose.Pdf.Row row = table.Rows.Add();
                row.VerticalAlignment = VerticalAlignment.Center;

                row.Cells.Add("Column (" + row_count + ", 1)" + DateTime.Now.Ticks);
                row.Cells.Add("Column (" + row_count + ", 2)");
                row.Cells.Add("Column (" + row_count + ", 3)");
            }
            Page tocPage = doc.Pages.Add();

            // Add table object to first page of input document
            tocPage.Paragraphs.Add(table);
            // Save updated document containing table object
            doc.Save(dataDir + "43620_ByWords_out.pdf");
            //ExEnd: TextAlignmentForTableRowContent
        }
Beispiel #4
0
        private void CreateTableOnPdfFile_4()
        {
            //create filename of pdf_file_tosave
            var pdf_file_tosave = @"d:\1.pdf";

            //new pdf doc
            var pdfDoc = new Aspose.Pdf.Document();

            //editing
            pdfDoc.SetTitle("hello!");
            var pdfPage = pdfDoc.Pages.Add();

            var 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.LightGray);
            // Set the border for table cells
            table.DefaultCellBorder = new Aspose.Pdf.BorderInfo(Aspose.Pdf.BorderSide.All, .5f, Aspose.Pdf.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)");
            }
            // Add table object to first page of input document
            pdfPage.Paragraphs.Add(table);
            //Aspose.Pdf.Layer layer1 = new Aspose.Pdf.Layer("layer1","layer1");
            //pdfPage.Layers.Add(layer1); //why is pdfPage.layers null?

            //save
            try
            {
                pdfDoc.Save(pdf_file_tosave, Aspose.Pdf.SaveFormat.Pdf);
                MessageBox.Show("Save Successfully!");
                pdfDoc.Dispose();
                Process.Start(pdf_file_tosave);
            }
            catch
            {
                MessageBox.Show("Faild to Save!");
            }
        }
Beispiel #5
0
        public static void Run()
        {
            // ExStart:1
            // The path to the documents directory.
            string dataDir = RunExamples.GetDataDir_AsposePdf_Tables();

            string outFile = dataDir + "AddRepeatingColumn_out.pdf";
            // Create a new document
            Document doc = new Document();

            Aspose.Pdf.Page page = doc.Pages.Add();

            // Instantiate an outer table that takes up the entire page
            Aspose.Pdf.Table outerTable = new Aspose.Pdf.Table();
            outerTable.ColumnWidths        = "100%";
            outerTable.HorizontalAlignment = HorizontalAlignment.Left;

            // Instantiate a table object that will be nested inside outerTable that will break inside the same page
            Aspose.Pdf.Table mytable = new Aspose.Pdf.Table();
            mytable.Broken           = TableBroken.VerticalInSamePage;
            mytable.ColumnAdjustment = ColumnAdjustment.AutoFitToContent;

            // Add the outerTable to the page paragraphs
            // Add mytable to outerTable
            page.Paragraphs.Add(outerTable);
            var bodyRow  = outerTable.Rows.Add();
            var bodyCell = bodyRow.Cells.Add();

            bodyCell.Paragraphs.Add(mytable);
            mytable.RepeatingColumnsCount = 5;
            page.Paragraphs.Add(mytable);

            // Add header Row
            Aspose.Pdf.Row row = mytable.Rows.Add();
            row.Cells.Add("header 1");
            row.Cells.Add("header 2");
            row.Cells.Add("header 3");
            row.Cells.Add("header 4");
            row.Cells.Add("header 5");
            row.Cells.Add("header 6");
            row.Cells.Add("header 7");
            row.Cells.Add("header 11");
            row.Cells.Add("header 12");
            row.Cells.Add("header 13");
            row.Cells.Add("header 14");
            row.Cells.Add("header 15");
            row.Cells.Add("header 16");
            row.Cells.Add("header 17");

            for (int RowCounter = 0; RowCounter <= 5; RowCounter++)

            {
                // Create rows in the table and then cells in the rows
                Aspose.Pdf.Row row1 = mytable.Rows.Add();
                row1.Cells.Add("col " + RowCounter.ToString() + ", 1");
                row1.Cells.Add("col " + RowCounter.ToString() + ", 2");
                row1.Cells.Add("col " + RowCounter.ToString() + ", 3");
                row1.Cells.Add("col " + RowCounter.ToString() + ", 4");
                row1.Cells.Add("col " + RowCounter.ToString() + ", 5");
                row1.Cells.Add("col " + RowCounter.ToString() + ", 6");
                row1.Cells.Add("col " + RowCounter.ToString() + ", 7");
                row1.Cells.Add("col " + RowCounter.ToString() + ", 11");
                row1.Cells.Add("col " + RowCounter.ToString() + ", 12");
                row1.Cells.Add("col " + RowCounter.ToString() + ", 13");
                row1.Cells.Add("col " + RowCounter.ToString() + ", 14");
                row1.Cells.Add("col " + RowCounter.ToString() + ", 15");
                row1.Cells.Add("col " + RowCounter.ToString() + ", 16");
                row1.Cells.Add("col " + RowCounter.ToString() + ", 17");
            }
            doc.Save(outFile);
            // ExEnd:1
        }
Beispiel #6
0
        public static void Run()
        {
            // ExStart:ExportExcelWorksheetDataToTable
            // The path to the documents directory.
            string dataDir = RunExamples.GetDataDir_AsposePdf_Tables();

            Aspose.Cells.Workbook workbook = new Aspose.Cells.Workbook(new FileStream(dataDir + "newBook1.xlsx", FileMode.Open));
            // Accessing the first worksheet in the Excel file
            Aspose.Cells.Worksheet worksheet = workbook.Worksheets[0];
            // Exporting the contents of 7 rows and 2 columns starting from 1st cell to DataTable
            DataTable dataTable = worksheet.Cells.ExportDataTable(0, 0, worksheet.Cells.MaxRow + 1, worksheet.Cells.MaxColumn + 1, true);

            // Instantiate a Document instanc
            Aspose.Pdf.Document pdf1 = new Aspose.Pdf.Document();
            // Create a page in the document instance
            Aspose.Pdf.Page sec1 = pdf1.Pages.Add();

            // Create a Table object
            Aspose.Pdf.Table tab1 = new Aspose.Pdf.Table();

            // Add the Table object in the paragraphs collection of the section
            sec1.Paragraphs.Add(tab1);

            // Set column widths of the table.  We need to specify the ColumnCount manually.
            // As the curent excel worksheet has three columsn, so we are specifying the same count
            tab1.ColumnWidths = "40 100 100";

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

            // Import data into the Table object from the DataTable created above
            tab1.ImportDataTable(dataTable, true, 0, 0, dataTable.Rows.Count + 1, dataTable.Columns.Count);
            // Get 1st row from the table
            Aspose.Pdf.Row row1 = tab1.Rows[0];

            // Iterate through all cells in the 1st row and set their background color to blue
            foreach (Aspose.Pdf.Cell curCell in row1.Cells)
            {
                // Set the background of all the cells in 1st row of the table.
                curCell.BackgroundColor = Color.Blue;
                // Set the font face for the cells of 1st row in the table.
                curCell.DefaultCellTextState.Font = Aspose.Pdf.Text.FontRepository.FindFont("Helvetica-Oblique");
                // Set the font Color of all the cells in 1st row of the table.
                curCell.DefaultCellTextState.ForegroundColor = Color.Yellow;
                // Set the text allignment for the cells of 1st row as Center.
                curCell.DefaultCellTextState.HorizontalAlignment = Aspose.Pdf.HorizontalAlignment.Center;
            }

            for (int All_Rows = 1; All_Rows <= dataTable.Rows.Count; All_Rows++)
            {
                // Iterate through all cells in the 1st row and set their background color to blue
                foreach (Aspose.Pdf.Cell curCell in tab1.Rows[All_Rows].Cells)
                {
                    // Set the background color of all the cells except of the 1st row.
                    curCell.BackgroundColor = Color.Gray;
                    // Set the Text color of all the cells except the 1st row.
                    curCell.DefaultCellTextState.ForegroundColor = Color.White;
                }
            }

            // Save the Pdf
            pdf1.Save(dataDir + @"Exceldata_toPdf_table.pdf");
            // ExEnd:ExportExcelWorksheetDataToTable
        }
        public static void Run()
        {
            // ExStart:PlacingTextAroundImage
            // The path to the documents directory.
            string dataDir = RunExamples.GetDataDir_AsposePdf_Text();

            // Instantiate document object
            Aspose.Pdf.Document doc = new Aspose.Pdf.Document();
            // Create a page in the Pdf
            Aspose.Pdf.Page page = doc.Pages.Add();

            // Instantiate a table object
            Aspose.Pdf.Table table1 = new Aspose.Pdf.Table();
            // Add the table in paragraphs collection of the desired section
            page.Paragraphs.Add(table1);
            // Set with column widths of the table
            table1.ColumnWidths = "120 270";

            // 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;

            // Create rows in the table and then cells in the rows
            Aspose.Pdf.Row row1 = table1.Rows.Add();

            // Create an image object
            Aspose.Pdf.Image logo = new Aspose.Pdf.Image();
            // Specify the image file path
            logo.File = dataDir + "aspose-logo.jpg";
            // Specify the image Fixed Height
            logo.FixHeight = 120;
            // Specify the image Fixed Width
            logo.FixWidth = 110;
            row1.Cells.Add();
            // Add the image to paragraphs collection of the table cell
            row1.Cells[0].Paragraphs.Add(logo);

            // Create string variables with text containing html tags
            string TitleString = "<font face=\"Arial\" size=6 color=\"#101090\"><b> Aspose.Pdf for .NET</b></font>";

            string BodyString1 = "<font face=\"Arial\" size=2><br/>Aspose.Pdf for .NET is a non-graphical PDF� document reporting component that enables .NET applications to <b> create PDF documents from scratch </b> without utilizing Adobe Acrobat�. Aspose.Pdf for .NET is very affordably priced and offers a wealth of strong features including: compression, tables, graphs, images, hyperlinks, security and custom fonts. </font>";

            // Create a text object to be added to the right of image
            Aspose.Pdf.HtmlFragment TitleText = new Aspose.Pdf.HtmlFragment(TitleString + BodyString1);
            row1.Cells.Add();
            // Add the text paragraphs containing HTML text to the table cell
            row1.Cells[1].Paragraphs.Add(TitleText);
            // Set the vertical alignment of the row contents as Top
            row1.Cells[1].VerticalAlignment = Aspose.Pdf.VerticalAlignment.Top;

            // Create rows in the table and then cells in the rows
            Aspose.Pdf.Row SecondRow = table1.Rows.Add();
            SecondRow.Cells.Add();
            // Set the row span value for Second row as 2
            SecondRow.Cells[0].ColSpan = 2;
            // Set the vertical alignment of the second row as Top
            SecondRow.Cells[0].VerticalAlignment = Aspose.Pdf.VerticalAlignment.Top;

            string SecondRowString = "<font face=\"Arial\" size=2>Aspose.Pdf for .NET supports the creation of PDF files through API and XML or XSL-FO templates. Aspose.Pdf for .NET is very easy to use and is provided with 14 fully featured demos written in both C# and Visual Basic.</font>";

            Aspose.Pdf.HtmlFragment SecondRowText = new Aspose.Pdf.HtmlFragment(SecondRowString);
            // Add the text paragraphs containing HTML text to the table cell
            SecondRow.Cells[0].Paragraphs.Add(SecondRowText);
            // Save the Pdf file
            doc.Save(dataDir + "PlacingTextAroundImage_out.pdf");
            // ExEnd:PlacingTextAroundImage
        }