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

The Document and its Pages


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.

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

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;


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;


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.

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.
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>

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.

    <!-- 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 applied-class="red-text" >
      <style:Fill color="#971B1E"/>

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


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


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

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


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

Rate This Page: Poor Great   |  Rate Content |
Average rating:  5   
Number of Ratings : 3
Add Comment
Posted At 26-12-2018 01:27:42