PDFsharp & MigraDoc Forum

PDFsharp - A .NET library for processing PDF & MigraDoc - Creating documents on the fly
It is currently Sat Nov 01, 2025 4:12 pm

All times are UTC


Forum rules


Please read this before posting on this forum: Forum Rules

Also see our new Tailored Support & Services site.



Post new topic Reply to topic  [ 4 posts ] 
Author Message
 Post subject: Get text of a Paragraph
PostPosted: Mon Feb 03, 2014 4:27 pm 
Offline

Joined: Fri Dec 14, 2012 10:28 am
Posts: 9
Hi there,
I'm trying to get the text set in a paragraph. I set the text this way:

Code:
parContent = cellContent.AddParagraph("Project manager:")


and I'm looking for a property like:

Code:
parContent.text


or something that returns me "Project manager:".

Thank you!


Top
 Profile  
Reply with quote  
PostPosted: Mon Feb 03, 2014 4:52 pm 
Offline
PDFsharp Guru
User avatar

Joined: Mon Oct 16, 2006 8:16 am
Posts: 3136
Location: Cologne, Germany
Hi!
In this code snippet, row is a table row:
Code:
Paragraph p = row.Cells[cell].Elements[idxElement] as Paragraph;
if (p != null && p.Elements.Count > 0)
{
    Text t = p.Elements.First as Text;
    if (t != null)
    {
        return t;
    }
}

Elements can contain other objects (e.g. FormattedText).
If you only call "AddParagraph(string)" and only once for each cell, then the code above will work (set idxElement to 0).

_________________
Regards
Thomas Hoevel
PDFsharp Team


Top
 Profile  
Reply with quote  
PostPosted: Tue Feb 04, 2014 9:42 am 
Offline

Joined: Fri Dec 14, 2012 10:28 am
Posts: 9
Hey, I'm sorry, I didn't realize that "cellContent" was in my snippet and that's why I didn't clarify where does actually come from, and you had to figure it out.

Anyway, your snippet works for me. I just added a

Code:
t.Content


to get the string. One more question, will it be the same if instead of adding the paragraph to a table cell I add it to a document section and with a predefined style? Like:

Code:
paragraphDesc = section.AddParagraph("Project description", "MyHeading2")


Where section is a Section of the Document. And "MyHeading2" an already definded style.

Thank you very much.


Top
 Profile  
Reply with quote  
PostPosted: Tue Feb 04, 2014 9:55 am 
Offline
PDFsharp Guru
User avatar

Joined: Mon Oct 16, 2006 8:16 am
Posts: 3136
Location: Cologne, Germany
Section or Cell - both have member Elements with the Paragraphs etc.

_________________
Regards
Thomas Hoevel
PDFsharp Team


Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 4 posts ] 

All times are UTC


Who is online

Users browsing this forum: Baidu [Spider] and 124 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Privacy Policy, Data Protection Declaration, Impressum
Powered by phpBB® Forum Software © phpBB Group