Free Support Forum -

Converting Excel document to PDF using c# Stream


I’m converting several files of different filetypes using memorystreams. However we noticed that when for example an Excel file only has a value (eg. number “1”) in Cell A1 and we convert to PDF the GroupDocs converter will only convert that cell, resulting in a very small PDF file.

How can we achieve that the converter always converts the complete page (empty cells included) AND keeps using the saved orientation mode (Landscape / Portrait) ? Because now, when the document is not filled with a lot of cells, we have no difference in landscape/portrait in the resulting PDF file.

This code is used for conversion where the file variabel is our Excel file byte[]:

using (MemoryStream sourceStream = new MemoryStream(file))
using (var converter = new Converter(() => sourceStream))
using (MemoryStream output = new MemoryStream())
// Convert document through GroupsDoc.Converter
converter.Convert(new SaveDocumentStream(() => output), new PdfConvertOptions()
MarginBottom = 0,
MarginLeft = 0,
MarginRight = 0,
MarginTop = 0,

                        PdfOptions = {
                            PdfFormat = PdfFormats.v1_7,
                            OptimizationOptions = {
                                CompressImages = false,
                                ImageQuality = 100
                            Zoom = 100

Thank you in advance

1 Like


We are investigating this scenario. Your investigation ticket ID is CONVERSIONNET-3935. As there’s any update, you’ll be notified.


Using code below you can specify the cells conversion range and get output accordingly.

using (var converter = new Converter(source, () => new SpreadsheetLoadOptions{ ConvertRange = "A1:T10" }))
    var options = new PdfConvertOptions();
    converter.Convert("converted.pdf", options);

Have a look at these sample (28.0 KB).