|
| 1 | +--- |
| 2 | +title: Generating a Table with RadFixedDocumentEditor |
| 3 | +description: Learn how to build a table using the RadFixedDocumentEditor for flow-like content management in RadPdfProcessing. |
| 4 | +type: how-to |
| 5 | +page_title: How to Generate a Table with RadFixedDocumentEditor |
| 6 | +slug: generate-table-with-radfixeddocumenteditor |
| 7 | +tags: pdf, document, processing, fixedcontenteditor, fixeddocumenteditor, edit, table,flow, position |
| 8 | +res_type: kb |
| 9 | +ticketid: 1674934 |
| 10 | +--- |
| 11 | +| Version | Product | Author | |
| 12 | +| ---- | ---- | ---- | |
| 13 | +| 2024.4.1106| RadPdfProcessing |[Desislava Yordanova](https://www.telerik.com/blogs/author/desislava-yordanova)| |
| 14 | + |
| 15 | +## Description |
| 16 | + |
| 17 | +When creating or editing a PDF document using [RadPdfProcessing]({%slug radpdfprocessing-overview%}), understanding how to manage the positioning of elements is essential. To eliminate the necessity of repositioning all elements below a newly added element in the middle of the PDF file, explore the functionality offerred by the [RadFixedDocumentEditor]({%slug radpdfprocessing-editing-radfixeddocumenteditor%}) to generate a PDF table. |
| 18 | + |
| 19 | +## Solution |
| 20 | + |
| 21 | +RadPdfProcessing offers the [RadFixedDocumentEditor]({%slug radpdfprocessing-editing-radfixeddocumenteditor%}, which allows for a flow-like content management approach and allows you to insert all desired elements one after another without calculating the elements' position. We will use this approach for generating the PDF table. |
| 22 | + |
| 23 | + This editor automates the positioning of elements, enabling you to insert content sequentially without manually calculating positions. This option might be more suitable for scenarios where manual positioning is cumbersome. |
| 24 | + |
| 25 | +The following example demonstrates how to create a table which result is illustrated below: |
| 26 | + |
| 27 | +```csharp |
| 28 | + RadFixedDocument radFixedDocument = new RadFixedDocument(); |
| 29 | + RadFixedDocumentEditor radFixedDocumentEditor = new RadFixedDocumentEditor(radFixedDocument); |
| 30 | + |
| 31 | + Table table = new Table(); |
| 32 | + table.LayoutType = Telerik.Windows.Documents.Fixed.Model.Editing.Flow.TableLayoutType.FixedWidth; |
| 33 | + |
| 34 | + TableRow row = table.Rows.AddTableRow(); |
| 35 | + TableCell cell = row.Cells.AddTableCell(); |
| 36 | + cell.Blocks.AddBlock().InsertText("Account No."); |
| 37 | + cell.Blocks.AddBlock().InsertText("12345678910"); |
| 38 | + |
| 39 | + cell = row.Cells.AddTableCell(); |
| 40 | + cell.Background = new RgbColor(255, 100, 100); |
| 41 | + cell.Blocks.AddBlock().InsertText("Statement Date"); |
| 42 | + cell.Blocks.AddBlock().InsertText("November 15, 2021"); |
| 43 | + |
| 44 | + row = table.Rows.AddTableRow(); |
| 45 | + cell = row.Cells.AddTableCell(); |
| 46 | + cell.Blocks.AddBlock().InsertText(" "); |
| 47 | + cell = row.Cells.AddTableCell(); |
| 48 | + cell.Background = new RgbColor(255, 100, 100); |
| 49 | + |
| 50 | + row = table.Rows.AddTableRow(); |
| 51 | + cell = row.Cells.AddTableCell(); |
| 52 | + cell.Blocks.AddBlock().InsertText("Account Name"); |
| 53 | + cell.Blocks.AddBlock().InsertText("Leslie Holden"); |
| 54 | + |
| 55 | + cell = row.Cells.AddTableCell(); |
| 56 | + cell.Background = new RgbColor(255, 100, 100); |
| 57 | + cell.Blocks.AddBlock().InsertText("Period Statement from"); |
| 58 | + cell.Blocks.AddBlock().InsertText("November 1, 2021");; |
| 59 | + |
| 60 | + row = table.Rows.AddTableRow(); |
| 61 | + cell = row.Cells.AddTableCell(); |
| 62 | + cell.Blocks.AddBlock().InsertText(" "); |
| 63 | + cell = row.Cells.AddTableCell(); |
| 64 | + cell.Background = new RgbColor(255, 100, 100); |
| 65 | + |
| 66 | + row = table.Rows.AddTableRow(); |
| 67 | + cell = row.Cells.AddTableCell(); |
| 68 | + cell.Blocks.AddBlock().InsertText("Address"); |
| 69 | + cell.Blocks.AddBlock().InsertText("4344 Poco Mas Drive"); |
| 70 | + cell.Blocks.AddBlock().InsertText("Dallas, FL, 33009"); |
| 71 | + |
| 72 | + cell = row.Cells.AddTableCell(); |
| 73 | + cell.Background = new RgbColor(255, 100, 100); |
| 74 | + cell.Blocks.AddBlock().InsertText("Period Statement until"); |
| 75 | + cell.Blocks.AddBlock().InsertText("November 13, 2021"); |
| 76 | + |
| 77 | + radFixedDocumentEditor.InsertTable(table); |
| 78 | + |
| 79 | + radFixedDocumentEditor.Dispose(); |
| 80 | + |
| 81 | + string outputFilePath = "output.pdf"; |
| 82 | + File.Delete(outputFilePath); |
| 83 | + PdfFormatProvider provider = new PdfFormatProvider(); |
| 84 | + using (Stream output = File.OpenWrite(outputFilePath)) |
| 85 | + { |
| 86 | + provider.Export(radFixedDocument, output, TimeSpan.FromSeconds(10)); |
| 87 | + } |
| 88 | + |
| 89 | + Process.Start(new ProcessStartInfo() { FileName = outputFilePath, UseShellExecute = true }); |
| 90 | +``` |
| 91 | + |
| 92 | +The observed result is illustrated below: |
| 93 | + |
| 94 | +  |
| 95 | + |
| 96 | +>note RadPdfProcessing offers an alternative approach with **[FixedContentEditor]({%slug radpdfprocessing-editing-fixedcontenteditor%})**. However, it requires managing the Position at which the document elements will be drawn. Enables precise control over the element's positioning within a PDF page. It acts as a pencil, allowing content to be drawn at specific locations. |
| 97 | +
|
| 98 | +## See Also |
| 99 | +- [RadPdfProcessing]({%slug radpdfprocessing-overview%}) |
| 100 | +- [RadFixedDocumentEditor]({%slug radpdfprocessing-editing-radfixeddocumenteditor%}) |
| 101 | +- [Table]({%slug radpdfprocessing-editing-table%}) |
| 102 | +- [Creating Custom Layout Tables with RadPdfProcessing]({%slug customize-table-layout-radpdfprocessing%}) |
| 103 | +- [How to Generate a Table with Images with PdfProcessing]({%slug generate-table-with-images-pdf-processing%}) |
| 104 | + |
0 commit comments