ShowTextParagraph
IPDFDocument4 :: Page Operations :: Text

See Also Example
Collapse All

This method draws a text paragraph.

Syntax

HRESULT ShowTextParagraph (
FLOAT x,
FLOAT y,
ParagraphAlign pAlign,
FLOAT interval,
FLOAT marginLeft,
FLOAT marginTop,
FLOAT marginRight,
FLOAT marginBottom,
BSTR text
)
Parameters
x
X coordinate of the starting text location

y
Y coordinate of the starting text location

pAlign
Text align within the paragraph

interval
Space (in pixels) between paragraph text lines. If it is negative ( < 0 ), then the default interval will be used.

marginLeft
The space from the left edge of the page to the text section (in pixels)

marginTop
The space from the top edge of the page to the text section (in pixels)

marginRight
The space from the right edge of the page to the text section (in pixels)

marginBottom
The space from the bottom edge of the page to the text section (in pixels)

text
Paragraph text to be displayed

Return value
If successful, this method returns S_OK. If it fails, this method should return one of the error values.

Remarks

The method will automatically split the paragraph text to the lines to fit the page bounds, align text lines as needed and add a new PDF page if the text does not fit to the rest of the current PDF page.

This method respects all text settings such as text direction, text font and font size, word spacing, character spacing and e.t.c.

Example

Creating a PDF book from a text file

Delphi
[copy to clipboard]
{ PDF object is supposed to be created }

{*** prepare PDF for e-reader size}
PDF.PageResolution := 166;
W := 584;
H := 754;
PDF.PageWidth := W;
PDF.PageHeight := H;
margin := 10;

{*** draw title and author}
fnt := PDF.AddFont('Some Font Family Name', false, false, false, false, fcDefault);
PDF.UseFont(fnt, 14.0);
PDF.SetColorFill(0.0, 0.0, 0.0, 0.0);
PDF.ShowUnicodeTextAligned(mLeft, margin, W - margin, margin + 40, taCenter, vaTop, 'Alice''s Adventures in Wonderland');

PDF.UseFont(fnt, 12.0);
PDF.SetColorFill(0.3, 0.3, 0.3, 0.0);
PDF.ShowUnicodeTextAligned(mLeft, margin + 40, W - margin, margin + 80, taCenter, vaTop, '(by Lewis Carroll)');

{*** now we'll read the text file (to an array of lines) and draw paragraphs}

PDF.SetColorFill(0.0, 0.0, 0.0, 0.0);
PDF.UseFont(fnt, 11.0);

{your method readTextLines returns an array of text lines}
txt := readTextLines('Alice.txt');

{your method getNumOfLines returns a total number of text lines in the array}
totalLines := getNumOfLines(txt);

for i := 0 to totalLines do
begin
  y := PDF.GetCurrentTextY();
  if i = 0 then
     y := y + 60.0;
  else
    y := y + 34.0;
  PDF.ShowUnicodeTextParagraph(mLeft + 20, y, 3, -1, margin, margin, margin, margin, txt[i]);
end;

{*** save to file}
PDF.SaveToFile('Alice.pdf', true);
C/C++
[copy to clipboard]
// PDF object is supposed to be created

//*** prepare PDF for e-reader size
PDF->PageResolution = 166;
int W = 584;
int H = 754;
PDF->PageWidth = W;
PDF->PageHeight = H;
float margin = 10.0f;

//*** draw title and author
int fnt = PDF->AddFont("Some Font Family Name", false, false, false, false, fcDefault);
PDF->UseFont(fnt, 14.0f);
PDF->SetColorFill(0.0f, 0.0f, 0.0f, 0.0f);
PDF->ShowUnicodeTextAligned(mLeft, margin, W - margin, margin + 40, taCenter, vaTop, "Alice's Adventures in Wonderland");

PDF->UseFont(fnt, 12.0f);
PDF->SetColorFill(0.3f, 0.3f, 0.3f, 0.0f);
PDF->ShowUnicodeTextAligned(mLeft, margin + 40, W - margin, margin + 80, taCenter, vaTop, "(by Lewis Carroll)");

//*** now we'll read the text file (to an array of lines) and draw paragraphs

PDF->SetColorFill(0.0f, 0.0f, 0.0f, 0.0f);
PDF->UseFont(fnt, 11.0f);

//your method readTextLines returns an array of text lines
TCHAR** text = readTextLines("Alice.txt");

//your method getNumOfLines returns a total number of text lines in the array
int totalLines = getNumOfLines(text);

for(int i = 0; i < totalLines; i++)
{
  float y = PDF->GetCurrentTextY();
  if(i = 0)
    y += 60.0f;
  else
    y += 34.0f;
  CComBSTR txtLine = text[i];
  PDF->ShowUnicodeTextParagraph(mLeft + 20, y, 3, -1, margin, margin, margin, margin, txtLine);
}

//*** save to file
PDF->SaveToFile("Alice.pdf", TRUE);
C#
[copy to clipboard]
// PDF object is supposed to be created

//*** prepare PDF for e-reader size
PDF.PageResolution = 166;
int W = 584;
int H = 754;
PDF.PageWidth = W;
PDF.PageHeight = H;
float margin = 10.0f;

//*** draw title and author
int fnt = PDF.AddFont("Some Font Family Name", false, false, false, false, FontCharset.fcDefault);
PDF.UseFont(fnt, 14.0f);
PDF.SetColorFill(0.0f, 0.0f, 0.0f, 0.0f);
PDF.ShowUnicodeTextAligned(mLeft, margin, W - margin, margin + 40, TextAlign.taCenter, VerticalAlign.vaTop, "Alice's Adventures in Wonderland");

PDF.UseFont(fnt, 12.0f);
PDF.SetColorFill(0.3f, 0.3f, 0.3f, 0.0f);
PDF.ShowUnicodeTextAligned(mLeft, margin + 40, W - margin, margin + 80, TextAlign.taCenter, VerticalAlign.vaTop, "(by Lewis Carroll)");

//*** now we'll read the text file (to an array of lines) and draw paragraphs

PDF.SetColorFill(0.0f, 0.0f, 0.0f, 0.0f);
PDF.UseFont(fnt, 11.0f);

//your method readTextLines returns an array of text lines
string[] text = readTextLines("Alice.txt");

//your method getNumOfLines returns a total number of text lines in the array
int totalLines = getNumOfLines(text);

for(int i = 0; i < totalLines; i++)
{
  float y = PDF.GetCurrentTextY();
  if(i = 0)
    y += 60.0f;
  else
    y += 34.0f;
  PDF.ShowUnicodeTextParagraph(mLeft + 20, y, 3, -1, margin, margin, margin, margin, text[i]);
}

//*** save to file
PDF.SaveToFile("Alice.pdf", true);
Visual Basic Script
[copy to clipboard]
' PDF object is supposed to be created

'*** prepare PDF for e-reader size
PDF.PageResolution = 166
W = 584
H = 754
PDF.PageWidth = W
PDF.PageHeight = H
margin = 10

taCenter = 1
vaTop = 0
fcDefault = 1

'*** draw title and author
fnt = PDF.AddFont("Some Font Family Name", false, false, false, false, fcDefault)
PDF.UseFont fnt, 14
PDF.SetColorFill 0, 0, 0, 0
PDF.ShowUnicodeTextAligned mLeft, margin, W - margin, margin + 40, taCenter, vaTop, "Alice's Adventures in Wonderland"

PDF.UseFont fnt, 12
PDF.SetColorFill 0.3, 0.3, 0.3, 0
PDF.ShowUnicodeTextAligned mLeft, margin + 40, W - margin, margin + 80, taCenter, vaTop, "(by Lewis Carroll)"

'*** now we'll read the text file (to an array of lines) and draw paragraphs

PDF.SetColorFill 0, 0, 0, 0
PDF.UseFont fnt, 11

'your method readTextLines returns an array of text lines
text = readTextLines("Alice.txt")

'your method getNumOfLines returns a total number of text lines in the array
totalLines = getNumOfLines(text)

For i = 0 To totalLines
  y = PDF.GetCurrentTextY()
  if i = 0 then
    y = y + 60
  else
    y = y + 34
  end if
  PDF.ShowUnicodeTextParagraph mLeft + 20, y, 3, -1, margin, margin, margin, margin, text(i)
Next

'*** save to file
PDF.SaveToFile "Alice.pdf", true

See Also

Reference