PDFiumSharp PDF to Image size

Solution 1:

When you call bitmap.Save(...), the resulting byte[] that gets put into the MemoryStream stream represents a BMP. You should convert it into JPG yourself.

    public static byte[] Render(PdfDocument pdfDocument, int pageNumber, (int width, int height) outputSize)
    {
        var page = pdfDocument.Pages[pageNumber];

        using var thumb = new PDFiumBitmap((int)page.Width, (int)page.Height, false);
        page.Render(thumb);

        using MemoryStream memoryStreamBMP = new();
        thumb.Save(memoryStreamBMP);

        using Image imageBmp = Image.FromStream(memoryStreamBMP);

        using MemoryStream memoryStreamJPG = new();
        imageBmp.Save(memoryStreamJPG, ImageFormat.Jpeg);

        return memoryStreamJPG.ToArray();
    }