Free Support Forum -

Convert PNG to PDF with fit to page aspect ratio in .NET


I have a very large PNG file, 10,000x10,000 pixels. This converts to PDF successfully, but slowly due to it’s size, how can I fit this image to a standard A4 page?

I have tried setting the Height / Width on the convert options, however this does not maintain the aspect ratio of the image.

Is there a property somewhere I can use to achieve this?


1 Like


Could you please share the source PNG, resultant file and the sample code? We’ll then test this scenario at our end. (2.0 MB)

Please find both the .png and resulting .pdf in the attached .zip file.

Code is fairly straightforward.

using (Converter converter = new Converter(() => inputFile, ImageLoadOptions))
            var convertOptions = new PdfConvertOptions();
            convertOptions.Height = 1123;
            convertOptions.Width = 794;
            converter.Convert(stream => new MemoryStream(), (stream) =>
            }, convertOptions);

Where inputFile is of type Stream.

Func<LoadOptions> ImageLoadOptions = () =>
        //Currently no need for options, so just return a default instance.
        var options = new ImageLoadOptions();
        return options;


We are investigating this scenario if the performance of the API could be improved and aspect ration could be fixed. Your investigation ticket ID is CONVERSIONNET-4477.

Thank you @Atir_Tahir

To clarify, I don’t think the performance is a huge issue, my main requirement is to fit this image to an A4 page whilst maintaining aspect ratio. To do this the image will shrink in size which may improve performance.

1 Like


We are investigating this scenario and you’ll be notified in case of any update.