Insert bitmaps or GIFs into a PDF

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}");
            }
        }
}



1 Reply 1 reply marked as answer

GK Gowthamraj Kumar Syncfusion Team April 28, 2021 03:37 PM UTC

  
Hi Mark, 
 
Thank you for contacting Syncfusion support. 
 
We can able to insert .gif image file to PDF document using Syncfusion.Pdf.Imaging.Net.Core NuGet package and PdfTiffImage Class. We have created a Net Core sample for adding the Gif image into PDF document and it generates a PDF document properly. Kindly try the below sample in your end and let us know the result. 
 
 
Please refer the below links for more information, 
 
Please let us know if you need any further assistance with this. 
 
Regards, 
Gowthamraj K   


Marked as answer
Loader.
Up arrow icon