Free Support Forum - aspose.com

How to create text directly in a PDF

The question was asked. “How do I create text directly in a PDF”. The only method used in the sample is the BindtoXML method. Here is the start of my code:



//create a new pdf object

Pdf mypdf = new Pdf();

//create a new section within the pdf object

Section mysection = new Section(mypdf);

//create a new paragraph object

Paragraph myparagraph = new Paragraph();

myparagraph



Neither the Paragraph nor the Section object have properties or methods to add text directly to them.

Dear user ,

Thanks for your consideration.

Paragraph is an abstract class. You should use Text class if you want to create text in PDF.

Here is an example:

Pdf pdf = new Pdf();

Section section = new Section(pdf);
pdf.Sections.Add(section);

Text text1 = new Text(section);
text1.Margin.Top = 30;
section.Paragraphs.Add(text1);

Segment segment1 = new Segment(text1);
text1.Segments.Add(segment1);
segment1.Content = “this is text content”;

pdf.Save(…);