You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
**.NET Standard** specification does not define APIs for converting images or scaling their quality. That is why to export to PDF format a document containing images different than Jpeg and Jpeg2000 or ImageQuality different than High, you will need to provide an implementation of the **JpegImageConverterBase** abstract class. This implementation should be passed to the **JpegImageConverter** property of the **FixedExtensibilityManager**.
35
+
**.NET Standard** specification does not define APIs for converting images or scaling their quality. That is why, when inserting images in a PDF document different than Jpeg and Jpeg2000 or ImageQuality different than High, you will need to implement the **JpegImageConverterBase** abstract class. This implementation should be passed to the **JpegImageConverter** property of the **FixedExtensibilityManager**.
36
+
37
+
>important With the [R2 2023 changes](https://docs.telerik.com/devtools/document-processing/libraries/radpdfprocessing/changes-and-backward-compatibility/backward-compatibility#whats-different-in-2023-r2) SkiaSharp replaced ImageSharp as the required dependency.
36
38
37
39
## Solution
38
40
39
-
The following code snippets demonstrate how to create a custom implementation of the JpegImageConverterBase abstract class using the [SixLabors.ImageSharp](https://github.com/SixLabors/ImageSharp) library and set it to the JpegImageConverter property of the FixedExtensibilityManager. We are using the ImageSharp library to convert the images from one of the library's supported formats to Jpeg and to change their quality if it is set.
41
+
The following code snippets demonstrate how to create a custom implementation of the JpegImageConverterBase abstract class using the [SixLabors.ImageSharp](https://github.com/SixLabors/ImageSharp) library and set it to the JpegImageConverter property of the FixedExtensibilityManager. We are using the ImageSharp library to convert the images from one of the library's supported formats to Jpeg and to change their quality if it is set. Note that this approach is valid up to version 2023.1.410 of RadPdfProcessing.
40
42
41
43
#### __[C#] Create a custom implementation inheriting the JpegImageConverterBase abstract class__
42
44
43
45
{{region kb-create-custom-jpeg-image-converter1}}
44
46
45
-
internal class JpegImageConverter : JpegImageConverterBase
46
-
{
47
-
public override bool TryConvertToJpegImageData(byte[] imageData, ImageQuality imageQuality, out byte[] jpegImageData)
47
+
public class CustomJpegImageConverter : JpegImageConverterBase
48
48
{
49
-
try
49
+
public override bool TryConvertToJpegImageData(byte[] imageData, ImageQuality imageQuality, out byte[] jpegImageData)
50
50
{
51
-
IImageFormat imageFormat;
52
-
using (SixLabors.ImageSharp.Image image = SixLabors.ImageSharp.Image.Load(imageData, out imageFormat))
51
+
try
53
52
{
54
-
if (imageFormat.GetType() == typeof(PngFormat))
53
+
IImageFormat imageFormat;
54
+
using (SixLabors.ImageSharp.Image image = SixLabors.ImageSharp.Image.Load(imageData, out imageFormat))
RadFixedDocument fixedDocument = new RadFixedDocument();
106
+
RadFixedDocumentEditor documentEditor = new RadFixedDocumentEditor(fixedDocument);
107
+
108
+
foreach (string imageFilePath in imageFiles)
109
+
{
110
+
FileStream fileStream = new FileStream(imageFilePath, FileMode.Open);
111
+
Telerik.Windows.Documents.Fixed.Model.Resources.ImageSource _imageSource = new Telerik.Windows.Documents.Fixed.Model.Resources.ImageSource(fileStream);
112
+
documentEditor.InsertImageInline(_imageSource);
113
+
documentEditor.InsertLineBreak();
114
+
}
115
+
116
+
documentEditor.Dispose();
117
+
string outputFilePath = @"output.pdf";
118
+
File.Delete(outputFilePath);
119
+
using (Stream output = File.OpenWrite(outputFilePath))
0 commit comments