Topics
All
MacOS
(Only)
Windows
(Only)
Linux
(Only, Not)
iOS
(Only, Not)
Components
Crossplatform Mac & Win
Server
Client
Old
Deprecated
Guides
Examples
Videos
New in version:
9.5
10.0
10.1
10.2
10.3
10.4
10.5
11.0
11.1
11.2
Statistic
FMM
Blog
Computes the width of a text string.
Component | Version | macOS | Windows | Linux | Server | iOS SDK |
DynaPDF | 5.0 | ✅ Yes | ✅ Yes | ✅ Yes | ✅ Yes | ✅ Yes |
Parameter | Description | Example |
---|---|---|
The PDF reference returned from DynaPDF.New. | ||
Text | The text to measure. | "Hello World" |
Returns width or error.
See also GetTextWidth function in DynaPDF manual.
Draw text over rectangle:
# where?
Set Variable [ $x ; Value: 100 ]
Set Variable [ $y ; Value: 100 ]
# the text
Set Variable [ $text ; Value: "Some blue text" ]
# set the font before measuring
Set Variable [ $r ; Value: MBS("DynaPDF.SetFont"; $pdf; "Helvetica"; 0; 12) ]
# measure now
Set Variable [ $width ; Value: MBS( "DynaPDF.GetTextWidth"; $pdf; $text ) ]
# draw rectangle width some addition 5 point margin
Set Variable [ $r ; Value: MBS("DynaPDF.SetFillColor"; $pdf; ,8; ,8; ,8) // light gray ]
Set Variable [ $r ; Value: MBS( "DynaPDF.Rectangle"; $pdf; $x - 5; $y - 5 - 2; $width + 10; 5 + 12 + 5; "fill") ]
# and draw text on top
Set Variable [ $r ; Value: MBS("DynaPDF.SetFillColor"; $pdf; 0; 0; 1) // 100% blue ]
Set Variable [ $r ; Value: MBS("DynaPDF.WriteText"; $pdf; 100; $x; $text) ]
Created 12nd November 2014, last changed 1st January 2021
DynaPDF.GetTextScaling - DynaPDF.GetTransparentColor
Feedback: Report problem or ask question.