PDFsharp & MigraDoc Foundation

PDFsharp - A .NET library for processing PDF & MigraDoc Foundation - Creating documents on the fly
It is currently Sun Jul 14, 2024 7:03 pm

All times are UTC


Forum rules


Please read this before posting on this forum: Forum Rules



Post new topic Reply to topic  [ 4 posts ] 
Author Message
PostPosted: Wed Aug 27, 2014 8:20 am 
Offline

Joined: Wed Aug 27, 2014 8:06 am
Posts: 3
I want to remove a paragraph / table from a migradoc document?

Consider the situation below :
I have para1 , para2 , para3. Whether para2 will be displayed or not is determined by the calculations done while determining para3. So I need to do something like the following :

DetermineContent_of_Para1();
Document.addpara(para1);

DetermineContent_of_Para2();
Document.addpara(para2);

DetermineContent_of_Para3();
Document.addpara(para3);

If(!displayPara2)
{
Document.removepara(para2);
}

Is there any such option like removePara() in migradoc or an alternative which achieves the above requirement?

Thank You


Top
 Profile  
Reply with quote  
PostPosted: Wed Aug 27, 2014 8:28 am 
Offline
PDFsharp Guru
User avatar

Joined: Mon Oct 16, 2006 8:16 am
Posts: 3101
Location: Cologne, Germany
Paragraphs are document elements. They are stored in collections and you can remove them using Remove() or RemoveAt().

I guess it would be cleaner to create Para2 and Para3 and also determine whether Para2 is needed.
And then add Para2 if needed and always add Para3.

With MigraDoc the document is dynamic, you can remove paragraphs, insert paragraphs, alter paragraphs. But IMHO you don't need this for your scenario.

_________________
Regards
Thomas Hoevel
PDFsharp Team


Top
 Profile  
Reply with quote  
PostPosted: Wed Aug 27, 2014 8:55 am 
Offline

Joined: Wed Aug 27, 2014 8:06 am
Posts: 3
Hi Thomas,

Thanks for replying. The actual requirement is much more complex, I just framed the question this way to make things simpler.

Say we have the following code:

var pdfdocument = new Document();
var pdfsection = pdfdocument.AddSection();
var para1 = pdfsection.AddParagraph();
var para2 = pdfsection.AddParagraph();
var para3 = pdfsection.AddParagraph();

// para2.Remove() [No such function exists]
// pdfsection.Remove(para2) [No such function exists]
// pdfdocument.Remove(para2) [No such function exists]

Can you tell me exactly how to remove a para2 ? I cant seem to find Remove() or RemoveAt() functions. I am using migradoc version 1.32.


Top
 Profile  
Reply with quote  
PostPosted: Wed Aug 27, 2014 11:46 am 
Offline
PDFsharp Guru
User avatar

Joined: Mon Oct 16, 2006 8:16 am
Posts: 3101
Location: Cologne, Germany
Oops, it's not Remove(), it's RemoveObjectAt().

Code:
myDocument.AddSection();
myDocument.LastSection.AddParagraph("Test");
var para = myDocument.LastSection.AddParagraph("Test #2");
myDocument.LastSection.AddParagraph("Test #3");

int idx = myDocument.LastSection.Elements.IndexOf(para);
if (idx >= 0)
    myDocument.LastSection.Elements.RemoveObjectAt(idx);

_________________
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: Bing [Bot], Google [Bot] and 54 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