FPdfTextBox
Facade for a simple editable PDF text box.
Access
Access through:
Inheritance
Extends FPdfPageElement. Its inherited members are available on this object.
Example
const pdf = univerAPI.getActivePdf()const page = pdf.getPageByIndex(0)const textBox = page.insertTextBox({ text: 'Hello PDF', left: 36, top: 36,})console.log(textBox?.getText())textBox .setText('Updated text') .setTextStyle( { bold: true, }, { start: 0, end: 5, }, ) .setTextAnchor(univerAPI.Enum.PdfTextAnchor.MIDDLE)console.log(textBox?.getText())Setup
Register @univerjs-pro/pdfs or a preset that includes it. In plugin mode, import @univerjs-pro/pdfs/facade. Additional methods below require their listed plugin packages. See Facade setup.
@univerjs-pro/pdfs
FPdfTextBox.getText
Return the current materialized text.
getText(): stringReturns
The complete text-box text.
Examples
const pdf = univerAPI.getActivePdf()const page = pdf.getPageByIndex(0)const textBox = page.getTextBoxes()[0]console.log(textBox?.getText())Package: @univerjs-pro/pdfs · Type definitions
FPdfTextBox.getTextAnchor
Return the current vertical text anchor.
getTextAnchor(): PdfTextAnchorReturns
The current text anchor.
Examples
const pdf = univerAPI.getActivePdf()const page = pdf.getPageByIndex(0)const textBox = page.getTextBoxes()[0]console.log(textBox?.getTextAnchor())Types: PdfTextAnchor
Package: @univerjs-pro/pdfs · Type definitions
FPdfTextBox.getTextRuns
Return detached text runs in visual order.
getTextRuns(): readonly IPdfTextRun[]Returns
Detached text-run snapshots.
Examples
const pdf = univerAPI.getActivePdf()const page = pdf.getPageByIndex(0)const textBox = page.getTextBoxes()[0]console.log(textBox?.getTextRuns())Types: IPdfTextRun
Package: @univerjs-pro/pdfs · Type definitions
FPdfTextBox.setText
Replace the complete text while retaining compatible run styling.
setText(text: string): thisParameters
text— Required. The replacement text.
Returns
This text-box Facade for chaining.
Examples
const pdf = univerAPI.getActivePdf()const page = pdf.getPageByIndex(0)const textBox = page.getTextBoxes()[0]if (textBox) { textBox.setText('Updated text')}Package: @univerjs-pro/pdfs · Type definitions
FPdfTextBox.setTextAnchor
Set the vertical text anchor.
setTextAnchor(anchor: PdfTextAnchor): thisParameters
anchor— Required. The new text anchor.
Returns
This text-box Facade for chaining.
Examples
const pdf = univerAPI.getActivePdf()const page = pdf.getPageByIndex(0)const textBox = page.getTextBoxes()[0]if (textBox) { textBox.setTextAnchor(univerAPI.Enum.PdfTextAnchor.MIDDLE)}Types: PdfTextAnchor
Package: @univerjs-pro/pdfs · Type definitions
FPdfTextBox.setTextStyle
Apply text styling to the whole box or one UTF-16 range.
setTextStyle(style: IPdfTextStyle, range?: IPdfTextRange): thisParameters
style— Required. The text style patch.range— Optional. An optional UTF-16 range.
Returns
This text-box Facade for chaining.
Examples
const pdf = univerAPI.getActivePdf()const page = pdf.getPageByIndex(0)const textBox = page.getTextBoxes()[0]if (textBox) { textBox.setTextStyle( { bold: true, }, { start: 0, end: 5, }, )}Types: IPdfTextStyle · IPdfTextRange
Package: @univerjs-pro/pdfs · Type definitions
How is this guide?