We're sorry Aspose doesn't work properply without JavaScript enabled.

Free Support Forum - aspose.com

Why is Aspose.Cells cutting off the top half of my text when I export to PDF (or TIFF or XPS)?

I'm using Aspose.Cells to create a report to be exported to both Excel and PDF. In cell A1, I have some text that I've given a font size of 20. When I save this workbook to a PDF file, the top half of the text is getting cut off.

Here's a screenshot of the PDF file.

I tried adjusting the height of the first row using AutoFitRow(int), but that's not fixing my problem. My code to reproduce this is very short:

static void Main(string[] args)
{
    Program.Licenses(); //only sets licenses
</span><span class="kwd" style="margin: 0px; padding: 0px; border: 0px; font-size: 13.63636302947998px; vertical-align: baseline; color: rgb(0, 0, 139); background: transparent;">var</span><span class="pln" style="margin: 0px; padding: 0px; border: 0px; font-size: 13.63636302947998px; vertical-align: baseline; background: transparent;"> wb </span><span class="pun" style="margin: 0px; padding: 0px; border: 0px; font-size: 13.63636302947998px; vertical-align: baseline; background: transparent;">=</span><span class="pln" style="margin: 0px; padding: 0px; border: 0px; font-size: 13.63636302947998px; vertical-align: baseline; background: transparent;"> </span><span class="kwd" style="margin: 0px; padding: 0px; border: 0px; font-size: 13.63636302947998px; vertical-align: baseline; color: rgb(0, 0, 139); background: transparent;">new</span><span class="pln" style="margin: 0px; padding: 0px; border: 0px; font-size: 13.63636302947998px; vertical-align: baseline; background: transparent;"> </span><span class="typ" style="margin: 0px; padding: 0px; border: 0px; font-size: 13.63636302947998px; vertical-align: baseline; color: rgb(43, 145, 175); background: transparent;">Aspose</span><span class="pun" style="margin: 0px; padding: 0px; border: 0px; font-size: 13.63636302947998px; vertical-align: baseline; background: transparent;">.</span><span class="typ" style="margin: 0px; padding: 0px; border: 0px; font-size: 13.63636302947998px; vertical-align: baseline; color: rgb(43, 145, 175); background: transparent;">Cells</span><span class="pun" style="margin: 0px; padding: 0px; border: 0px; font-size: 13.63636302947998px; vertical-align: baseline; background: transparent;">.</span><span class="typ" style="margin: 0px; padding: 0px; border: 0px; font-size: 13.63636302947998px; vertical-align: baseline; color: rgb(43, 145, 175); background: transparent;">Workbook</span><span class="pun" style="margin: 0px; padding: 0px; border: 0px; font-size: 13.63636302947998px; vertical-align: baseline; background: transparent;">();</span><span class="pln" style="margin: 0px; padding: 0px; border: 0px; font-size: 13.63636302947998px; vertical-align: baseline; background: transparent;">
</span><span class="kwd" style="margin: 0px; padding: 0px; border: 0px; font-size: 13.63636302947998px; vertical-align: baseline; color: rgb(0, 0, 139); background: transparent;">var</span><span class="pln" style="margin: 0px; padding: 0px; border: 0px; font-size: 13.63636302947998px; vertical-align: baseline; background: transparent;"> ws </span><span class="pun" style="margin: 0px; padding: 0px; border: 0px; font-size: 13.63636302947998px; vertical-align: baseline; background: transparent;">=</span><span class="pln" style="margin: 0px; padding: 0px; border: 0px; font-size: 13.63636302947998px; vertical-align: baseline; background: transparent;"> wb</span><span class="pun" style="margin: 0px; padding: 0px; border: 0px; font-size: 13.63636302947998px; vertical-align: baseline; background: transparent;">.</span><span class="typ" style="margin: 0px; padding: 0px; border: 0px; font-size: 13.63636302947998px; vertical-align: baseline; color: rgb(43, 145, 175); background: transparent;">Worksheets</span><span class="pun" style="margin: 0px; padding: 0px; border: 0px; font-size: 13.63636302947998px; vertical-align: baseline; background: transparent;">[</span><span class="lit" style="margin: 0px; padding: 0px; border: 0px; font-size: 13.63636302947998px; vertical-align: baseline; color: rgb(128, 0, 0); background: transparent;">0</span><span class="pun" style="margin: 0px; padding: 0px; border: 0px; font-size: 13.63636302947998px; vertical-align: baseline; background: transparent;">];</span><span class="pln" style="margin: 0px; padding: 0px; border: 0px; font-size: 13.63636302947998px; vertical-align: baseline; background: transparent;">
</span><span class="kwd" style="margin: 0px; padding: 0px; border: 0px; font-size: 13.63636302947998px; vertical-align: baseline; color: rgb(0, 0, 139); background: transparent;">var</span><span class="pln" style="margin: 0px; padding: 0px; border: 0px; font-size: 13.63636302947998px; vertical-align: baseline; background: transparent;"> cell </span><span class="pun" style="margin: 0px; padding: 0px; border: 0px; font-size: 13.63636302947998px; vertical-align: baseline; background: transparent;">=</span><span class="pln" style="margin: 0px; padding: 0px; border: 0px; font-size: 13.63636302947998px; vertical-align: baseline; background: transparent;"> ws</span><span class="pun" style="margin: 0px; padding: 0px; border: 0px; font-size: 13.63636302947998px; vertical-align: baseline; background: transparent;">.</span><span class="typ" style="margin: 0px; padding: 0px; border: 0px; font-size: 13.63636302947998px; vertical-align: baseline; color: rgb(43, 145, 175); background: transparent;">Cells</span><span class="pun" style="margin: 0px; padding: 0px; border: 0px; font-size: 13.63636302947998px; vertical-align: baseline; background: transparent;">[</span><span class="lit" style="margin: 0px; padding: 0px; border: 0px; font-size: 13.63636302947998px; vertical-align: baseline; color: rgb(128, 0, 0); background: transparent;">0</span><span class="pun" style="margin: 0px; padding: 0px; border: 0px; font-size: 13.63636302947998px; vertical-align: baseline; background: transparent;">,</span><span class="pln" style="margin: 0px; padding: 0px; border: 0px; font-size: 13.63636302947998px; vertical-align: baseline; background: transparent;"> </span><span class="lit" style="margin: 0px; padding: 0px; border: 0px; font-size: 13.63636302947998px; vertical-align: baseline; color: rgb(128, 0, 0); background: transparent;">0</span><span class="pun" style="margin: 0px; padding: 0px; border: 0px; font-size: 13.63636302947998px; vertical-align: baseline; background: transparent;">];</span><span class="pln" style="margin: 0px; padding: 0px; border: 0px; font-size: 13.63636302947998px; vertical-align: baseline; background: transparent;">

cell</span><span class="pun" style="margin: 0px; padding: 0px; border: 0px; font-size: 13.63636302947998px; vertical-align: baseline; background: transparent;">.</span><span class="typ" style="margin: 0px; padding: 0px; border: 0px; font-size: 13.63636302947998px; vertical-align: baseline; color: rgb(43, 145, 175); background: transparent;">Value</span><span class="pln" style="margin: 0px; padding: 0px; border: 0px; font-size: 13.63636302947998px; vertical-align: baseline; background: transparent;"> </span><span class="pun" style="margin: 0px; padding: 0px; border: 0px; font-size: 13.63636302947998px; vertical-align: baseline; background: transparent;">=</span><span class="pln" style="margin: 0px; padding: 0px; border: 0px; font-size: 13.63636302947998px; vertical-align: baseline; background: transparent;"> </span><span class="str" style="margin: 0px; padding: 0px; border: 0px; font-size: 13.63636302947998px; vertical-align: baseline; color: rgb(128, 0, 0); background: transparent;">"Text is cutoff"</span><span class="pun" style="margin: 0px; padding: 0px; border: 0px; font-size: 13.63636302947998px; vertical-align: baseline; background: transparent;">;</span><span class="pln" style="margin: 0px; padding: 0px; border: 0px; font-size: 13.63636302947998px; vertical-align: baseline; background: transparent;">

</span><span class="kwd" style="margin: 0px; padding: 0px; border: 0px; font-size: 13.63636302947998px; vertical-align: baseline; color: rgb(0, 0, 139); background: transparent;">var</span><span class="pln" style="margin: 0px; padding: 0px; border: 0px; font-size: 13.63636302947998px; vertical-align: baseline; background: transparent;"> style </span><span class="pun" style="margin: 0px; padding: 0px; border: 0px; font-size: 13.63636302947998px; vertical-align: baseline; background: transparent;">=</span><span class="pln" style="margin: 0px; padding: 0px; border: 0px; font-size: 13.63636302947998px; vertical-align: baseline; background: transparent;"> cell</span><span class="pun" style="margin: 0px; padding: 0px; border: 0px; font-size: 13.63636302947998px; vertical-align: baseline; background: transparent;">.</span><span class="typ" style="margin: 0px; padding: 0px; border: 0px; font-size: 13.63636302947998px; vertical-align: baseline; color: rgb(43, 145, 175); background: transparent;">GetStyle</span><span class="pun" style="margin: 0px; padding: 0px; border: 0px; font-size: 13.63636302947998px; vertical-align: baseline; background: transparent;">();</span><span class="pln" style="margin: 0px; padding: 0px; border: 0px; font-size: 13.63636302947998px; vertical-align: baseline; background: transparent;">
style</span><span class="pun" style="margin: 0px; padding: 0px; border: 0px; font-size: 13.63636302947998px; vertical-align: baseline; background: transparent;">.</span><span class="typ" style="margin: 0px; padding: 0px; border: 0px; font-size: 13.63636302947998px; vertical-align: baseline; color: rgb(43, 145, 175); background: transparent;">Font</span><span class="pun" style="margin: 0px; padding: 0px; border: 0px; font-size: 13.63636302947998px; vertical-align: baseline; background: transparent;">.</span><span class="typ" style="margin: 0px; padding: 0px; border: 0px; font-size: 13.63636302947998px; vertical-align: baseline; color: rgb(43, 145, 175); background: transparent;">Size</span><span class="pln" style="margin: 0px; padding: 0px; border: 0px; font-size: 13.63636302947998px; vertical-align: baseline; background: transparent;"> </span><span class="pun" style="margin: 0px; padding: 0px; border: 0px; font-size: 13.63636302947998px; vertical-align: baseline; background: transparent;">=</span><span class="pln" style="margin: 0px; padding: 0px; border: 0px; font-size: 13.63636302947998px; vertical-align: baseline; background: transparent;"> </span><span class="lit" style="margin: 0px; padding: 0px; border: 0px; font-size: 13.63636302947998px; vertical-align: baseline; color: rgb(128, 0, 0); background: transparent;">20</span><span class="pun" style="margin: 0px; padding: 0px; border: 0px; font-size: 13.63636302947998px; vertical-align: baseline; background: transparent;">;</span><span class="pln" style="margin: 0px; padding: 0px; border: 0px; font-size: 13.63636302947998px; vertical-align: baseline; background: transparent;">
cell</span><span class="pun" style="margin: 0px; padding: 0px; border: 0px; font-size: 13.63636302947998px; vertical-align: baseline; background: transparent;">.</span><span class="typ" style="margin: 0px; padding: 0px; border: 0px; font-size: 13.63636302947998px; vertical-align: baseline; color: rgb(43, 145, 175); background: transparent;">SetStyle</span><span class="pun" style="margin: 0px; padding: 0px; border: 0px; font-size: 13.63636302947998px; vertical-align: baseline; background: transparent;">(</span><span class="pln" style="margin: 0px; padding: 0px; border: 0px; font-size: 13.63636302947998px; vertical-align: baseline; background: transparent;">style</span><span class="pun" style="margin: 0px; padding: 0px; border: 0px; font-size: 13.63636302947998px; vertical-align: baseline; background: transparent;">);</span><span class="pln" style="margin: 0px; padding: 0px; border: 0px; font-size: 13.63636302947998px; vertical-align: baseline; background: transparent;">

ws</span><span class="pun" style="margin: 0px; padding: 0px; border: 0px; font-size: 13.63636302947998px; vertical-align: baseline; background: transparent;">.</span><span class="typ" style="margin: 0px; padding: 0px; border: 0px; font-size: 13.63636302947998px; vertical-align: baseline; color: rgb(43, 145, 175); background: transparent;">AutoFitRow</span><span class="pun" style="margin: 0px; padding: 0px; border: 0px; font-size: 13.63636302947998px; vertical-align: baseline; background: transparent;">(</span><span class="lit" style="margin: 0px; padding: 0px; border: 0px; font-size: 13.63636302947998px; vertical-align: baseline; color: rgb(128, 0, 0); background: transparent;">1</span><span class="pun" style="margin: 0px; padding: 0px; border: 0px; font-size: 13.63636302947998px; vertical-align: baseline; background: transparent;">);</span><span class="pln" style="margin: 0px; padding: 0px; border: 0px; font-size: 13.63636302947998px; vertical-align: baseline; background: transparent;"> </span><span class="com" style="margin: 0px; padding: 0px; border: 0px; font-size: 13.63636302947998px; vertical-align: baseline; color: rgb(128, 128, 128); background: transparent;">//doesn't prevent text cutoff</span><span class="pln" style="margin: 0px; padding: 0px; border: 0px; font-size: 13.63636302947998px; vertical-align: baseline; background: transparent;">

wb</span><span class="pun" style="margin: 0px; padding: 0px; border: 0px; font-size: 13.63636302947998px; vertical-align: baseline; background: transparent;">.</span><span class="typ" style="margin: 0px; padding: 0px; border: 0px; font-size: 13.63636302947998px; vertical-align: baseline; color: rgb(43, 145, 175); background: transparent;">Save</span><span class="pun" style="margin: 0px; padding: 0px; border: 0px; font-size: 13.63636302947998px; vertical-align: baseline; background: transparent;">(</span><span class="str" style="margin: 0px; padding: 0px; border: 0px; font-size: 13.63636302947998px; vertical-align: baseline; color: rgb(128, 0, 0); background: transparent;">@"C:\Users\guest\Desktop\file2.pdf"</span><span class="pun" style="margin: 0px; padding: 0px; border: 0px; font-size: 13.63636302947998px; vertical-align: baseline; background: transparent;">,</span><span class="pln" style="margin: 0px; padding: 0px; border: 0px; font-size: 13.63636302947998px; vertical-align: baseline; background: transparent;"> </span><span class="typ" style="margin: 0px; padding: 0px; border: 0px; font-size: 13.63636302947998px; vertical-align: baseline; color: rgb(43, 145, 175); background: transparent;">Aspose</span><span class="pun" style="margin: 0px; padding: 0px; border: 0px; font-size: 13.63636302947998px; vertical-align: baseline; background: transparent;">.</span><span class="typ" style="margin: 0px; padding: 0px; border: 0px; font-size: 13.63636302947998px; vertical-align: baseline; color: rgb(43, 145, 175); background: transparent;">Cells</span><span class="pun" style="margin: 0px; padding: 0px; border: 0px; font-size: 13.63636302947998px; vertical-align: baseline; background: transparent;">.</span><span class="typ" style="margin: 0px; padding: 0px; border: 0px; font-size: 13.63636302947998px; vertical-align: baseline; color: rgb(43, 145, 175); background: transparent;">SaveFormat</span><span class="pun" style="margin: 0px; padding: 0px; border: 0px; font-size: 13.63636302947998px; vertical-align: baseline; background: transparent;">.</span><span class="typ" style="margin: 0px; padding: 0px; border: 0px; font-size: 13.63636302947998px; vertical-align: baseline; color: rgb(43, 145, 175); background: transparent;">Pdf</span><span class="pun" style="margin: 0px; padding: 0px; border: 0px; font-size: 13.63636302947998px; vertical-align: baseline; background: transparent;">);</span><span class="pln" style="margin: 0px; padding: 0px; border: 0px; font-size: 13.63636302947998px; vertical-align: baseline; background: transparent;">

}

What am I doing wrong that is causing the top half of my text to be cutoff? the text is also getting cut off if I export to Tiff or XPS. It looks fine however if I export to XLSX.

Version Information:

  • Aspose.Cells.DLL: Runtime Version = v2.0.50727, Version = 8.1.2.0
  • Aspose.Pdf.DLL: Runtime Version = v4.0.30319, Version 9.5.0.0



Hi Jordan,


Thank you for contacting Aspose support.

Please change the ws.AutoFitRow(1) to ws.AutoFitRow(0), it should produce the correct results. Actually Aspose.Cells.Rows has zero based index, so when you wish to perform autoFitRow on the first row, you have to pass 0 to the method.

Hope this helps.

That did it. Thanks. Somehow I remembered that the indexes are 0-based when setting the ws.Cells[0,0].Value, but I forgot that when calling AutoFitRow. I’m used to using the Microsoft.Office.Interop.Excel code and cell references there are 1-based.


Edit: I had an additional problem in my actual code that was also causing the text to be cutoff in the same way. When auto-fitting, I needed to set a flag to turn on AutoFitMergedCells. I can do that with a call to this:

ws.AutoFitRow(0, 0, 1, new Aspose.Cells.AutoFitterOptions() { AutoFitMergedCells = true });

Hi,


Good to know that it sorts out your original issue for Auto-fitting rows by putting the correct index for the row.

For your other issue, yes, you are doing fine to set the AutoFitMergedCells option on in AutoFitterOptions to auto-fit row(s) by using it. This option is useful when there are some cells in the row(s), so it will take care of it when auto-fitting the row(s).

Feel free to contact us any time if you have any other issue or queries, we will be happy to assist you soon.

Thank you.