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

Labels and inline text

3

Textual content is core to a PDF document, and with scryber this content is built to flow around the document quickly and easily

Contents

Adding inline text

All the container components support inline text - Pages, Sections, Panels (inc. Divs, Spans, etc) and Table Cells

The content can simply be included as part of the document content within the XML template definition. This textual content will flow within the available space breaking on words as best fit and any formatting within the text such as tabs or line breaks will by default be ignored.
To include this content as part of the code, then add it as a text literal.

    <pdf:Page id="MyFirstPage" style:margins="10pt" style:font-family="Times" style:font-size="12pt" >
      <Content>
        Lorem ipsum dolor sit amet, consectetur adipiscing elit. Fusce sit amet feugiat mauris. 
        In commodo erat velit, sed viverra tortor placerat ac. Etiam in lobortis arcu. Integer semper sem vitae
        arcu semper pellentesque. Nam pulvinar metus eu ante elementum accumsan. Duis et porta turpis. 
        Proin ut pretium massa. Vestibulum vitae interdum nisi. Fusce sit amet cursus nibh. Praesent consectetur 
        velit in sodales cursus. In nibh turpis, semper eget ultrices ut, feugiat luctus libero. Vestibulum sed 
        vulputate velit. In ullamcorper auctor faucibus. Vivamus nec urna ante. Sed sed 
        ipsum vulputate, eleifend augue vel, cursus tortor.

        Duis dictum bibendum nisl, nec bibendum erat. Aliquam dolor justo, 
        fringilla vel ultricies at, facilisis quis ligula. Vestibulum non nibh enim. 
        Sed posuere leo augue. Maecenas condimentum mi erat, tempor dignissim lectus rhoncus ac. 
        Donec velit diam, malesuada eget fermentum nec, ultricies sed lectus. Donec ac enim eleifend, adipiscing leo eget,
        pellentesque leo. Interdum et malesuada fames ac ante ipsum primis in faucibus. Aliquam fermentum in risus eget adipiscing.
        Praesent interdum tellus nulla, nec pharetra sem pharetra in. Nam rhoncus dui eget purus vestibulum bibendum. 
        Nam egestas faucibus auctor. Aenean rutrum consequat ultricies.
        </Content>
    </pdf:Page>
            PDFDocument doc = new PDFDocument();

            PDFPage page = new PDFPage();
            page.FontFamily = "Times";
            page.FontSize = 12;
            doc.Pages.Add(page);

            PDFTextLiteral lit = new PDFTextLiteral(@"Lorem ipsum dolor sit amet, consectetur adipiscing elit. Fusce sit amet feugiat mauris. 
        In commodo erat velit, sed viverra tortor placerat ac. Etiam in lobortis arcu. Integer semper sem vitae
        arcu semper pellentesque. Nam pulvinar metus eu ante elementum accumsan. Duis et porta turpis. 
        Proin ut pretium massa. Vestibulum vitae interdum nisi. Fusce sit amet cursus nibh. Praesent consectetur 
        velit in sodales cursus. In nibh turpis, semper eget ultrices ut, feugiat luctus libero. Vestibulum sed 
        vulputate velit. In ullamcorper auctor faucibus. Vivamus nec urna ante. Sed sed 
        ipsum vulputate, eleifend augue vel, cursus tortor.

        Duis dictum bibendum nisl, nec bibendum erat. Aliquam dolor justo, 
        fringilla vel ultricies at, facilisis quis ligula. Vestibulum non nibh enim. 
        Sed posuere leo augue. Maecenas condimentum mi erat, tempor dignissim lectus rhoncus ac. 
        Donec velit diam, malesuada eget fermentum nec, ultricies sed lectus. Donec ac enim eleifend, adipiscing leo eget,
        pellentesque leo. Interdum et malesuada fames ac ante ipsum primis in faucibus. Aliquam fermentum in risus eget adipiscing.
        Praesent interdum tellus nulla, nec pharetra sem pharetra in. Nam rhoncus dui eget purus vestibulum bibendum. 
        Nam egestas faucibus auctor. Aenean rutrum consequat ultricies.");

           page.Contents.Add(lit);

Preview Image

Styling textual content

Text literal components do not have any specific styling attributes, but because the Font style is inherited, all child components will implicitly gain the declared font family and size set on the page, unless they are set differently though other applied styles or inline style declarations.
Therefore the font of the text and the Div in the example below is also 12pt Times as specified in the containing page.
The Font style has bold and italic flags which can be set independently. And these will flow onto child components

    <pdf:Page id="MyFirstPage" style:margins="10pt" style:font-family="Times" style:font-size="12pt" >
      <Content>
        Lorem ipsum dolor sit amet, consectetur adipiscing elit. Fusce sit amet feugiat mauris. 
        In commodo erat velit, sed viverra tortor placerat ac. Etiam in lobortis arcu. Integer semper sem vitae
        arcu semper pellentesque. Nam pulvinar metus eu ante elementum accumsan. Duis et porta turpis. 
        Proin ut pretium massa. Vestibulum vitae interdum nisi. Fusce sit amet cursus nibh. Praesent consectetur 
        velit in sodales cursus. In nibh turpis, semper eget ultrices ut, feugiat luctus libero. Vestibulum sed 
        vulputate velit. In ullamcorper auctor faucibus. Vivamus nec urna ante. Sed sed 
        ipsum vulputate, eleifend augue vel, cursus tortor.

        Duis dictum bibendum nisl, nec bibendum erat. Aliquam dolor justo, 
        fringilla vel ultricies at, facilisis quis ligula. Vestibulum non nibh enim. 
        Sed posuere leo augue. Maecenas condimentum mi erat, tempor dignissim lectus rhoncus ac. 
        Donec velit diam, malesuada eget fermentum nec, ultricies sed lectus. Donec ac enim eleifend, adipiscing leo eget,
        pellentesque leo. Interdum et malesuada fames ac ante ipsum primis in faucibus. Aliquam fermentum in risus eget adipiscing.
        Praesent interdum tellus nulla, nec pharetra sem pharetra in. Nam rhoncus dui eget purus vestibulum bibendum. 
        Nam egestas faucibus auctor. Aenean rutrum consequat ultricies.

          <pdf:Div style:font-bold="true" style:fill-color="red" >
            Ut a lacus nec mauris tincidunt rhoncus. Curabitur nec nibh ut nulla tristique gravida. 
            Ut sit amet rutrum arcu, vitae venenatis magna. Quisque sodales mi vitae elementum pharetra.
            Vestibulum vel mauris et ante ultrices laoreet. Duis at tristique diam. Pellentesque id diam 
            consequat, gravida lorem non, varius mauris. Nullam leo magna, iaculis vitae suscipit vitae, 
            molestie id est.
          </pdf:Div>
        </Content>
    </pdf:Page>
            PDFDocument doc = new PDFDocument();

            PDFPage page = new PDFPage();
            page.FontFamily = "Times";
            page.FontSize = 12;
            doc.Pages.Add(page);

            PDFTextLiteral lit = new PDFTextLiteral(@"Lorem ipsum dolor sit amet, consectetur adipiscing elit. Fusce sit amet feugiat mauris. 
        In commodo erat velit, sed viverra tortor placerat ac. Etiam in lobortis arcu. Integer semper sem vitae
        arcu semper pellentesque. Nam pulvinar metus eu ante elementum accumsan. Duis et porta turpis. 
        Proin ut pretium massa. Vestibulum vitae interdum nisi. Fusce sit amet cursus nibh. Praesent consectetur 
        velit in sodales cursus. In nibh turpis, semper eget ultrices ut, feugiat luctus libero. Vestibulum sed 
        vulputate velit. In ullamcorper auctor faucibus. Vivamus nec urna ante. Sed sed 
        ipsum vulputate, eleifend augue vel, cursus tortor.

        Duis dictum bibendum nisl, nec bibendum erat. Aliquam dolor justo, 
        fringilla vel ultricies at, facilisis quis ligula. Vestibulum non nibh enim. 
        Sed posuere leo augue. Maecenas condimentum mi erat, tempor dignissim lectus rhoncus ac. 
        Donec velit diam, malesuada eget fermentum nec, ultricies sed lectus. Donec ac enim eleifend, adipiscing leo eget,
        pellentesque leo. Interdum et malesuada fames ac ante ipsum primis in faucibus. Aliquam fermentum in risus eget adipiscing.
        Praesent interdum tellus nulla, nec pharetra sem pharetra in. Nam rhoncus dui eget purus vestibulum bibendum. 
        Nam egestas faucibus auctor. Aenean rutrum consequat ultricies.");
            page.Contents.Add(lit);

            PDFDiv div = new PDFDiv();
            div.FontBold = true;
            div.FillColor = PDFColors.Red;
            lit = new PDFTextLiteral(@"Ut a lacus nec mauris tincidunt rhoncus. Curabitur nec nibh ut nulla tristique gravida. 
       Ut sit amet rutrum arcu, vitae venenatis magna. Quisque sodales mi vitae elementum pharetra.
       Vestibulum vel mauris et ante ultrices laoreet. Duis at tristique diam. Pellentesque id diam 
       consequat, gravida lorem non, varius mauris. Nullam leo magna, iaculis vitae suscipit vitae, 
       molestie id est.");
            div.Contents.Add(lit);

            page.Contents.Add(div);

Preview Image

Text alignment and positioning

All alignment and positioning information is applied to content containers and the child components will be arranged as appropriate given the alignment information.
In the alignment example below the content of the page is set to a horizontal alignment of Right and vertical alignment of Middle, positioning the content appropriately within the page.
Because the Position style is not inherited, then the inner content of the div does not gain the Middle Right alignment, and text is back to the default Left alignment. Because an explicit width is set on the Div it can be seen that it is itself aligned Right. To have the alignment applied to all containers, then set it explicitly through styles

    <pdf:Page id="MyFirstPage" style:margins="10pt" style:font-family="Times" style:font-size="12pt"
                               style:h-align="Right" style:v-align="Middle" >
      <Content>
        Lorem ipsum dolor sit amet, consectetur adipiscing elit. Fusce sit amet feugiat mauris. 
        In commodo erat velit, sed viverra tortor placerat ac. Etiam in lobortis arcu. Integer semper sem vitae
        arcu semper pellentesque. Nam pulvinar metus eu ante elementum accumsan. Duis et porta turpis. 
        Proin ut pretium massa. Vestibulum vitae interdum nisi. Fusce sit amet cursus nibh. Praesent consectetur 
        velit in sodales cursus. In nibh turpis, semper eget ultrices ut, feugiat luctus libero. Vestibulum sed 
        vulputate velit. In ullamcorper auctor faucibus. Vivamus nec urna ante. Sed sed 
        ipsum vulputate, eleifend augue vel, cursus tortor.

        Duis dictum bibendum nisl, nec bibendum erat. Aliquam dolor justo, 
        fringilla vel ultricies at, facilisis quis ligula. Vestibulum non nibh enim. 
        Sed posuere leo augue. Maecenas condimentum mi erat, tempor dignissim lectus rhoncus ac. 
        Donec velit diam, malesuada eget fermentum nec, ultricies sed lectus. Donec ac enim eleifend, adipiscing leo eget,
        pellentesque leo. Interdum et malesuada fames ac ante ipsum primis in faucibus. Aliquam fermentum in risus eget adipiscing.
        Praesent interdum tellus nulla, nec pharetra sem pharetra in. Nam rhoncus dui eget purus vestibulum bibendum. 
        Nam egestas faucibus auctor. Aenean rutrum consequat ultricies.

        <pdf:Div style:font-bold="true" style:fill-color="red" style:width="400pt" >
            Ut a lacus nec mauris tincidunt rhoncus. Curabitur nec nibh ut nulla tristique gravida. 
            Ut sit amet rutrum arcu, vitae venenatis magna. Quisque sodales mi vitae elementum pharetra.
            Vestibulum vel mauris et ante ultrices laoreet. Duis at tristique diam. Pellentesque id diam 
            consequat, gravida lorem non, varius mauris. Nullam leo magna, iaculis vitae suscipit vitae, 
            molestie id est.
          </pdf:Div>
        </Content>
    </pdf:Page>
            PDFDocument doc = new PDFDocument();

            PDFPage page = new PDFPage();
            page.FontFamily = "Times";
            page.FontSize = 12;
            page.HorizontalAlignment = HorizontalAlignment.Right;
            page.VerticalAlignment = VerticalAlignment.Middle;
            doc.Pages.Add(page);

            PDFTextLiteral lit = new PDFTextLiteral(@"Lorem ipsum dolor sit amet, consectetur adipiscing elit. Fusce sit amet feugiat mauris. 
        In commodo erat velit, sed viverra tortor placerat ac. Etiam in lobortis arcu. Integer semper sem vitae
        arcu semper pellentesque. Nam pulvinar metus eu ante elementum accumsan. Duis et porta turpis. 
        Proin ut pretium massa. Vestibulum vitae interdum nisi. Fusce sit amet cursus nibh. Praesent consectetur 
        velit in sodales cursus. In nibh turpis, semper eget ultrices ut, feugiat luctus libero. Vestibulum sed 
        vulputate velit. In ullamcorper auctor faucibus. Vivamus nec urna ante. Sed sed 
        ipsum vulputate, eleifend augue vel, cursus tortor.

        Duis dictum bibendum nisl, nec bibendum erat. Aliquam dolor justo, 
        fringilla vel ultricies at, facilisis quis ligula. Vestibulum non nibh enim. 
        Sed posuere leo augue. Maecenas condimentum mi erat, tempor dignissim lectus rhoncus ac. 
        Donec velit diam, malesuada eget fermentum nec, ultricies sed lectus. Donec ac enim eleifend, adipiscing leo eget,
        pellentesque leo. Interdum et malesuada fames ac ante ipsum primis in faucibus. Aliquam fermentum in risus eget adipiscing.
        Praesent interdum tellus nulla, nec pharetra sem pharetra in. Nam rhoncus dui eget purus vestibulum bibendum. 
        Nam egestas faucibus auctor. Aenean rutrum consequat ultricies.");
            page.Contents.Add(lit);

            PDFDiv div = new PDFDiv();
            div.FontBold = true;
            div.FillColor = PDFColors.Red;
            div.Width = 400;
            lit = new PDFTextLiteral(@"Ut a lacus nec mauris tincidunt rhoncus. Curabitur nec nibh ut nulla tristique gravida. 
       Ut sit amet rutrum arcu, vitae venenatis magna. Quisque sodales mi vitae elementum pharetra.
       Vestibulum vel mauris et ante ultrices laoreet. Duis at tristique diam. Pellentesque id diam 
       consequat, gravida lorem non, varius mauris. Nullam leo magna, iaculis vitae suscipit vitae, 
       molestie id est.");
            div.Contents.Add(lit);

            page.Contents.Add(div);

Preview Image

Literals vs Labels

Along with the text literal content scryber supports Labels -fully qualified, styled components that can only contain textual content.

The label supports the standard component attributes for visibility, id, outline along with a text attribute
This means that it's content can be data bound or set through code, without altering the structure of the document

The actual content of the label can also be specified within the element itself, instead of the @text attribute if required

    <pdf:Page id="MyFirstPage" style:margins="10pt" style:font-family="Times" style:font-size="12pt" >
      <Content>
        Lorem ipsum dolor sit amet, consectetur adipiscing elit. Fusce sit amet feugiat mauris. 
        In commodo erat velit, sed viverra tortor placerat ac. Etiam in lobortis arcu. Integer semper sem vitae
        arcu semper pellentesque. Nam pulvinar metus eu ante elementum accumsan. 
        <pdf:Label id="MyLabel" visible="true" style:font-bold="true" text="Within the content " />
        Duis et porta turpis. 
        Proin ut pretium massa. Vestibulum vitae interdum nisi. Fusce sit amet cursus nibh. Praesent consectetur 
        velit in sodales cursus. In nibh turpis, semper eget ultrices ut, feugiat luctus libero. Vestibulum sed 
        vulputate velit. In ullamcorper auctor faucibus. Vivamus nec urna ante. Sed sed 
        ipsum vulputate, eleifend augue vel, cursus tortor.
        </Content>
    </pdf:Page>
            PDFDocument doc = new PDFDocument();

            PDFPage page = new PDFPage();
            page.FontFamily = "Times";
            page.FontSize = 12;
            doc.Pages.Add(page);

            PDFTextLiteral lit = new PDFTextLiteral(@"Lorem ipsum dolor sit amet, consectetur adipiscing elit. Fusce sit amet feugiat mauris. 
        In commodo erat velit, sed viverra tortor placerat ac. Etiam in lobortis arcu. Integer semper sem vitae
        arcu semper pellentesque. Nam pulvinar metus eu ante elementum accumsan.");

           page.Contents.Add(lit);

           PDFLabel lbl = new PDFLabel();
          lbl.Text = "Within the content";
           lbl.FontBold = true;
           page.Contents.Add(lbl);

           lit = new PDFTextLiteral(@"Duis et porta turpis. 
        Proin ut pretium massa. Vestibulum vitae interdum nisi. Fusce sit amet cursus nibh. Praesent consectetur 
        velit in sodales cursus. In nibh turpis, semper eget ultrices ut, feugiat luctus libero. Vestibulum sed 
        vulputate velit. In ullamcorper auctor faucibus. Vivamus nec urna ante. Sed sed 
        ipsum vulputate, eleifend augue vel, cursus tortor.");

           page.Contents.Add(lit);

Preview Image

Bold, Italic and Line Breaks

Technically the Bold and Italic components are Spans (see Panel, Div, Para, Pre, Span), but by default the only effect they have is to alter the current font.
A <pdf:B> entry will mark the current font with a bold requirement. If the current font is already bold, then it will have no effect, and the closing </pdf:B> element will have no effect either.
The same is true for the italic flag of the <pdf:I> element.
Because scryber relies on well formed XML to parse the document contents it is illegal to mix the order of these element (i.e. close a bold before closing an italic if the italic was opened last).

NOTE: Because B and I tags inherit from Span(s) if an explicit style is set on the Span type, it will also be applied to the B and I tags.

The line break <pdf:BR/> element will force the next content onto a new line no matter if it is defined as inline or block

Controlling the flow of text

There are a number of extra Text styling options that are available to alter the flow of content. Because they are part of the Text Style Item they are inherited by child components.

@leading
Specifies the Leading within the text layout. This is the amount of space between base lines of the text irrespective of the default value specified within the font descriptor.
@first-indent
Specifies the horizontal offset of the first line of text after a line break or at the start of a new block
@wrap
One of the WordWrapping options that define how lines will be soft-broken onto the next line. Options are...
  • Auto (same as word, except for long words that will be split if they are the only word on that line)
  • Word
  • Character
  • NoWrap
@whitespace-significant
A boolean value that if true will force all whitespace (inc. carriage returns) to be honoured and text will flow as it is laid out in the string or file
    <style:Style applied-class="FormattedText" >
      <style:Text first-indent="20pt" leading="30pt"/>
    </style:Style>

    <style:Style applied-class="Preserved" >
      <style:Text whitespace-significant="true"/>
      <style:Border color="silver" width="1pt"/>
      <style:Padding all="4pt"/>
    </style:Style>

        
        <!-- other document content-->
        
        
        <pdf:Div style:class="FormattedText" >
          This is text that has a first line indent of 20 points with a leading
          of 30pt even though the font-size is 12 points, and this will flow onto child components...
          <pdf:Span >
            Proin ut pretium massa. Vestibulum vitae interdum nisi. Fusce sit amet cursus nibh. Praesent consectetur
            velit in sodales cursus. In nibh turpis, semper eget ultrices ut, feugiat luctus libero. <pdf:Br/>
            Vestibulum sed vulputate velit. In ullamcorper auctor faucibus. 
            Vivamus nec urna ante. Sed sed ipsum vulputate, eleifend augue vel, cursus tortor.
          </pdf:Span>
        </pdf:Div>
        <pdf:Div style:class="Preserved" >This content 
has preserved white space
           so content
     will be laid out as written.</pdf:Div>

Preview Image

See Also



  Rating
Rate This Page: Poor Great   |  Rate Content |
Average rating:  3   
00100
12345
Number of Ratings : 1
  Comments
Add Comment
SDM
When I try the c# code in "Adding inline text" I get an error in VS:

"CS1503 Argument 1: cannot convert from 'Scryber.Components.PDFTextLiteral' to 'Scryber.Components.PDFVisualComponent"

Thnx!
Posted At 27-09-2017 17:07:11

SDM
When I try the c# code in "Adding inline text" I get an error in VS:

"CS1503 Argument 1: cannot convert from 'Scryber.Components.PDFTextLiteral' to 'Scryber.Components.PDFVisualComponent"

Thnx!
Posted At 27-09-2017 17:06:57