Results 1 to 3 of 3

Thread: [RESOLVED] Change Paragraph Font using ItextSharp

  1. #1

    Thread Starter
    Frenzied Member toecutter's Avatar
    Join Date
    Apr 2006
    Location
    Brisbane, Australia
    Posts
    1,160

    Resolved [RESOLVED] Change Paragraph Font using ItextSharp

    I have tried many examples found from Google without a lot of luck.

    I have below but cannot implement without getting "System.InvalidCastException: 'Conversion from string "Report by: Some Text" to type 'Integer' is not valid.'" and do not understand why it is wanting to convert to Integer.

    ERROR ON THIS LINE:
    Code:
     pdfParagraph.Add("Report by: Some Text", Ffont)
    Code:
     Dim pdfFont As BaseFont = BaseFont.CreateFont("c:\windows\fonts\Arial.ttf", BaseFont.IDENTITY_H, True)
            Dim Ffont As New iTextSharp.text.Font(pdfFont, 8, iTextSharp.text.Font.NORMAL)
            'pdfParagraph.Add(Ffont)
            'Dim pdfFont As iTextSharp.text.Font = New Font(FontFactory.GetFont(FontFactory.TIMES_ROMAN, 8.0F, Font.Bold, BaseColor.BLACK))
            pdfParagraph.Add("Report by: Some Text", Ffont)
            pdfDoc.Add(pdfParagraph)
    Attached Images Attached Images  

  2. #2
    Super Moderator Shaggy Hiker's Avatar
    Join Date
    Aug 2002
    Location
    Idaho
    Posts
    40,109

    Re: Change Paragraph Font using ItextSharp

    It looks like something is missing, but you probably just didn't include it in the code you posted. What you showed doesn't show you creating the paragraph, but you probably did.

    There are so many variants out there around this subject, but you might try something like this:
    Code:
      paragraph.Font = font
       paragraph.Add(content)
    In other words, add the font in one step, then add the content in the next. I found things that suggest that what you are doing should work, but like I said, there seem to be loads of slightly different variants out there.
    My usual boring signature: Nothing

  3. #3

    Thread Starter
    Frenzied Member toecutter's Avatar
    Join Date
    Apr 2006
    Location
    Brisbane, Australia
    Posts
    1,160

    Re: Change Paragraph Font using ItextSharp

    perfect, thx Shags...

    Code:
     Dim pdfFont As BaseFont = BaseFont.CreateFont("c:\windows\fonts\Arial.ttf", BaseFont.IDENTITY_H, True)
            Dim Ffont As New iTextSharp.text.Font(pdfFont, 8, iTextSharp.text.Font.NORMAL)
            pdfParagraph.Font = Ffont
            pdfParagraph.Add("Report by: Some text")
            pdfDoc.Add(pdfParagraph)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width