Hi,
I'm trying to insert bitmaps or GIFs into a PDF Document that I am creating in a .NET Core Application (.NET Core 3.1, it's an Azure Function). I can insert PNGs without problem but if I try to insert a bitmap I get an exception ("Only JPEG and PNG images are supported").
The documentation on Syncfusion's web site (https://help.syncfusion.com/file-formats/pdf/working-with-images) suggests that this is possible. What else do I need to do to get bitmaps (and the other file formats the documentation states is supported) working?
My sample code is based on Syncfusion's sample and is as follows:
public void ValidateAndConvert(Stream inputStream, Stream outputStream, string filename)
{
try
{
var pdfDocument = new PdfDocument
{
PageSettings = { Size = PdfPageSize.A4 }
};
PdfPage pdfPage = pdfDocument.Pages.Add();
// Get page size to draw image which fits the page
SizeF pageSize = pdfPage.GetClientSize();
// Create PDF graphics for the page
PdfGraphics graphics = pdfPage.Graphics;
// Load the image from the disk
PdfBitmap image = new PdfBitmap(inputStream);
// Draw the image
graphics.DrawImage(image, new RectangleF(0, 0, pageSize.Width, pageSize.Height));
pdfDocument.Save(outputStream);
}
catch (Exception e)
{
this.Logger.LogWarning($"Exception error while processing file {filename}: {e.Message}");
}
}
}