To achieve a thicker underline for the bold text in your PDF generated with iTextSharp/RazorPDF, use a bottom border instead of text-decoration: underline. This gives you control over the underline's thickness. Here's the solution:
Step 1: Update Your CSS
Replace text-decoration: underline with a custom bottom border on a <span> inside the cell:
<style>
.fixedfor {
font-weight: bold;
font-size: 1.1em;
padding-bottom: 3px; /* Space between text and underline */
}
.fixedfor .thick-underline {
border-bottom: 2px solid black; /* Adjust thickness (2px) and color */
display: inline-block; /* Contain underline to text width */
line-height: 1.2em; /* Adjust vertical alignment */
}
</style>
Step 2: Wrap Text in a <span> with the Underline Class
Modify your HTML to include the <span>:
<table width="100%" cellpadding="6" cellspacing="0">
<tr>
<td class="fixedfor">
<span class="thick-underline">For @Model.FixedForName</span>
</td>
</tr>
</table>
Key Changes & Why:
-
Thickness Control
border-bottom: 2px solid black creates an underline whose thickness you control via 2px (increase for a bolder line).
-
Inline-Block Display
display: inline-block ensures the underline spans only the text width, not the full cell.
-
Spacing Adjustment
padding-bottom: 3px adds space between the text and the underline. Adjust as needed.
-
Line Height
line-height: 1.2em prevents vertical clipping of the underline.
Troubleshooting:
-
Underline Too Wide?
Ensure the <span> uses display: inline-block (not block).
-
Alignment Issues?
Adjust line-height and padding-bottom values until the position looks correct.
-
PDF Rendering Problems?
iTextSharp has limited CSS support. Stick to basic properties like border, padding, and display.
This approach reliably generates a thick underline for bold text in PDFs.