Chris B
Chris B

Reputation: 15

How to get textbox's value and turning into PDF format with itextsharp?

I'm coming with a question, and I wish someone could answer to it.
I can't convert the string value of my textbox to put it in a PDF File Format.
I got an error, something like:

impossible to convert string to iTextSharp.Text.IElement...

I tried to cast it but it doesn't work.

So, my question, how to do to put my value into my PDF File Format?

Here is a bit of my code:

string adresseProf = adProf.Text;
Document doc = new Document(PageSize.A4, 10f, 20f, 20f, 10f);
doc.Open();
doc.Add(adresseProf); //I tried something like : doc.Add((IElement)adresseProf);

Upvotes: 0

Views: 393

Answers (1)

mkl
mkl

Reputation: 95918

The iText 5 Document class has only one Add method,

public virtual bool Add(IElement element) 

and there is no IElement operator allowing implicit or explicit casting of a string to an IElement.

Thus, you cannot simply call doc.Add(adresseProf) and expect that to work. What you can do instead, though, is look for an IElement implementation that can be used to wrap your string.

One candidate is the Paragraph class which implements IElement and has a constructor taking a single string parameter:

public Paragraph(string str)

So you can write the following in your code

doc.Add(new Paragraph(adresseProf));

Upvotes: 1

Related Questions