Set PDF global textinfo

I am currently using the trial version of Aspose PDF and have a bunch of question. To keep it simple, I will only ask one: How do you set a global textinfo object for the entire PDF, so that all child items inherit from that. I find it hard to believe that you would be required to explicitly set the textinfo on every “element” on the page?


I have attempted:

Aspose.Pdf.Generator.Pdf pdf = new Aspose.Pdf.Generator.Pdf();
pdf.TextInfo = new Aspose.Pdf.Generator.TextInfo
{
FontSize = 40f,
FontName = “Courier”,
Color = new Aspose.Pdf.Generator.Color(255,0,0)
};

I have also attempted to set it on a section level:

Aspose.Pdf.Generator.Section spcSection = new Aspose.Pdf.Generator.Section();

spcSection.TextInfo = new Aspose.Pdf.Generator.TextInfo
{
FontSize = 40f,
FontName = “Courier”,
Color = new Aspose.Pdf.Generator.Color(255, 0, 0)
};

…And nothing changes.

Please advise

… and I am a moron. You need to ensure you specify the parent element properly as you create children:


http://www.aspose.com/docs/display/pdfnet/Text+Formatting

To obtain desired results with minimum effort, you just need to set the text format settings for the [Section] object. And the newly created [Text] paragraphs can inherit text format settings from the Section Class created before. For this, it is must for the [Text] paragraphs to be created by calling one of the overloaded constructors of [Text] class that takes a [Section] instance as parameter to inherit its settings.”

Hi Andrew,


nokturnal:
I am currently using the trial version of Aspose PDF and have a bunch of question. To keep it simple, I will only ask one: How do you set a global textinfo object for the entire PDF, so that all child items inherit from that. I find it hard to believe that you would be required to explicitly set the textinfo on every "element" on the page?

I have attempted:

Aspose.Pdf.Generator.Pdf pdf = new Aspose.Pdf.Generator.Pdf();
pdf.TextInfo = new Aspose.Pdf.Generator.TextInfo
{
FontSize = 40f,
FontName = "Courier",
Color = new Aspose.Pdf.Generator.Color(255,0,0)
};

I have also attempted to set it on a section level:

Aspose.Pdf.Generator.Section spcSection = new Aspose.Pdf.Generator.Section();

spcSection.TextInfo = new Aspose.Pdf.Generator.TextInfo
{
FontSize = 40f,
FontName = "Courier",
Color = new Aspose.Pdf.Generator.Color(255, 0, 0)
};

...And nothing changes.

Please advise

Thanks for your inquiry. It is recommend to use new generator(Aspose.Pdf) as it is more improved and efficient than old generator(Aspose.Pdf.Generator). Using new generator you can not only create a PDF from scratch but also manipulate/edit existing PDF documents. Moreover, we are not fixing any issues in old generator any more and it will be obsolete in near future.

Please check how you can set default TextState for the PDF document in new generator.

TextState textState = new TextState();

textState.Font = FontRepository.FindFont("Arial", FontStyles.Bold);

Document doc = new Document();

doc.PageInfo.DefaultTextState = textState;

Page page = doc.Pages.Add();

page.Paragraphs.Add(new TextFragment("Some bold arial text"));

doc.Save(outFile);

Please feel free to contact us for any further assistance.


Best Regards,

Hi Andrew,

nokturnal:
... and I am a moron. You need to ensure you specify the parent element properly as you create children:


"To obtain desired results with minimum effort, you just need to set the text format settings for the [Section] object. And the newly created [Text] paragraphs can inherit text format settings from the Section Class created before. For this, it is must for the [Text] paragraphs to be created by calling one of the overloaded constructors of [Text] class that takes a [Section] instance as parameter to inherit its settings."

It is good to know that you have managed to resolve your issue in old generator(Aspose.Pdf.Generator). As stated above, it is recommended to use new generator(Aspose.Pdf) instead old generator.

We are sorry for the inconvenience.

Best Regards,