Background Color:
 
Background Pattern:
Reset
Search

Forum

Please Log In

We want you to contribute! 

This forum is a moderated environment. 
We try to keep it neat and tidy. In order to access the forum content we would like you to either or register.

HomeHomeScryberScryberDevelopment Que...Development Que...Dynamically Adding Components to Page InstanceDynamically Adding Components to Page Instance
Previous
 
Next
New Post
5/11/2016 8:43 PM
 

How can I add/append a component onto a PDFDocument instance using C# without having to create a whole new page? I have a base template that I load into the PDFDocument instance, and then I want to add a component that is built using another method to that PDFDocument instance.

For context, below is how I am current doing it: by adding a whole new page onto the end with doc.Pages.Add().

using (PDFDocument doc = PDFDocument.ParseDocument(path))

        {

            PDFSection infoTable = CreateInfoTable(infoStrArray, InfoForPDF);

            doc.Pages.Add(infoTable);

            doc.ProcessDocument(this.Response);

        }

 
New Post
5/13/2016 6:44 PM
Accepted Answer 

Hi Mophiematt

You can dynamically add components to any part of the content easily using the FindAComponentByID or FindAComponentByName methods on the PDFDocument class or the TryFindAComponentByID<T> extension methods for strongly typed returned values.

There is also the PlaceHolder component which is designed specifically to hold other components without fixing the layout.

So in your template content add the placeholder wherever you need to.

  <pdf:Page id="ToAddContentTo" >

      <Content>

        Content above

        <pdf:Div >Inline contents

          <pdf:PlaceHolder id="AddHere" />

        </pdf:Div>

        And content below.

      </Content>

    </pdf:Page>


And in your code behind.

                using (Scryber.Components.PDFDocument doc = Scryber.Components.PDFDocument.ParseDocument(path))

                {

                    //Add your content to the place holder as required.

                    PDFPlaceHolder dynamic;

                    if (doc.TryFindAComponentByID("AddHere", out dynamic))

                    {

                        dynamic.Contents.Add(CreateInfoTable(infoStrArray, InfoForPDF));

                    }

                    else

                    {  

                        //take appropriate action

                    }

                    doc.ProcessDocument(this.Response);

                }


The document and its contents are full instances - you can do whatever you wish with them before processing.

 
New Post
5/13/2016 9:29 PM
 

Perfect!

Now it adds it right to the page instead of creating a new one.

Thanks!

 
Previous
 
Next
HomeHomeScryberScryberDevelopment Que...Development Que...Dynamically Adding Components to Page InstanceDynamically Adding Components to Page Instance