Image
Image is a content element, which contains an ImageSource and represents an image. It can be added in the Content collection of a IContainerElement such as RadFixedPage.
Working With an Image
You can edit an Image element using the properties the class exposes. The properties are listed below.
- ImageSource: Specifies the ImageSource that will be visualized in the Image object.
- Width: The width of the image.
- Height: The height of the image.
- Position: The Position of the image inside the IContainerElement.
As of Q3 2024 RadPdfProcessing provides support for SVG (vector graphics image format): Adding SVG into a Document.
Example 1 shows how to initialize an Image object, assigns an ImageSource to it and add it to a previously defined container (page).
Example 1: Create image
RadFixedDocument fixedDocument = new RadFixedDocument();
RadFixedPage fixedPage = fixedDocument.Pages.AddPage();
Image image = new Image();
string imageFilePath = "ProgressNinjas.png";
FileStream fileStream = new FileStream(imageFilePath, FileMode.Open);
ImageSource imageSrc = new ImageSource(fileStream);
image.ImageSource = imageSrc;
image.Width = 200;
image.Height = 200;
SimplePosition simplePosition = new SimplePosition();
simplePosition.Translate(200, 300);
image.Position = simplePosition;
fixedPage.Content.Add(image);
Example 2 demonstrates how to use one of the factory methods of the ContentElementCollection to create a new image and insert it into the respective container.
Example 2: Add image to container
Image image = container.Content.AddImage();
Image imageWithSource = container.Content.AddImage(imageSource);
There are other methods that allow adding an image to a document by passing image size, format and source. They could be used through the FixedContentEditor class.
The Image class exposes also the GetBitmapSource() method, enabling you to obtain a BitmapSource instance representing the image.
The GetBitmapSource() method is not available in the .NET Standard version of the PdfProcessing binaries.
Example 3: Obtain BitmapSource
BitmapSource source = image.GetBitmapSource();
See Also
- ImageSource
- RadFixedPage
- FixedContentEditor
- Position
- How to Generate a PDF Document from Images with FixedContentEditor
- How to Generate a PDF Document from Images with RadFixedDocumentEditor
- Change file size of a PDF with images through ImageCompression and ImageQuality
- Adding Images with a Shadow in PDF Documents
- Splitting a Large Image Across Multiple PDF Pages
- Change file size of a PDF with images through ImageCompression and ImageQuality
- Adding a Barcode to a PDF Document using PdfProcessing and the WinForms BarcodeView