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

Numbers and Dates

Not Rated Yet

Numbers and Dates support the cultural formatting on number values and DateTime values within a PDF Document. As dynamic components they can be data bound to values or be set in code.

Article Contents

 

 

A Number Value

Perhaps the simplest number is defined very quickly in the template file as follows

<pdf:Div >This is some text with the number <pdf:Number value="100" /> in it.</pdf:Div>

 

The number value is strongly typed, so setting it to something that cannot be parsed into a double value will raise an error.

 

Number value formatting

One of the advantages of using an explicit number rather than just a label or literal within the text, is that you can apply formatting to it.

<pdf:Div >
    This is some text with the currency <pdf:Number value="100.20" style:number-format="C" /> in it.<pdf:Br/>
    This is some text with the number <pdf:Number value="100.20" style:number-format="###0.000" /> in it.
</pdf:Div>

 

The thread culture is used by the .NET framework to define the currency symbol and format. Scryber does not alter this, but simply makes use of it

 

Number Styles

Of course, because this is scryber, we can apply the format as a style class and declare the specifics outside of the actual number.

Same rules apply for Understanding Styles

<style:Style applied-type="pdf:Number" applied-class="currency" >
   <style:Text number-format="C"/>
</style:Style>
.
.
.
.
<pdf:Div >
   This is some text with the currency style for <pdf:Number value="100.20" style:class="currency" /> in it.
</pdf:Div>

 

 

 

 

A Date Value

Dates work very similar way to numbers, and they already have a default value - the current date and time

<pdf:Div >
   This is some text with the current date <pdf:Date /> in it.
</pdf:Div>

 

 

Date value formatting

The date component has the value and date-format options that control how the date is presented, and as with numbers the current culture will be used by the .NET framework when required.

<pdf:Div >
     This is some text with a specific date <pdf:Date value="20/07/2010" style:date-format="D" /> in it.<pdf:Br/>
     This is some text with a specific date and format <pdf:Date value="10:02:24pm" style:date-format="T" /> in it.
</pdf:Div>

 

Note: As with the output, the input must be a date value. If it cannot be parsed into a date then an error will be raised. And the current culture will also be used for parsing - 10/07/2010 could be parsed as either the 10th of July OR 7th of October depending upon the current thread culture.

 

Date Styles

As per numbers, the date-format on the Text style controls how the date is output

<style:Style applied-type="pdf:Date" applied-class="long-date" >
   <style:Text date-format="ddd, dd MMMM yyyy HH:mm:ss zzzz"/>
</style:Style>
.
.
.
.
<pdf:Div >
   This is some text with the format in a style <pdf:Date style:class="long-date" /> in it.
</pdf:Div>

 

 

 

Setting the value from your code

Once you have loaded a document, then you can get access to the component and manually change the value to whatever you wish.

     doc = Scryber.Components.PDFDocument.ParseDocument(path);
    Scryber.Components.PDFDate date = (Scryber.Components.PDFDate)doc.FindAComponentById("MyDate");
    date.Value = new DateTime(2014, 01, 01);
                
    doc.ProcessDocument(outputstream, true);

 

 

Binding to Sources

Finally, because this is scryber and we support data-binding, it is easy to use the Date or Number components in your bound sources

If we have an example xml file called SimpleBindingDate.xml with the following content

<?xml version="1.0" encoding="utf-8" ?>
<data>
  <row>
    <field name="Event Date" type="DateTime" >2014-12-25</field>
    <field name="Title" type="String" >Christmas Day</field>
  </row>
  <row>
    <field name="Event Date" type="DateTime" >2014-04-25</field>
    <field name="Title" type="String" >Birthday Day</field>
  </row>
  <row>
    <field name="Event Date" type="DateTime" >2014-07-12</field>
    <field name="Title" type="String" >Battle of the Boyne</field>
  </row>
</data>

Then we can bind to this data applying styles as we need them

        <data:ForEach datasource-id="SimpleXml" select="data/row" >
          <Template>
            <pdf:Div style:margins="10pt" style:bg-color="aqua" style:bg-opacity="0.3">
              <pdf:Label text="{xpath:field[@name='Title']}" /> = <pdf:Date value="{xpath:field[@name='Event Date']}" style:fill-color="red" style:class="long-date" />
            </pdf:Div>
          </Template>
        </data:ForEach>

        <data:XMLDataSource id="SimpleXml" source-path="SimpleBindingDate.xml" >
        </data:XMLDataSource>

And once generated we can see the results

 



  Rating
Rate This Page: Poor Great   |  Rate Content |
Average rating:  No Ratings Yet   
Number of Ratings : 0
  Comments
Add Comment
No Comments Yet