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...Assigning Header to DocAssigning Header to Doc
Previous
 
Next
New Post
6/17/2016 5:17 PM
 

Follow up to this thread: https://www.scryber.co.uk/Forum/tabid/134/forumid/1/threadid/257/scope/posts/Default.aspx

In an effort to make customizable headers, the above thread worked. The issue is adding them to a parsed document without appending a whole new page onto the "doc" variable.

When I run the below code in aspx:

ArrayList ListyMcListFace = new ArrayList{"One", "Two", "Three", "Four"};

path = Server.MapPath(path);

 PDFDocument doc = PDFDocument.ParseDocument(path);

 doc.Page.Header = new DefaultHeader(ListyMcListFace);

doc.ProcessDocument(this.Response);

I get a runtime error stating a null reference exception.

When I run this and append it with doc.Pages.Add(pg):

PDFPage pg = new PDFPage();

pg.Header = new DefaultHeader(ListyMcListFace);

doc.Pages.Add(pg);

There is no runtime error and the header is created, just on the next page rather than the whole document. 

Why is one working and not the other, as both instances of DefaultHeader are being assigned to "PDFPage IPDFTemplate PDFPageBase.Header" variables?

 
New Post
6/17/2016 9:50 PM
Accepted Answer 

Hi Mophiematt

 

Personally I blame ListyMcListFace. I have never liked him, and he always causes trouble whenever you poke him.

 

However, the Page property is declared on the component to return the current page a component is on, by looking up the hierarchy.
A document does not have a page, so null is returned. I think this is where your error is coming from.

The PDFDocument class does has a Pages collection that can be accessed by index or enumerated over to assign a header.

 

doc.Pages[0].Header = ....

 

R

 
New Post
6/22/2016 4:58 PM
 

Worked like a charm! Thanks!

 
Previous
 
Next
HomeHomeScryberScryberDevelopment Que...Development Que...Assigning Header to DocAssigning Header to Doc