XLSX to PDF only the first rows are rendered

Hi team,

I’m converting an Excel file (.xlsx) to PDF. The PDF only shows the first rows of the sheet; the rest of the rows are not rendered. I’m attaching the original Excel and a screenshot of the output where the truncation is visible.

Attachments

  • sample-file.xlsx (original workbook
  • screenshot-missing-rows.png (PDF snapshot showing only the initial rows)

Expected: the PDF should include all rows that are visible in Excel.
Actual: only the first rows are included; rows further down the sheet are missing.

Environment

  • .NET (tested in both .NET Framework and .NET Core with C#)
  • Aspose.Cells to load/process the workbook
  • Final export to PDF (the generated workbook stream is passed to the PDF step)

​Is there a recommended snippet to guarantee that everything visible in Excel is rendered into the PDF across as many pages as necessary?

If you need more information on how I am processing the xlsx please let me know.
Thanks!

@gabriel.vega

It sounds like you’re experiencing an issue where only the first few rows of your Excel sheet are being rendered in the PDF output. This can occur due to various reasons, such as page size settings or the way the workbook is being processed.

Cause: The problem may stem from incorrect page setup, hidden rows, or specific rendering options that are not configured properly.

Solution: To ensure that all visible rows in your Excel sheet are included in the PDF, please follow these steps:

  1. Check Page Setup: Verify that the page size and orientation settings in your Excel file are appropriate for the content. Adjust these settings in the Excel application before conversion.

  2. Use PdfSaveOptions: When saving the workbook to PDF, utilize the PdfSaveOptions class to specify settings that might help with rendering all content. Here’s a sample code snippet:

    // Load the workbook
    Workbook workbook = new Workbook("sample-file.xlsx");
    
    // Create PdfSaveOptions
    PdfSaveOptions saveOptions = new PdfSaveOptions();
    saveOptions.PageSet = new PageSet(0); // This will include all pages
    
    // Save the workbook to PDF
    workbook.Save("output.pdf", saveOptions);
    
  3. Adjust Image and Print Options: If your workbook contains images or complex formatting, ensure that the rendering options are set correctly. Specify options like image quality and rendering mode.

  4. Check for Hidden Rows: Ensure that there are no hidden rows in your Excel sheet that you expect to be rendered. Unhide any rows that might be hidden.

  5. Test with Different Formats: If the issue persists, try saving the workbook in different formats (like XPS or HTML) to determine if the problem is specific to PDF conversion.

Next Steps: If you continue to face issues after trying these solutions, please provide more details about how you are processing the workbook, and I will assist you further.

Let me know if this resolves your issue!

@gabriel.vega,

It seems the sample Excel file and screenshot are not attached. Perhaps they were missed by you. Kindly compress the sample Excel file and screenshot into a zipped archive and attach it here. We will review it soon.

As a side note, it appears that a predefined printable area is set for the worksheet in your template Excel file, which might be causing some rows or data to be excluded in the output PDF. Keep in mind that when a printable area is defined in the Page Setup settings, only the specified range will be included in the PDF rendering. To address this issue, you can remove the printable area by navigating to Page Setup > Sheet tab and clearing the “Print area”. After saving the updated file, retry your scenario using Aspose.Cells, and it should function correctly. Alternatively, you can dynamically remove the printable area within your code using Aspose.Cells.

....
//Get the PageSetup for the sheet named "Sheet1" (please change the line accordingly for your scenario).
PageSetup pageSetup = workbook.Worksheets["Sheet1"].PageSetup;
//Remove the printable area
pageSetup.PrintArea = "";
//....
//your code to render to PDF goes here.
//...

Hi @amjad.sahi

Thank you for your patience. This time, I have attached the requested test files (sample Excel file and screenshot) in a zipped archive for your review.

Excel Preview Issue.zip (186.5 KB)

I followed the proposed solution, but unfortunately the issue persists.

@gabriel.vega
By analyzing the sample file, we can find that the printing area is set in the sample file. So only the content within the printing area will be exported. If you want to print all the content, please clear the printing area. You can manually clear the printing area in Excel, or refer to the following example code. Please refer to the attachment. pagesetup.png (75.7 KB) out_net.pdf (115.8 KB)

Workbook book = new Workbook(filePath + @"sample-file.xlsx");

//Get the PageSetup for the sheet named "高雄結關"
//You can also use indexes to access worksheets
PageSetup pageSetup = book.Worksheets[0].PageSetup;
//Remove the printable area
pageSetup.PrintArea = "";

book.Save(filePath + "out_net.pdf");

Hope helps a bit.