Jacob Lenertz
Jacob Lenertz

Reputation: 81

Column Text Wont change Font type

I am trying to change the font of the Column text, but it wont work and I am not getting any errors. The text is showing up on the pdf, but it is not the text style that I changed it to. Can anyone point out what is wrong?

I have looked on other questions like mine and they all are given the setfontandsize. Also im not getting a error on the null reference or anything like that.

The Custom font does have a value linked to the correct file.

private void btn_print_Click(object sender, EventArgs e)
{
    PdfReader reader = new PdfReader(@"C:\Users\jacob\Documents\test\3.pdf"); 

    PdfStamper stamper = new PdfStamper(reader, new FileStream(@"C:\Users\jacob\Documents\test\12).pdf", FileMode.Create));
    int x = reader.NumberOfPages;
    int[] a = Enumerable.Range(1,x).ToArray();

    foreach (int n in a)
    {
        BaseFont customfont = FontFactory.GetFont(@"C:\Windows\Fonts\bgothm.ttf", BaseFont.CP1252, true).BaseFont;
        PdfContentByte canvas = stamper.GetOverContent(n); 

        canvas.SetFontAndSize(customfont, 12);
        ColumnText.ShowTextAligned(canvas, Element.ALIGN_LEFT, new Phrase("nooooo"), 36, 540, 0);
    }
    stamper.Close();
} 

Upvotes: 0

Views: 246

Answers (1)

mkl
mkl

Reputation: 95918

ColumnText.ShowTextAligned does not use the current font of the canvas. Instead it uses the font its Phrase argument brings along; as you don't set any specific font to your Phrase, some simple default font is used.

To use the font of your choice, do

ColumnText.ShowTextAligned(canvas, Element.ALIGN_LEFT, new Phrase("nooooo", new Font(customfont, 12)), 36, 54, 0);

instead.

Upvotes: 1

Related Questions