-
Notifications
You must be signed in to change notification settings - Fork 26
Added new kb article append-pdf-terms-to-telerik-reporting #1712
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
github-actions
wants to merge
2
commits into
master
Choose a base branch
from
new-kb-append-pdf-terms-to-telerik-reporting-d5fc5f84f23f4cc8b0a68db709a9fbe2
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+141
−0
Open
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
141 changes: 141 additions & 0 deletions
141
knowledge-base/append-pdf-terms-to-telerik-reporting.md
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,141 @@ | ||
--- | ||
title: Adding More Content to a PDF Report | ||
description: Learn how to append a PDF with terms and conditions to the last page of a Telerik Reporting report using Telerik Reporting and Telerik Document Processing. | ||
type: how-to | ||
page_title: How to Append More Content to a PDF Report | ||
slug: append-pdf-terms-to-telerik-reporting | ||
tags: telerik, reporting, pdf, pdfprocessing, append | ||
res_type: kb | ||
ticketid: 1690348 | ||
--- | ||
|
||
## Environment | ||
|
||
| Version | Product | Author | | ||
| ---- | ---- | ---- | | ||
| 19.1.25.521| Telerik Reporting|[Desislava Yordanova](https://www.telerik.com/blogs/author/desislava-yordanova)| | ||
| 2025.2.520| RadPdfProcessing |-| | ||
|
||
## Description | ||
|
||
This article demonstrates how to append a PDF, containing general terms and conditions, to the last page of my Telerik Reporting report (.trdp files exported as PDF documents). The terms and conditions PDF should always appear at the end, regardless of the report's content. | ||
|
||
## Solution | ||
|
||
To achieve this functionality, use: | ||
|
||
* [Telerik Reporting]({%slug telerikreporting/welcome-to-telerik-reporting!%}) to generate reports. | ||
* [Telerik Document Processing](https://docs.telerik.com/devtools/document-processing/introduction) to manipulate the PDF and add some extra content. | ||
|
||
Follow these steps: | ||
|
||
1. **Generate the Report PDF using Telerik Reporting** | ||
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. | ||
|
||
2. **Import and Modify the PDF Report using Telerik Document Processing** | ||
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. Refer to [RadPdfProcessing documentation](https://docs.telerik.com/devtools/document-processing/libraries/radpdfprocessing/overview) for additional details. | ||
|
||
### Example Code | ||
|
||
Below is a complete example demonstrating how to generate the report PDF and append a new page: | ||
|
||
```csharp | ||
using System.Diagnostics; | ||
using Telerik.Windows.Documents.Fixed.FormatProviders.Pdf; | ||
using Telerik.Windows.Documents.Fixed.Model; | ||
using Telerik.Windows.Documents.Fixed.Model.Data; | ||
using Telerik.Windows.Documents.Fixed.Model.Editing; | ||
using Telerik.Windows.Documents.Fixed.Model.Text; | ||
|
||
namespace GeneratePDFReportsAndUpdate | ||
{ | ||
internal class Program | ||
{ | ||
static void Main(string[] args) | ||
{ | ||
Telerik.Documents.ImageUtils.ImagePropertiesResolver defaultImagePropertiesResolver = new Telerik.Documents.ImageUtils.ImagePropertiesResolver(); | ||
Telerik.Windows.Documents.Extensibility.FixedExtensibilityManager.ImagePropertiesResolver = defaultImagePropertiesResolver; | ||
//https://docs.telerik.com/devtools/document-processing/libraries/radpdfprocessing/cross-platform/images | ||
|
||
string reportFolderPath = @"..\..\..\Reports"; | ||
string pdfFolderPath = reportFolderPath + @"\Pdf Files"; | ||
string[] reportFiles = Directory.GetFiles(reportFolderPath); | ||
|
||
foreach (string reportFilePath in reportFiles) | ||
{ | ||
var reportProcessor = new Telerik.Reporting.Processing.ReportProcessor(); | ||
var deviceInfo = new System.Collections.Hashtable(); | ||
|
||
var reportSource = new Telerik.Reporting.UriReportSource(); | ||
reportSource.Uri = reportFilePath; | ||
|
||
Telerik.Reporting.Processing.RenderingResult result = reportProcessor.RenderReport("PDF", reportSource, deviceInfo); | ||
string fileName = result.DocumentName + "_byReporting." + result.Extension; | ||
string path = System.IO.Path.GetTempPath(); | ||
string filePath = pdfFolderPath + @"\" + fileName; | ||
if (!result.HasErrors) | ||
{ | ||
using (System.IO.FileStream fs = new System.IO.FileStream(filePath, System.IO.FileMode.Create)) | ||
{ | ||
fs.Write(result.DocumentBytes, 0, result.DocumentBytes.Length); | ||
} | ||
} | ||
Process.Start(new ProcessStartInfo() { FileName = filePath, UseShellExecute = true }); | ||
|
||
// By Document Processing | ||
string filePathToImport = pdfFolderPath + @"\" + fileName; | ||
|
||
Telerik.Windows.Documents.Fixed.FormatProviders.Pdf.PdfFormatProvider pdf_provider = new PdfFormatProvider(); | ||
string[] pdfFilesByReporting = Directory.GetFiles(pdfFolderPath); | ||
|
||
|
||
fileName = result.DocumentName + "_byDPL." + result.Extension; | ||
filePath = pdfFolderPath + @"\" + fileName; | ||
|
||
using (Stream output = File.OpenWrite(filePath)) | ||
{ | ||
//import the PDF report | ||
RadFixedDocument fixedDocument = pdf_provider.Import(File.OpenRead(filePathToImport), TimeSpan.FromSeconds(10)); | ||
|
||
//add a new page to the document | ||
//https://docs.telerik.com/devtools/document-processing/libraries/radpdfprocessing/model/textfragment | ||
|
||
RadFixedPage page = new RadFixedPage(); | ||
fixedDocument.Pages.Add(page); | ||
FixedContentEditor editor = new FixedContentEditor(page); | ||
|
||
SimplePosition simplePosition = new SimplePosition(); | ||
simplePosition.Translate(20, 20); | ||
TextFragment textFragment = page.Content.AddTextFragment("General terms and conditions"); | ||
textFragment.CharacterSpacing = 5; | ||
textFragment.WordSpacing = 15; | ||
textFragment.Position = simplePosition; | ||
|
||
SimplePosition simplePosition2 = new SimplePosition(); | ||
simplePosition2.Translate(20, 120); | ||
TextFragment textFragment2 = new TextFragment("by Document Processing Libraries"); | ||
textFragment2.CharacterSpacing = 10; | ||
textFragment2.WordSpacing = 20; | ||
textFragment2.Position = simplePosition2; | ||
page.Content.Add(textFragment2); | ||
|
||
|
||
pdf_provider.Export(fixedDocument, output, TimeSpan.FromSeconds(10)); | ||
} | ||
|
||
Process.Start(new ProcessStartInfo() { FileName = filePath, UseShellExecute = true }); | ||
} | ||
} | ||
} | ||
} | ||
``` | ||
|
||
### Key Steps Explained: | ||
1. **Generate a PDF**: Use Telerik Reporting's `ReportProcessor` to render the `.trdp` file as a PDF. | ||
2. **Import the PDF**: Use `PdfFormatProvider` from RadPdfProcessing to load the generated PDF. | ||
3. **Add a Page**: Create a new page and use `FixedContentEditor` to add the terms and conditions text. | ||
4. **Export the Modified PDF**: Save the final PDF with the appended terms and conditions. | ||
|
||
## See Also | ||
- [RadPdfProcessing Overview](https://docs.telerik.com/devtools/document-processing/libraries/radpdfprocessing/overview) | ||
- [PDF Format Provider]([https://docs.telerik.com/devtools/document-processing/libraries/radpdfprocessing/formats-and-conversion/pdf/pdfformatprovider/pdfformatprovider#import](https://docs.telerik.com/devtools/document-processing/libraries/radpdfprocessing/formats-and-conversion/pdf/pdfformatprovider/pdfformatprovider)) |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[nitpick] Consider extracting hard-coded positioning values (e.g.,
20, 20
and20, 120
) into named constants or configuration to improve readability and maintainability.Copilot uses AI. Check for mistakes.