Issue with ODS to PDF Conversion – Text and Shapes Missing Intermittently Aspose.Cells 25.9.0

Dear Aspose Support,

I am encountering an issue while converting ODS (OpenOffice / LibreOffice Calc) files to PDF using Aspose.Cells version 25.9.0. The problem seems to be intermittent — sometimes the text is visible in the output PDF, but the shape is missing. In other instances, the shape is visible but the text is missing.

The issue occurs with files that were originally in XLSX format, and later saved as ODS format using Excel. Despite trying several approaches to resolve the issue, the result remains inconsistent.

Here are the various solutions I have attempted:

1. First Approach – Basic PDF Conversion with Standard Options:

// Load the workbook
Workbook wb = new Workbook(inStream);

// Use fully qualified name to avoid ambiguity
Aspose.Cells.PdfSaveOptions pdfSaveOptions = new Aspose.Cells.PdfSaveOptions();
pdfSaveOptions.OnePagePerSheet = false; // Keep natural page breaks
pdfSaveOptions.AllColumnsInOnePagePerSheet = false; // Respect column widths
pdfSaveOptions.OptimizationType = Aspose.Cells.Rendering.PdfOptimizationType.Standard;
pdfSaveOptions.Compliance = Aspose.Cells.Rendering.PdfCompliance.None; // Or set to PdfA1b if needed

// Configure each worksheet
foreach (Worksheet ws in wb.Worksheets)
{
// Page setup
ws.PageSetup.Orientation = PageOrientationType.Landscape;
ws.PageSetup.PaperSize = PaperSizeType.PaperLetter;

// Fit content to page
ws.PageSetup.FitToPagesTall = 0; // Auto height
ws.PageSetup.FitToPagesWide = 1; // Fit to 1 page width

// Margins (adjust as needed)
ws.PageSetup.LeftMargin = 0.5;
ws.PageSetup.RightMargin = 0.5;
ws.PageSetup.TopMargin = 0.5;
ws.PageSetup.BottomMargin = 0.5;

// Print quality
ws.PageSetup.PrintQuality = 300;

}

// Save to PDF with options
wb.Save(outStream, pdfSaveOptions);

2. Second Approach – Force Each Sheet to One Page:

// Load the workbook
Workbook wb = new Workbook(inStream);

// Use fully qualified name to avoid ambiguity
Aspose.Cells.PdfSaveOptions pdfSaveOptions = new Aspose.Cells.PdfSaveOptions();
pdfSaveOptions.OnePagePerSheet = true; // Force each sheet to one page
pdfSaveOptions.AllColumnsInOnePagePerSheet = true; // Fit all columns on one page

// Configure each worksheet
foreach (Worksheet ws in wb.Worksheets)
{
// Page setup
ws.PageSetup.Orientation = PageOrientationType.Landscape;
ws.PageSetup.PaperSize = PaperSizeType.PaperLetter;

// Force fit to 1 page
ws.PageSetup.FitToPagesTall = 1; // Fit to 1 page height
ws.PageSetup.FitToPagesWide = 1; // Fit to 1 page width

// Minimize margins to maximize content area
ws.PageSetup.LeftMargin = 0.25;
ws.PageSetup.RightMargin = 0.25;
ws.PageSetup.TopMargin = 0.25;
ws.PageSetup.BottomMargin = 0.25;

// Center content
ws.PageSetup.CenterHorizontally = true;
ws.PageSetup.CenterVertically = true;

}

// Save to PDF with options
wb.Save(outStream, pdfSaveOptions);

3. Third Approach – Setting Print Area and Fit to Page with Auto-Fitting Columns and Rows:

// Load the workbook
Workbook wb = new Workbook(inStream);

// Use fully qualified name to avoid ambiguity
Aspose.Cells.PdfSaveOptions pdfSaveOptions = new Aspose.Cells.PdfSaveOptions();
pdfSaveOptions.OnePagePerSheet = true; // Force each sheet to one page
pdfSaveOptions.AllColumnsInOnePagePerSheet = true; // Fit all columns

// Configure each worksheet
foreach (Worksheet ws in wb.Worksheets)
{
// Auto-fit columns and rows to ensure all content is visible
ws.AutoFitColumns();
ws.AutoFitRows();

// Get the actual used range (where data exists)
Aspose.Cells.Range usedRange = ws.Cells.MaxDisplayRange;

// Set print area to the actual used range to avoid cutting content
if (usedRange != null)
{
    ws.PageSetup.PrintArea = usedRange.RefersTo.Replace("=", "");
}

// Page setup
ws.PageSetup.Orientation = PageOrientationType.Landscape;
ws.PageSetup.PaperSize = PaperSizeType.PaperLetter;

// Force fit to 1 page
ws.PageSetup.FitToPagesTall = 1;
ws.PageSetup.FitToPagesWide = 1;
ws.PageSetup.IsPercentScale = false;

// Minimize margins to maximize content area
ws.PageSetup.LeftMargin = 0.2;
ws.PageSetup.RightMargin = 0.2;
ws.PageSetup.TopMargin = 0.2;
ws.PageSetup.BottomMargin = 0.2;
ws.PageSetup.HeaderMargin = 0;
ws.PageSetup.FooterMargin = 0;

// Ensure gridlines and content are visible
ws.PageSetup.PrintGridlines = false; // Set to true if you want gridlines
ws.PageSetup.PrintHeadings = false;

// Center content
ws.PageSetup.CenterHorizontally = true;
ws.PageSetup.CenterVertically = true;

// Print quality
ws.PageSetup.PrintQuality = 600; // Higher quality for better rendering

}

// Calculate before saving to ensure formulas are evaluated
wb.CalculateFormula();

// Save to PDF with options
wb.Save(outStream, pdfSaveOptions);

4. Fourth Approach – Dynamic Page Scaling Based on Content Size:

// Load the workbook
Workbook wb = new Workbook(inStream);

// Configure save options
Aspose.Cells.PdfSaveOptions pdfSaveOptions = new Aspose.Cells.PdfSaveOptions();
pdfSaveOptions.OnePagePerSheet = false; // Let it paginate naturally first
pdfSaveOptions.CalculateFormula = true;

foreach (Worksheet ws in wb.Worksheets)
{
if (ws.Cells.MaxDataRow < 0) continue;

// Get actual used range
int maxRow = ws.Cells.MaxDataRow;
int maxCol = ws.Cells.MaxDataColumn;

// Calculate appropriate scaling
PageSetup ps = ws.PageSetup;

// Set page to landscape letter
ps.Orientation = PageOrientationType.Landscape;
ps.PaperSize = PaperSizeType.PaperLetter;

// Calculate how many columns can fit
double totalWidth = 0;
for (int col = 0; col <= maxCol; col++)
{
    totalWidth += ws.Cells.GetColumnWidthInch(col);
}

// Calculate how many rows can fit
double totalHeight = 0;
for (int row = 0; row <= maxRow; row++)
{
    totalHeight += ws.Cells.GetRowHeightInch(row);
}

// Page dimensions (Letter landscape: 11" x 8.5")
double pageWidth = 11.0 - 0.5; // minus margins
double pageHeight = 8.5 - 0.5; // minus margins

// Calculate required pages
int pagesWide = (int)Math.Ceiling(totalWidth / pageWidth);
int pagesTall = (int)Math.Ceiling(totalHeight / pageHeight);

// Force to single page if close enough
if (pagesWide <= 2 && pagesTall <= 2)
{
    ps.FitToPagesWide = 1;
    ps.FitToPagesTall = 1;
    ps.IsPercentScale = false;
}
else
{
    // Use natural pagination
    ps.FitToPagesWide = 0;
    ps.FitToPagesTall = 0;
}

// Set minimal margins
ps.LeftMargin = 0.25;
ps.RightMargin = 0.25;
ps.TopMargin = 0.25;
ps.BottomMargin = 0.25;

// Set print area
ps.PrintArea = $"A1:{CellsHelper.CellIndexToName(maxRow, maxCol)}";

// Print settings
ps.PrintQuality = 600;
ps.Order = PrintOrderType.OverThenDown;

}

// Save
wb.CalculateFormula();
wb.Save(outStream, pdfSaveOptions);
outStream.Position = 0;

Aspose.Pdf.Document pdfDocPg = new Aspose.Pdf.Document(outStream);
pageCountDocument = pdfDocPg.Pages.Count.ToString();

The issue appears with ODS files that were originally in XLSX format, and subsequently saved as ODS files using Excel. After conversion, the following happens:

  • Intermittent Missing Content: When the text is visible in the PDF, shapes are missing. Conversely, if shapes are present, the text is missing.
  • This behavior is observed when converting the file to PDF using Aspose.Cells version 25.9.0.

I have tried all possible fixes mentioned above, but the issue persists in all cases. Please

@tarangtbs

It seems you’re experiencing intermittent issues with text and shapes missing during the conversion of ODS files to PDF using Aspose.Cells version 25.9.0. This can occur, particularly when the ODS files were originally created in XLSX format and then saved as ODS.

Here are some suggestions to troubleshoot and potentially resolve the issue:

  1. Update Aspose.Cells: Ensure you are using the latest version of Aspose.Cells, as updates often include bug fixes and improvements that could resolve your issue.

  2. Check for Corruption: Files saved in different formats can sometimes become corrupted. Open the ODS file in LibreOffice or OpenOffice and re-save it to see if that resolves the issue.

  3. Use Different PDF Save Options: Experiment with different settings in PdfSaveOptions. For example, try adjusting the OptimizationType or Compliance settings to see if that affects the output.

  4. Evaluate Shapes and Text Separately: If the issue persists, consider separating the conversion of shapes and text. You could first convert the text to PDF and then overlay the shapes using a different method.

  5. Debugging: Implement logging to identify which shapes or text are missing during the conversion process. This may help pinpoint specific elements causing the issue.

  6. Contact Support: If none of the above solutions work, consider reaching out to Aspose support with a sample file that reproduces the issue. They may provide more targeted assistance.

If you need further assistance or specific code examples, feel free to ask!

@tarangtbs
Please share your template files ? We will check them ASAP.
If the worksheet contains shapes, please use Cells.MaxDisplayRange to get max row and colum.