Background Color:
 
Background Pattern:
Reset
Search
Home Recent Changes Show All Pages

The Document and its Pages

5

At the top level of a pdfx file is always the document. Everything is part of the document and every component in the hierarchy can get access to the current document instance.

<pdf:Document 
              xmlns:pdf="Scryber.Components, Scryber.Components, Version=0.8.0.0, Culture=neutral, PublicKeyToken=872cbeb81db952fe"
              xmlns:styles="Scryber.Styles, Scryber.Styles, Version=0.8.0.0, Culture=neutral, PublicKeyToken=872cbeb81db952fe"
              xmlns:data="Scryber.Data, Scryber.Components, Version=0.8.0.0, Culture=neutral, PublicKeyToken=872cbeb81db952fe"
              compression="Compress" auto-bind="true" >
  <Info ></Info>
  <Viewer  ></Viewer>
  <Styles></Styles>
  <Pages></Pages>
</pdf:Document>

The namespace declarations are important, as the XML Parser uses them to identify which .NET component class is referred to by the element. The standard group of namespaces are identified for the components namespace (pdf), styles namespace and data namespace. The prefix’s are arbitrary, but allow the parser to differentiate components and instantiate the correct instance.

As with any component, the document can be created directly in code if required.

        protected void Button_Click(object sender, CommandEventArgs e)
        {
            PDFDocument doc = new PDFDocument();
            doc.Info.Author = "Scryber";
            doc.Info.CreationDate = DateTime.Now;

            PDFPage pg = new PDFPage();
            pg.PaperSize = Scryber.PaperSize.A4;
            doc.Pages.Add(pg);

            doc.ProcessDocument(this.Response);
        }

Or the document supports modification once loaded and before processing.

        protected void Button_Click(object sender, CommandEventArgs e)
        {
            PDFDocument doc = PDFDocument.ParseDocument("~/PDFs/MyFirstPDF.pdfx");
            doc.Info.Author = System.Environment.UserName;
            doc.Info.CreationDate = DateTime.Now;

            doc.ProcessDocument(this.Response);
        }

Within the XML document element there are a number of supported attributes and child elements. The ordering of these elements is a fixed sequence within the schema.

Document Attributes

On the document element itself is an auto-bind attribute that dictates if the document will automatically execute databinding during the generation lifecycle, and a compression attribute.

auto-bind
If this value is true then before the Layout is started the DataBind method will be executed on the document and all it's child components so all the dynamic content will be generated. If this is false it is up to the processing code to execute the DataBind on any required components or the document as a whole.
Not all documents require databinding and it may be advantageous to have multiple data bound parts in a document, but the standard template has this set to true to ease processing.
compression
The default compression of a document is to zip the content streams, image streams and fonts. This (significantly) reduces the output size of the document, but can have a detrimental effect on the memory consumed during rendering, and the time taken to generate the content. It is also difficult to read the resultant content of the PDF in as a text file. 
This attribute controls if compression of this content occurs. If ‘Compress’ then the content will be compressed, if ‘None’ then it will not.

Document Info

General information about the generated PDF that can viewed by the reader application in the document properties. This forms the top level meta data about the document and some PDF plug-ins use this to inform searches.

<Info created-date="2012-12-31" creator="Application Name" modified-date="2013-01-01 12:40:40" producer="Scryber" >
    <Title>My First PDF</Title>
    <Subject>Just a test PDF</Subject>
    <Keywords>Scryber PDF</Keywords>
    <Author>Richard Hewitson</Author>
    <pdf:Extra name="More" >A bit more info</pdf:Extra>
    <pdf:Extra name="Even More" >A n other bit of info</pdf:Extra>
  </Info>

If no values are provided the defaults will be set for the created-date, creator and producer. The other values will blank. The pdf:Extra elements add name value items to the custom properties of the PDF Document.

Document Viewer preferences

The Viewer element defines the initial presentation of pages as they are opened in the application. This is not forced, and is up to the viewer to comply, and some are only relevant to full screen view, and some have no effect at all, but are included for completeness.

<Viewer center-window="true" hide-windowUI="false"
          page-display="Outlines" page-layout="TwoPageLeft" 
          hide-menubar="false" hide-toolbar="false" fit-window="true" />

The resulting page display when the document is first opened is shown below.

Document styles

The next element within the document structure is Styles and contains all the styles that a document should use when generating content.
The creation of styles and their impact on the layout is covered in a separate document Understanding Styles and is beyond the scope of this document. However, styles can be defined within this element or defined in a separate file and referenced in the document with a relative path.

  <Styles>
    <!-- define styles or include external stylesheets -->
    <style:Styles-Ref source="../PDFStyles/Styles.psfx" />

    <style:Style applied-class="heading" >
      <style:Border color="#971B1E" sides="Top Left Bottom Right"/>
    </style:Style>
    
    <style:Style applied-class="red-text" >
      <style:Fill color="#971B1E"/>
    </style:Style>

    <style:Style applied-class="red-underline" >
      <style:Border color="#971B1E"/>
    </style:Style>

  </Styles>

Document pages

The final child element to any document is the pages content. Whilst it is possible to generate a document without any pages at all, most viewer applications will issue a warning when the document is opened.

The contents of the pages element is either a Page which will not overflow content onto a new page, or a Section element that will allow multiple document pages to be generated with the content within it.

Or, just like styles, a reference to a page / section in a different file. This allows you to separate out standard pages and styles, reducing the complexity of a document

  <Pages>

    <pdf:Page id="FirstPage" >
      <Content>My First Page</Content>
    </pdf:Page>

    <pdf:Section id="FirstSection" >
      <Content>
        The first page of the section
        <pdf:PageBreak/>
        The second page of the content
      </Content>
    </pdf:Section>
    
    <pdf:Page-Ref id="FirstPage” source="./Pages/TermsAndConditions.ppfx" >

  </Pages>

The page and section elements are discussed in the next chapter Pages and Sections



  Rating
Rate This Page: Poor Great   |  Rate Content |
Average rating:  5   
00003
12345
Number of Ratings : 3
  Comments
Add Comment
No Comments Yet