I am writing a simple program on CSharp. What it does, is that you write a text(in a richTextBox), and it saves it's content on a .pdf in a specific path. Now, i want the user to target a specific word/phrase, and by clicking a button, the specific word/phrase will go bold. Is this possible ?? And if yes, how ??
Asked
Active
Viewed 1,795 times
0
-
Have you seen this? http://stackoverflow.com/questions/3497124/itextsharp-textfield-setting-the-font-to-bold Looks like changing the font name might help – Volkan Paksoy Feb 09 '16 at 16:04
-
I don't want to make all the phrase bold. I whant the user to specify which words will go bold. – Feb 09 '16 at 16:24
2 Answers
1
First of all check this out : http://www.mikesdotnetting.com/article/81/itextsharp-working-with-fonts
What basically you need to do is to call the SetFieldProperty function You take your old pdf, edit it and out put a new PDF with a bolded textbox.
MemoryStream stream = new MemoryStream(); //Memory stream to with new pdf with changed bold text
PdfReader pdfReader = new PdfReader("file.pdf"); //The original PDF
PdfStamper stamper = new PdfStamper(pdfReader, stream); //A stamper to create the pdf
SetFieldProperty("fieldName","textfont",BaseFont.COURIER_BOLD,null); //Change textbox properties
SetField("fieldName","TEXT"); //Change field text
stamper.Close(); //Save and close
byte[] newFile = stream.ToArray(); //Here you have your new file with the bolded text
This code will give you a new file with the bolded text

misha130
- 5,457
- 2
- 29
- 51
-
-
-
You may want to go to the basics and read this: http://developers.itextpdf.com/examples/itext-action-second-edition/chapter-8 – misha130 Feb 09 '16 at 17:54
0
I think you can input an html to itextsharp. This way you can control many styling attributes using html. for ex: This is bold text. can be input as :
This is <b>bold</b> text.
You can use Html to customize the styling and color of the text like this. Although I haven't tried using external stylesheets using itextsharp, but the inline styling works fine.

user1849310
- 491
- 6
- 10