Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to render PdfContentByte like chunk in iTextSharp

Tags:

c#

itext

In case of Chunk we could specify the text and the font which is to be used. For example we can set bold and font size in case of Chunk. While in case of PdfContentByte I am trying to set the text in bold for

PdfContentByte cb = writer.DirectContent;
cb.ShowTextAligned(PdfContentByte.ALIGN_CENTER,"INVOICE",386,596, 0);

using

cb.SetTextRenderingMode(PdfContentByte.TEXT_RENDER_MODE_FILL_STROKE);

But the text being rendered is too Black, is there any way to render the text as that of Chunk to use a font like

 Font contentBoldHead = FontFactory.GetFont("Arial-BoldMT", 14, Font.BOLD);

in the PdfContentByte.

Any suggestions would be really helping.

like image 741
Vinay Avatar asked Dec 22 '22 06:12

Vinay


1 Answers

Just to add to what @calum said, the solution is to just use a bold font. SetTextRenderingMode creates a faux bold which is why it looks bad to you.

cb.SetFontAndSize(FontFactory.GetFont(FontFactory.HELVETICA_BOLD).BaseFont, 20);
cb.BeginText();
cb.ShowTextAligned(PdfContentByte.ALIGN_CENTER, "INVOICE", 386, 596, 0);
cb.EndText();
like image 74
Chris Haas Avatar answered Dec 28 '22 09:12

Chris Haas