Skip to content

Commit 9d330ff

Browse files
author
KB Bot
committed
Added new kb article draw-rectangle-with-content
1 parent 68f43cf commit 9d330ff

File tree

1 file changed

+97
-0
lines changed

1 file changed

+97
-0
lines changed
Lines changed: 97 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
1+
---
2+
title: Drawing Rectangles, Text, and Images with RadPdfProcessing
3+
description: Learn how to draw rectangles with specific styles, add centered text, and images within those rectangles using the RadPdfProcessing library.
4+
type: how-to
5+
page_title: How to Draw Styled Rectangles, Text, and Images in PDFs with RadPdfProcessing
6+
slug: draw-rectangles-text-images-radpdfprocessing
7+
tags: radpdfprocessing, document processing, rectangles, text, images, drawing, pdf
8+
res_type: kb
9+
ticketid: 1677969
10+
---
11+
12+
## Environment
13+
14+
<table>
15+
<tbody>
16+
<tr>
17+
<td>Product</td>
18+
<td>RadPdfProcessing for Document Processing</td>
19+
</tr>
20+
</tbody>
21+
</table>
22+
23+
## Description
24+
25+
I have created a block that contains some text and is located at a specific position with a defined size. I need to draw a rectangle at the same position and size, style it with a black stroke and a light blue background, and then place text and an image centered both vertically and horizontally within this rectangle.
26+
27+
This knowledge base article also answers the following questions:
28+
- How can I draw a rectangle and style it using RadPdfProcessing?
29+
- How to add centered text within a rectangle in a PDF document?
30+
- How to insert an image and center it within a rectangle using RadPdfProcessing?
31+
32+
## Solution
33+
34+
To draw a rectangle with a black stroke and a light blue background, add centered text, and insert a centered image within the rectangle using the RadPdfProcessing library, follow these steps:
35+
36+
### Drawing a Rectangle
37+
38+
1. Create a `RectangleGeometry` and define its dimensions.
39+
2. Create a `Path` and set the `RectangleGeometry` to its geometry.
40+
3. Set the `IsFilled` and `IsStroked` properties of the path to true.
41+
4. Specify the `Fill`, `Stroke`, and `StrokeThickness` properties for the path.
42+
5. Add the path to the page content.
43+
44+
```csharp
45+
RectangleGeometry rectangleGeometry = new RectangleGeometry();
46+
rectangleGeometry.Rect = new Rect(100, 100, 100, 300);
47+
48+
Telerik.Windows.Documents.Fixed.Model.Graphics.Path path = new Telerik.Windows.Documents.Fixed.Model.Graphics.Path();
49+
path.Geometry = rectangleGeometry;
50+
51+
path.IsFilled = true;
52+
path.IsStroked = true;
53+
54+
path.Fill = new RgbColor(173, 216, 230); // Light blue
55+
path.Stroke = RgbColors.Black;
56+
path.StrokeThickness = 2;
57+
58+
Page.Content.Add(path);
59+
```
60+
61+
### Adding Centered Text
62+
63+
1. Create a `Block` and insert the text.
64+
2. Apply text and graphic properties as desired.
65+
3. Use a `FixedContentEditor` to draw the block at the desired position and size.
66+
67+
```csharp
68+
Block textBlock = new Block();
69+
textBlock.InsertText("Your text here");
70+
// Apply desired text and graphic properties to textBlock
71+
FixedContentEditor editor = new FixedContentEditor(Page);
72+
editor.Position.Translate(100, 100);
73+
editor.DrawBlock(textBlock, new System.Windows.Size(100, 300));
74+
```
75+
76+
### Inserting a Centered Image
77+
78+
1. Load or create an `ImageSource`.
79+
2. Create an `Image` and set the image source.
80+
3. Use a `FixedContentEditor` to draw the image at the desired position and size.
81+
82+
```csharp
83+
ImageSource imageSource = new ImageSource("path/to/your/image.jpg");
84+
Image image = new Image(imageSource);
85+
// Use FixedContentEditor to draw the image as shown for the text block
86+
```
87+
88+
Following these steps allows you to draw styled rectangles, add centered text, and insert centered images within these rectangles using the RadPdfProcessing library.
89+
90+
## See Also
91+
92+
- [Text and Graphic Properties Documentation](https://docs.telerik.com/devtools/document-processing/libraries/radpdfprocessing/editing/text-and-graphic-properties)
93+
- [Path Documentation](https://docs.telerik.com/devtools/document-processing/libraries/radpdfprocessing/model/path)
94+
- [Geometry Documentation](https://docs.telerik.com/devtools/document-processing/libraries/radpdfprocessing/concepts/geometry)
95+
- [Image Documentation](https://docs.telerik.com/devtools/document-processing/libraries/radpdfprocessing/model/image)
96+
- [RadPdfProcessing Overview](https://docs.telerik.com/devtools/document-processing/libraries/radpdfprocessing/overview)
97+
---

0 commit comments

Comments
 (0)