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