GemBox Support Forum

Spreadsheet to PDF missing Content


I used this code to convert this xlsx file to a pdf. But this pdf is missing a bit of content:

I used this code:

using GemBox.Spreadsheet;

class Program
    static void Main()
        // If using Professional version, put your serial key below.

        // In order to convert Excel to PDF, we just need to:
        //   1. Load XLS or XLSX file into ExcelFile object.
        //   2. Save ExcelFile object to PDF file.
        ExcelFile workbook = ExcelFile.Load("ComplexTemplate.xlsx");
        workbook.Save("Convert.pdf", new PdfSaveOptions() { SelectionType = SelectionType.EntireFile });

And also tried to set each worksheet from the Workbook to:

foreach (var workSheet in _excelFile.Worksheets)
    workSheet.PrintOptions.FitWorksheetWidthToPages = 1;
    workSheet.PrintOptions.FitWorksheetHeightToPages = 1;

TypeOfFileThatIsWrapped = DocumentType.SpreadsheetFile;

But that also didn’t work. How can I fit the excel file on a single pdf page?

Greetings Brian



Hi Brian,

The reason that content is missing is because the Excel sheet specifies “A:I” as its print area.
In other words, the content after the column “I” is not exported.

Anyway, try using this:

var workbook = ExcelFile.Load("Jahreszeitlicher Fotokalender2.xlsx");

foreach (var worksheet in workbook.Worksheets)
    worksheet.PrintOptions.FitWorksheetWidthToPages = 1;
    worksheet.PrintOptions.FitWorksheetHeightToPages = 1;

workbook.Save("Convert.pdf", new PdfSaveOptions() { SelectionType = SelectionType.EntireFile });

Does this solve your issue?


1 Like

Thanks that did the trick :slight_smile: