Skip to main content

TextFont Class

A font used to draw text in a PDF document.

Declaration

public class TextFont extends JavaObject implements IEquatable<TextFont>

Remarks

The following code snippet adds a text fragment with custom formatting:

import com.devexpress.docs.pdf.*;
import com.devexpress.drawing.*;
import com.devexpress.system.drawing.*;
import com.devexpress.drawing.printing.*;

import java.nio.channels.*;
import java.nio.file.*;

public class Main {
    public static void main(String[] args) throws Exception {
        // Create a new PDF document.
        try (PdfDocument pdfDocument = new PdfDocument()) {

            // Add a Letter-size page to the document.
            Page page = pdfDocument.getPages().add(DXPaperKind.LETTER);

            TextFragment text = new TextFragment();
            text.setFont(new TextFont("Courier New"));
            text.setLocation(new PointF(10, 740));
            text.setText("The PDF Document API");
            text.setFontSize(18);

            page.addFragment(text);

            // Save the document to a PDF file.
            try (WritableByteChannel writableByteChannel =
                    FileChannel.open(Path.of("result.pdf"),
                        StandardOpenOption.CREATE,
                        StandardOpenOption.WRITE,
                        StandardOpenOption.TRUNCATE_EXISTING)) {

                pdfDocument.save(writableByteChannel);
            }
        }
    }
}

Implements

com.devexpress.system.IEquatable<com.devexpress.docs.pdf.TextFont>

Inherited Members

com.devexpress.system.JavaObject.clone()
com.devexpress.system.JavaObject.equals(java.lang.Object)
com.devexpress.system.JavaObject.hashCode()
com.devexpress.system.JavaObject.initFields()
com.devexpress.system.JavaObject.memberwiseClone()
com.devexpress.system.JavaObject.toString()
java.lang.Object.finalize()
java.lang.Object.getClass()
java.lang.Object.notify()
java.lang.Object.notifyAll()
java.lang.Object.wait()
java.lang.Object.wait(long)
java.lang.Object.wait(long,int)

Inheritance

Object
com.devexpress.system.JavaObject
TextFont

Constructors

TextFont(String familyName, TextFontStyle style) Constructor

Initializes a new instance of the TextFont class with the specified font family name and style.

Declaration

public TextFont(String familyName, TextFontStyle style)

Parameters

Name Type Description
familyName String

The font family name.

style TextFontStyle

The font style.

TextFont(String familyName) Constructor

Initializes a new instance of the TextFont class with the specified font family name.

Declaration

public TextFont(String familyName)

Parameters

Name Type Description
familyName String

The font family name.

Methods

equals(Object obj) Method

Determines whether the specified object is equal to this font.

Declaration

public boolean equals(Object obj)

Parameters

Name Type Description
obj Object

The object to compare with this font.

Returns

Type Description
boolean

true if the specified object is equal to this font; otherwise, false.

equals(TextFont other) Method

Determines whether the specified font is equal to this font.

Declaration

public boolean equals(TextFont other)

Parameters

Name Type Description
other TextFont

The font to compare with this font.

Returns

Type Description
boolean

true if the specified font is equal to this font; otherwise, false.

getBaseFont() Method

Returns the base font name.

Declaration

public String getBaseFont()

Returns

Type Description
String

The base font name.

getFamilyName() Method

Returns the font family name.

Declaration

public String getFamilyName()

Returns

Type Description
String

The font family name.

getIsEmbedded() Method

Returns whether this font is embedded in the document.

Declaration

public boolean getIsEmbedded()

Returns

Type Description
boolean

true if this font is embedded in the document; otherwise, false.

getStyle() Method

Returns the font style.

Declaration

public TextFontStyle getStyle()

Returns

Type Description
TextFontStyle

The font style.

hashCode() Method

Returns the hash code for this font.

Declaration

public int hashCode()

Returns

Type Description
int

The hash code for this font.

toString() Method

Returns the string representation of this font.

Declaration

public String toString()

Returns

Type Description
String

The string representation of this font.