|
| 1 | +--- |
| 2 | +title: Adding More Content to a PDF Report |
| 3 | +description: "Learn how to append a PDF with terms and conditions to the last page of an exported into PDF report using Telerik Reporting and Telerik Document Processing." |
| 4 | +type: how-to |
| 5 | +page_title: How to Append More Content to a PDF Report Document |
| 6 | +slug: append-pdf-terms-to-telerik-reporting |
| 7 | +tags: telerik, reporting, pdf, pdfprocessing, append |
| 8 | +res_type: kb |
| 9 | +ticketid: 1690348 |
| 10 | +--- |
| 11 | + |
| 12 | +## Environment |
| 13 | + |
| 14 | +| Version | Product | Author | |
| 15 | +| ---- | ---- | ---- | |
| 16 | +| 19.1.25.521| Telerik Reporting|[Desislava Yordanova](https://www.telerik.com/blogs/author/desislava-yordanova)| |
| 17 | +| 2025.2.520| RadPdfProcessing |-| |
| 18 | + |
| 19 | +## Description |
| 20 | + |
| 21 | +This article demonstrates how to append a PDF, containing general terms and conditions, to the last page of a PDF document produced by exporting a Telerik Report(*.trdp/.trdx files exported as PDF documents*). The terms and conditions PDF should always appear at the end, regardless of the report's content. |
| 22 | + |
| 23 | +## Solution |
| 24 | + |
| 25 | +### Requirements and Steps |
| 26 | + |
| 27 | +To achieve this functionality, use: |
| 28 | + |
| 29 | +* [Telerik Reporting]({%slug telerikreporting/welcome-to-telerik-reporting!%}) to generate PDF reports. |
| 30 | +* [Telerik Document Processing](https://docs.telerik.com/devtools/document-processing/introduction) to manipulate the PDF and add some extra content. |
| 31 | + |
| 32 | +Follow these steps: |
| 33 | + |
| 34 | +1. **Generate the Report PDF using Telerik Reporting** |
| 35 | + Use Telerik Reporting to render the report as a PDF file. Refer to the [Generating Reports Locally with Code]({%slug telerikreporting/using-reports-in-applications/call-the-report-engine-via-apis/embedded-report-engine%}) article for more details on generating reports locally. |
| 36 | +1. **Import and Modify the PDF Report using Telerik Document Processing** |
| 37 | + Use Telerik Document Processing's [RadPdfProcessing](https://docs.telerik.com/devtools/document-processing/libraries/radpdfprocessing/overview) library to [import](https://docs.telerik.com/devtools/document-processing/libraries/radpdfprocessing/formats-and-conversion/pdf/pdfformatprovider/pdfformatprovider#import) the generated PDF, append a new page with the terms and conditions and export the final document. |
| 38 | + |
| 39 | +### Example Code |
| 40 | + |
| 41 | +Below is a complete example demonstrating how to generate the report PDF and append a new page: |
| 42 | + |
| 43 | +````C# |
| 44 | +using System.Diagnostics; |
| 45 | +using Telerik.Windows.Documents.Fixed.FormatProviders.Pdf; |
| 46 | +using Telerik.Windows.Documents.Fixed.Model; |
| 47 | +using Telerik.Windows.Documents.Fixed.Model.Data; |
| 48 | +using Telerik.Windows.Documents.Fixed.Model.Editing; |
| 49 | +using Telerik.Windows.Documents.Fixed.Model.Text; |
| 50 | + |
| 51 | +namespace GeneratePDFReportsAndUpdate |
| 52 | +{ |
| 53 | + internal class Program |
| 54 | + { |
| 55 | + static void Main(string[] args) |
| 56 | + { |
| 57 | + Telerik.Documents.ImageUtils.ImagePropertiesResolver defaultImagePropertiesResolver = new Telerik.Documents.ImageUtils.ImagePropertiesResolver(); |
| 58 | + Telerik.Windows.Documents.Extensibility.FixedExtensibilityManager.ImagePropertiesResolver = defaultImagePropertiesResolver; |
| 59 | + //https://docs.telerik.com/devtools/document-processing/libraries/radpdfprocessing/cross-platform/images |
| 60 | +
|
| 61 | + string reportFolderPath = @"..\..\..\Reports"; |
| 62 | + string pdfFolderPath = reportFolderPath + @"\Pdf Files"; |
| 63 | + string[] reportFiles = Directory.GetFiles(reportFolderPath); |
| 64 | + |
| 65 | + foreach (string reportFilePath in reportFiles) |
| 66 | + { |
| 67 | + var reportProcessor = new Telerik.Reporting.Processing.ReportProcessor(); |
| 68 | + var deviceInfo = new System.Collections.Hashtable(); |
| 69 | + |
| 70 | + var reportSource = new Telerik.Reporting.UriReportSource(); |
| 71 | + reportSource.Uri = reportFilePath; |
| 72 | + |
| 73 | + Telerik.Reporting.Processing.RenderingResult result = reportProcessor.RenderReport("PDF", reportSource, deviceInfo); |
| 74 | + string fileName = result.DocumentName + "_byReporting." + result.Extension; |
| 75 | + string path = System.IO.Path.GetTempPath(); |
| 76 | + string filePath = pdfFolderPath + @"\" + fileName; |
| 77 | + if (!result.HasErrors) |
| 78 | + { |
| 79 | + using (System.IO.FileStream fs = new System.IO.FileStream(filePath, System.IO.FileMode.Create)) |
| 80 | + { |
| 81 | + fs.Write(result.DocumentBytes, 0, result.DocumentBytes.Length); |
| 82 | + } |
| 83 | + } |
| 84 | + Process.Start(new ProcessStartInfo() { FileName = filePath, UseShellExecute = true }); |
| 85 | + |
| 86 | + // By Document Processing |
| 87 | + string filePathToImport = pdfFolderPath + @"\" + fileName; |
| 88 | + |
| 89 | + Telerik.Windows.Documents.Fixed.FormatProviders.Pdf.PdfFormatProvider pdf_provider = new PdfFormatProvider(); |
| 90 | + string[] pdfFilesByReporting = Directory.GetFiles(pdfFolderPath); |
| 91 | + |
| 92 | + |
| 93 | + fileName = result.DocumentName + "_byDPL." + result.Extension; |
| 94 | + filePath = pdfFolderPath + @"\" + fileName; |
| 95 | + |
| 96 | + using (Stream output = File.OpenWrite(filePath)) |
| 97 | + { |
| 98 | + //import the PDF report |
| 99 | + RadFixedDocument fixedDocument = pdf_provider.Import(File.OpenRead(filePathToImport), TimeSpan.FromSeconds(10)); |
| 100 | + |
| 101 | + //add a new page to the document |
| 102 | + //https://docs.telerik.com/devtools/document-processing/libraries/radpdfprocessing/model/textfragment |
| 103 | +
|
| 104 | + RadFixedPage page = new RadFixedPage(); |
| 105 | + fixedDocument.Pages.Add(page); |
| 106 | + FixedContentEditor editor = new FixedContentEditor(page); |
| 107 | + |
| 108 | + SimplePosition simplePosition = new SimplePosition(); |
| 109 | + simplePosition.Translate(20, 20); |
| 110 | + TextFragment textFragment = page.Content.AddTextFragment("General terms and conditions"); |
| 111 | + textFragment.CharacterSpacing = 5; |
| 112 | + textFragment.WordSpacing = 15; |
| 113 | + textFragment.Position = simplePosition; |
| 114 | + |
| 115 | + SimplePosition simplePosition2 = new SimplePosition(); |
| 116 | + simplePosition2.Translate(20, 120); |
| 117 | + TextFragment textFragment2 = new TextFragment("by Document Processing Libraries"); |
| 118 | + textFragment2.CharacterSpacing = 10; |
| 119 | + textFragment2.WordSpacing = 20; |
| 120 | + textFragment2.Position = simplePosition2; |
| 121 | + page.Content.Add(textFragment2); |
| 122 | + |
| 123 | + |
| 124 | + pdf_provider.Export(fixedDocument, output, TimeSpan.FromSeconds(10)); |
| 125 | + } |
| 126 | + |
| 127 | + Process.Start(new ProcessStartInfo() { FileName = filePath, UseShellExecute = true }); |
| 128 | + } |
| 129 | + } |
| 130 | + } |
| 131 | +} |
| 132 | +```` |
| 133 | + |
| 134 | +### Key Steps Explained: |
| 135 | + |
| 136 | +1. **Generate a PDF**: Use Telerik Reporting's `ReportProcessor` to render the `.trdp` file as a PDF. |
| 137 | +1. **Import the PDF**: Use `PdfFormatProvider` from RadPdfProcessing to load the generated PDF. |
| 138 | +1. **Add a Page**: Create a new page and use `FixedContentEditor` to add the terms and conditions text. |
| 139 | +1. **Export the Modified PDF**: Save the final PDF with the appended terms and conditions. |
| 140 | + |
| 141 | +## See Also |
| 142 | + |
| 143 | +* [RadPdfProcessing Overview](https://docs.telerik.com/devtools/document-processing/libraries/radpdfprocessing/overview) |
| 144 | +* [PDF Format Provider](https://docs.telerik.com/devtools/document-processing/libraries/radpdfprocessing/formats-and-conversion/pdf/pdfformatprovider/pdfformatprovider) |
0 commit comments