Skip to content

Commit 5ca8230

Browse files
author
KB Bot
committed
Added new kb article generating-pdf-product-catalog
1 parent 2b446ab commit 5ca8230

File tree

1 file changed

+163
-0
lines changed

1 file changed

+163
-0
lines changed
Lines changed: 163 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,163 @@
1+
---
2+
title: Generating a PDF Product Catalog
3+
description: Learn how to export items, images, and editable text fields into a PDF using Telerik PdfProcessing.
4+
type: how-to
5+
page_title: Creating Editable PDF Catalog with Telerik PdfProcessing
6+
meta_title: Creating Editable PDF Catalog with Telerik PdfProcessing
7+
slug: generating-pdf-product-catalog
8+
tags: telerik, pdf,processing, catalog, product, item
9+
res_type: kb
10+
ticketid: 1697233
11+
---
12+
13+
## Environment
14+
15+
| Version | Product | Author |
16+
| ---- | ---- | ---- |
17+
| 2025.3.806| RadPdfProcessing |[Desislava Yordanova](https://www.telerik.com/blogs/author/desislava-yordanova)|
18+
19+
## Description
20+
21+
I need to export items, including images, text, and prices, into a PDF format that allows the text fields to be editable. This PDF document will be shared with a team while maintaining the look and feel of a specific design template.
22+
23+
This knowledge base article also answers the following questions:
24+
- How can I export items with editable text fields to a PDF?
25+
- Can Telerik PdfProcessing create an editable PDF with interactive fields?
26+
- How to generate a PDF catalog with images and editable text using Telerik PdfProcessing?
27+
28+
## Solution
29+
30+
To achieve this, use the Telerik [PdfProcessing](https://docs.telerik.com/devtools/document-processing/libraries/radpdfprocessing/overview) library, which supports creating and modifying PDF documents with interactive forms. Below is a sample implementation to generate a catalog PDF with editable text fields:
31+
32+
### Code Example
33+
34+
```csharp
35+
internal class Program
36+
{
37+
static void Main(string[] args)
38+
{
39+
Telerik.Documents.ImageUtils.ImagePropertiesResolver defaultImagePropertiesResolver = new Telerik.Documents.ImageUtils.ImagePropertiesResolver();
40+
Telerik.Windows.Documents.Extensibility.FixedExtensibilityManager.ImagePropertiesResolver = defaultImagePropertiesResolver;
41+
42+
// Create a list of Item objects
43+
var items = CreateSampleItems();
44+
45+
// Generate PDF with table
46+
GeneratePdfCatalog(items, "catalog.pdf");
47+
48+
Console.WriteLine("PDF catalog generated successfully!");
49+
}
50+
51+
private static List<Item> CreateSampleItems()
52+
{
53+
return new List<Item>
54+
{
55+
new Item
56+
{
57+
Image = "product-image-1.png",
58+
Description = "Premium Wireless Headphones with noise cancellation technology",
59+
Price = 199.99m
60+
},
61+
new Item
62+
{
63+
Image = "product-image-2.png",
64+
Description = "Smartphone with 128GB storage and dual camera system",
65+
Price = 699.99m
66+
},
67+
new Item
68+
{
69+
Image = "product-image-4.png",
70+
Description = "Laptop with 16GB RAM and 512GB SSD for professional use",
71+
Price = 1299.99m
72+
}
73+
};
74+
}
75+
76+
private static void GeneratePdfCatalog(List<Item> items, string fileName)
77+
{
78+
var document = new RadFixedDocument();
79+
80+
using (var editor = new RadFixedDocumentEditor(document))
81+
{
82+
// Add title
83+
editor.InsertRun("Product Catalog");
84+
editor.InsertLineBreak();
85+
editor.InsertLineBreak();
86+
87+
// Create table
88+
var table = new Table();
89+
90+
// Add data rows
91+
foreach (var item in items)
92+
{
93+
var row = table.Rows.AddTableRow();
94+
var itemCell = row.Cells.AddTableCell();
95+
96+
// Insert image
97+
var imageBlock = itemCell.Blocks.AddBlock();
98+
if (!string.IsNullOrEmpty(item.Image) && File.Exists(item.Image))
99+
{
100+
using (FileStream fileStream = new FileStream(item.Image, FileMode.Open))
101+
{
102+
ImageSource imageSrc = new ImageSource(fileStream);
103+
imageBlock.InsertImage(imageSrc, 180, 200);
104+
}
105+
}
106+
else
107+
{
108+
imageBlock.InsertText("No Image Available");
109+
}
110+
111+
// Insert description
112+
var descriptionBlock = itemCell.Blocks.AddBlock();
113+
descriptionBlock.TextProperties.FontSize = 12;
114+
descriptionBlock.InsertText(item.Description ?? "No Description");
115+
116+
// Insert price
117+
var priceBlock = itemCell.Blocks.AddBlock();
118+
priceBlock.TextProperties.FontSize = 18;
119+
priceBlock.InsertText($"${item.Price:F2}");
120+
121+
// Add editable field for price
122+
var textField = new TextBoxField("PriceField", $"${item.Price:F2}")
123+
{
124+
Width = 100,
125+
Height = 20
126+
};
127+
document.AcroForm.FormFields.Add(textField);
128+
}
129+
130+
// Insert the table into the document
131+
editor.InsertTable(table);
132+
}
133+
134+
// Save the document
135+
using (var output = File.Create(fileName))
136+
{
137+
var provider = new PdfFormatProvider();
138+
provider.Export(document, output);
139+
}
140+
141+
Console.WriteLine($"PDF saved to {fileName}");
142+
}
143+
144+
public class Item
145+
{
146+
public string Image { get; set; }
147+
public string Description { get; set; }
148+
public decimal Price { get; set; }
149+
}
150+
}
151+
```
152+
153+
### Key Notes
154+
1. Replace the inserted text blocks with interactive form fields like [TextBoxField](https://docs.telerik.com/devtools/document-processing/libraries/radpdfprocessing/model/interactive-forms/form-fields/textboxfield) for editable text.
155+
2. Ensure all required images are available in the specified paths.
156+
157+
## See Also
158+
159+
- [Telerik PdfProcessing Overview](https://docs.telerik.com/devtools/document-processing/libraries/radpdfprocessing/overview)
160+
- [Interactive Forms in PdfProcessing](https://docs.telerik.com/devtools/document-processing/libraries/radpdfprocessing/model/interactive-forms/overview)
161+
- [TextBoxField API](https://docs.telerik.com/devtools/document-processing/libraries/radpdfprocessing/model/interactive-forms/form-fields/textboxfield)
162+
- [Creating Interactive Forms Example](https://github.com/telerik/document-processing-sdk/tree/master/PdfProcessing/CreateInteractiveForms)
163+
- [PdfProcessing SDK Repository](https://github.com/telerik/document-processing-sdk)

0 commit comments

Comments
 (0)