com.cete.dynamicpdf.pageelements
Class FormattedTextArea




Examples Description
Example 1 The following example shows a paragraph of formatted text being displayed on the page.
Example 2 The following example shows you how to use the GetOverflowFormattedTextArea object to allow text of variable length to flow onto new pages as needed.
Example 3 The following example shows you how to use the GetOverflowFormattedTextArea object with x,y coordinates to allow text of variable length to flow onto new pages as needed.
Example 4 The following example shows you how to use the GetOverflowFormattedTextArea object with x,y coordinates & height to allow text of variable length to flow onto new pages as needed.



Example 1: The following example shows a paragraph of formatted text being displayed on the page

 import com.cete.dynamicpdf.*;
 import com.cete.dynamicpdf.pageelements.*;
  
 public class MyClass{
       public static void main(String args[]){
       
           // Create a PDF Document
           Document document = new Document();
 
           // Create a Page and add it to the document
           Page page = new Page();
           document.getPages().add(page);
   
           // Create an formatted style
           FormattedTextAreaStyle style = new FormattedTextAreaStyle(FontFamily.getHelvetica(), 12, false);
 
           // Create the text and the formatted text area
           String formattedText = "<p>Formatted text area provide rich formatting support for text that " + 
           "appears in the document. You have complete control over 8 paragraph properties: " + 
           "spacing before, spacing after, first line indentation, left indentation, right " + 
           "indentation, alignment, allowing orphan lines, and white space preservation; 6 " + 
           "font properties: <font face='Times'>font face, </font><font " + 
           "pointSize='6'>font size, </font><font color='FF0000'>color, " + 
           "</font><b>bold, </b><i>italic and </i><u>" + 
           "underline</u> and 2 line properties: leading, and leading type. Text can " + 
           "also be rotated.</p>"; 
 
           FormattedTextArea formattedTextArea = new FormattedTextArea(formattedText, 0, 0, 256, 400, style);
 
           // Add the Formatted text area to the page
           page.getElements().add(formattedTextArea);    
 
           // Save the PDF
           document.draw("[PhysicalPath]/MyDocument.pdf");
       }
 }

Top

Example 2: The following example shows you how to use the GetOverflowFormattedTextArea object to allow text of variable length to flow onto new pages as needed.

import com.cete.dynamicpdf.*;
import com.cete.dynamicpdf.pageelements.*;

public class MyClass
{
    public static void Main(String args[])
    {
        // Create a PDF Document
        Document document = new Document();

        // Create a string and assign it to text of variable length
        String variableText = "";
        for( int i = 0; i < 50; i++ )
            variableText += "<i>This</i> is a <font color='FF0000'>sentence</font> that I " +
            "will use as my <b>variable length</b> text. ";

        // Create an Formatted text area
        FormattedTextArea formattedTextArea = new FormattedTextArea(variableText, 0, 0, 250, 200, FontFamily.getHelvetica(), 12, false); 
    
        do
        {
            // Create a new page
            Page page = new Page();
 
            // Add the text area to the page;
            page.getElements().add( formattedTextArea );

            // Add the page to the document
            document.getPages().add( page );

            // Set the Formatted text area object equal to the rest of the text that did not fit
            // if all the text did fit, GetOverflowFormattedTextArea will return null
            formattedTextArea = formattedTextArea.getOverflowFormattedTextArea(); 
        } while( formattedTextArea != null );
    
        // Save the PDF
        document.draw("[Physicalpath/MyDocument.pdf");
    }
}

Top

Example 3: The following example shows you how to use the GetOverflowFormattedTextArea object with x,y coordinates to allow text of variable length to flow onto new pages as needed.

import com.cete.dynamicpdf.*;
import com.cete.dynamicpdf.pageelements.*;

public class MyClass
{
    public static void Main(String args[])
    {
        // Create a PDF Document
        Document document = new Document();

        // Create a string and assign it to text of variable length
        String variableText = "";
        for( int i = 0; i < 50; i++ )
            variableText += "<i>This</i> is a <font color='FF0000'>sentence</font> that I " +
            "will use as my <b>variable length</b> text. ";

        // Create an Formatted text area
        FormattedTextArea formattedTextArea = new FormattedTextArea(variableText, 0, 0, 250, 200, FontFamily.getHelvetica(), 12, false); 
    
        do
        {
            // Create a new page
            Page page = new Page();
 
            // Add the text area to the page;
            page.getElements().add( formattedTextArea );

            // Add the page to the document
            document.getPages().add( page );

            // Set the Formatted text area object equal to the rest of the text that did not fit
            // if all the text did fit, GetOverflowFormattedTextArea will return null
            formattedTextArea = formattedTextArea.getOverflowFormattedTextArea(200,30); 
        } while( formattedTextArea != null );
    
        // Save the PDF
        document.draw("[Physicalpath/MyDocument.pdf");
    }
}

Top

Example 4: The following example shows you how to use the GetOverflowFormattedTextArea object with x,y coordinates & height to allow text of variable length to flow onto new pages as needed.

import com.cete.dynamicpdf.*;
import com.cete.dynamicpdf.pageelements.*;

public class MyClass
{
    public static void Main(String args[])
    {
        // Create a PDF Document
        Document document = new Document();

        // Create a string and assign it to text of variable length
        String variableText = "";
        for( int i = 0; i < 50; i++ )
            variableText += "<i>This</i> is a <font color='FF0000'>sentence</font> that I " +
            "will use as my <b>variable length</b> text. ";

        // Create an HTML text area
        FormattedTextArea formattedTextArea = new FormattedTextArea(variableText, 0, 0, 250, 200, FontFamily.getHelvetica(), 12, false); 
    
        do
        {
            // Create a new page
            Page page = new Page();
 
            // Add the text area to the page;
            page.getElements().add( formattedTextArea );

            // Add the page to the document
            document.getPages().add( page );

            // Set the Formatted text area object equal to the rest of the text that did not fit
            // if all the text did fit, GetOverflowFormattedTextArea will return null
            formattedTextArea = formattedTextArea.getOverflowFormattedTextArea(200,30,100); 
        } while( formattedTextArea != null );
    
        // Save the PDF
        document.draw("[Physicalpath/MyDocument.pdf");
    }
}

Top