Skip to content

PDF Generation Template Editor

Open-source visual PDF generation engine with customizable templates and developer-friendly APIs.

View on GitHub

Get or Set Content Box ​

You can get or set content box with these API below.

Get the list of content boxes

javascript
const contentBoxesList = await documentViewer.getContentEditManager().loadContentBoxes(1) // The content boxes on the first page.

Then You can get or set the properties or content of the content box

javascript
const box = contentBoxesList.find(contentBox => contentBox.type === ContentEdit.Types.TEXT)

// Get the rect of the box
const rect = box.getBoxAttributes().rect

// Get the content of the box
const text = await ContentEdit.getContent(box)

// Insert text with index
const editor = await box.startContentEditing()
await editor.setSelection(index)
await editor.type('Test')

// Replace text with start and end
// start, end: The start and end character index of the text to be replaced
// Paragraphs in the text are separated by \n, and you can wrap the text with \n when inserting text
const start = 3
const end = 6
await editor.setSelection(start, end)
await editor.type('Test')

// Replace all text of the box
await ContentEdit.setContent(box, 'Test')

// Add text at end of the box
const textEditor = await box.startContentEditing()
await textEditor.setSelection(textEditor.getText().length)
await textEditor.type('Test')

const imageBox = contentBoxesList.find(contentBox => contentBox.type === ContentEdit.Types.OBJECT)
const imageEditor = await imageBox.startContentEditing()

// Replace with new image
await imageEditor.replaceImage(imageBase64)

// Get the image data
await imageEditor.extractImage()