Rich Text Content Fields with iTextSharp

I use iTextSharp to create PDF files on the fly so that my users can save them on their computers. Currently, it works so that I had several PDF templates that iTextSharp opens, sets fields from the database, and saves them on the user's computer.

I'm having real problems adding rich content to the body field that users enter using the Rich Text editor (NiceEdit). It contains really simple options, such as bullets, bold, italics, font color, sizes, etc., which is all they need. I tried all possible options, but nothing helped.

PdfReader reader = new PdfReader(originalReport.ToString());

PdfStamper stamper = new PdfStamper(reader, new FileStream(report, FileMode.Create));
AcroFields fields = stamper.AcroFields;

fields.SetFieldProperty("body", "setfflags", PdfFormField.FF_RICHTEXT, null);
fields.SetFieldRichValue("body", bodyValue.ToString());

fields.GenerateAppearances = false;

I tried to flatten the form, but it does not display the field at all. If I did not smooth the form, then the field displays the content, but without the format at all (even new lines are deleted), and if I used the SetField parameter instead of SetFieldRichValue, I get the html content line

I also tried to allow the PDF template field "Allow Rich Text" from acrobat pro, but this gives an exception and stops the PDF :)

Also note that since I use a template that depends on the type of user, the SetField option is used, I do not create the document from scratch, so I do not use the paragraphs that I can get if I used HTMLWorker and just add to the document

Any help please?

+5
source share

All Articles