|
| 1 | +//ExStart |
| 2 | +//ExSummary: This code demonstrates how to create a PDF document with a table containing 10 rows and 3 columns. |
| 3 | +//ExStepSummary:0: This step sets the directory path where the output PDF file will be saved. |
| 4 | +//ExStepSummary:1: This step creates a new PDF document instance. |
| 5 | +//ExStepSummary:2: This step initializes a new table object. |
| 6 | +//ExStepSummary:3: This step sets the border color of the table to LightGray. |
| 7 | +//ExStepSummary:4: This step applies a LightGray border to all table cells. |
| 8 | +//ExStepSummary:5: This step starts a loop to add 10 rows to the table. |
| 9 | +//ExStepSummary:6: This step adds a new row to the table and sets its vertical alignment to center. |
| 10 | +//ExStepSummary:7: This step adds three cells to the row, with the first cell containing dynamic content based on the current timestamp. |
| 11 | +//ExStepSummary:8: This step adds a new page to the PDF document. |
| 12 | +//ExStepSummary:9: This step adds the table to the newly created page in the document. |
| 13 | +//ExStepSummary:10: This step saves the final PDF document to the specified output directory. |
| 14 | +//ExStepImage:8:images/1.png |
| 15 | + |
| 16 | +//ExStep:0- |
| 17 | +// The path to the documents directory. |
| 18 | +string dataDir = "Your Document Directory"; |
| 19 | + |
| 20 | +//ExStep:1- |
| 21 | +// Create a new PDF document. |
| 22 | +Aspose.Pdf.Document doc = new Aspose.Pdf.Document(); |
| 23 | + |
| 24 | +//ExStep:2- |
| 25 | +// Initializes a new instance of the Table. |
| 26 | +Aspose.Pdf.Table table = new Aspose.Pdf.Table(); |
| 27 | + |
| 28 | +//ExStep:3- |
| 29 | +// Set the table border color as LightGray. |
| 30 | +table.Border = new Aspose.Pdf.BorderInfo(Aspose.Pdf.BorderSide.All, .5f, Aspose.Pdf.Color.FromRgb(System.Drawing.Color.LightGray)); |
| 31 | + |
| 32 | +//ExStep:4- |
| 33 | +// Set the border for table cells. |
| 34 | +table.DefaultCellBorder = new Aspose.Pdf.BorderInfo(Aspose.Pdf.BorderSide.All, .5f, Aspose.Pdf.Color.FromRgb(System.Drawing.Color.LightGray)); |
| 35 | + |
| 36 | +//ExStep:5- |
| 37 | +// Create a loop to add 10 rows |
| 38 | +for (int row_count = 0; row_count < 10; row_count++) |
| 39 | +{ |
| 40 | +//ExStep:6- |
| 41 | + // Add row to table |
| 42 | + Aspose.Pdf.Row row = table.Rows.Add(); |
| 43 | + // Set vertical alignment of the row. |
| 44 | + row.VerticalAlignment = VerticalAlignment.Center; |
| 45 | + |
| 46 | +//ExStep:7- |
| 47 | + // Add first cell with dynamic content. |
| 48 | + row.Cells.Add("Column (" + row_count + ", 1)" + DateTime.Now.Ticks); |
| 49 | + // Add second cell. |
| 50 | + row.Cells.Add("Column (" + row_count + ", 2)"); |
| 51 | + // Add third cell. |
| 52 | + row.Cells.Add("Column (" + row_count + ", 3)"); |
| 53 | +} |
| 54 | + |
| 55 | +//ExStep:8- |
| 56 | +// Add a new page to the PDF document. |
| 57 | +Page tocPage = doc.Pages.Add(); |
| 58 | + |
| 59 | +//ExStep:9- |
| 60 | +// Add the table object to the first page of the document. |
| 61 | +tocPage.Paragraphs.Add(table); |
| 62 | + |
| 63 | +//ExStep:10- |
| 64 | +// Save the updated document containing the table object. |
| 65 | +doc.Save(dataDir + "43620_ByWords_out.pdf"); |
| 66 | +//ExEnd |
0 commit comments