Text Flow Example

ABCpdf .net

 
   

This example shows how to flow text from one area to another. The techniques shown here are used to flow text between pages but they could equally well be applied to flowing text between areas - such as columns - on the same page.

 

   
Setup  

First we'll set up some convenient variables. One will determine the gap between our columns and the other will contain the text we want to display.

[C#]
int theID = 0;
string theText = "Gallia est omnis divisa in partes tres, quarum unam incolunt Belgae, aliam Aquitani, tertiam qui ipsorum lingua Celtae, nostra Galli appellantur. Hi omnes..."; // truncated for clarity

[Visual Basic]
Dim theID As Integer = 0
Dim theText As String = "Gallia est omnis divisa in partes tres, quarum unam incolunt Belgae, aliam Aquitani, tertiam qui ipsorum lingua Celtae, nostra Galli appellantur. Hi omnes..." ' truncated for clarity


   

Doc Obj
 

Next we create an ABCpdf Doc object and give it our basic settings.

We enlarge the line width, increase the font size, enable justification and inset the drawing rectangle from the edges of the document.

[C#]
Doc theDoc = new Doc();
theDoc.Width = 4;
theDoc.FontSize = 32;
theDoc.TextStyle.Justification = 1;
theDoc.Rect.Inset(20, 20);

[Visual Basic]
Dim theDoc As Doc = New Doc()
theDoc.Width = 4
theDoc.FontSize = 32
theDoc.TextStyle.Justification = 1
theDoc.Rect.Inset(20, 20)

 

   

Adding
 

We add our base text to the current page of the document. We then enter a loop, adding pages and chaining HTML boxes together until we run out of text to display.

[C#]
theDoc.FrameRect();
theID = theDoc.AddHtml(theText);
while (theDoc.Chainable(theID)) {
  theDoc.Page = theDoc.AddPage();
  theDoc.FrameRect();
  theID = theDoc.AddHtml("", theID);
}

[Visual Basic]
theDoc.FrameRect()
theID = theDoc.AddHtml(theText)
While theDoc.Chainable(theID)
  theDoc.Page = theDoc.AddPage()
  theDoc.FrameRect()
  theID = theDoc.AddHtml("", theID)
End While

 

   

Save
 

After adding all our text we save the document to a specified location and clear our document.

[C#]
theDoc.Save(Server.MapPath("textflow.pdf"));
theDoc.Clear();

[Visual Basic]
theDoc.Save(Server.MapPath("textflow.pdf"))
theDoc.Clear()

 

   

Results
 


textflow.pdf [Page 1]


textflow.pdf [Page 2]


textflow.pdf [Page 3]