# Word wrap within textannotation widget

**URL:** <https://pdfjs.community/t/word-wrap-within-textannotation-widget/893>\
**Category:** Technical Support\
**Tags:** pdfjs-express\
**Created:** [July 19, 2021, 5:22pm UTC](https://pdfjs.community/t/word-wrap-within-textannotation-widget/893 "2021-07-19T17:22:59Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![licenses](https://avatars.discourse-cdn.com/v4/letter/l/848f3c/32.png) [@licenses](https://pdfjs.community/u/licenses)\
**Post date:** [July 19, 2021, 5:22pm UTC](https://pdfjs.community/t/word-wrap-within-textannotation-widget/893/1 "2021-07-19T17:22:59Z")

</div>

**PDF.js Express Version**

**Detailed description of issue**  
I’m trying to add text content to a TextWidgetAnnotation (programatically, no UI) and I can’t seem to find any functionality to make the text wrap when the widget box ends. For now, I iterate through the widgets, find the field I want to fill with a "if (field.name === …) " and set the value use field.setValue.

**Expected behaviour**  
{Provide a screenshot or description of the expected behaviour}

**Does your issue happen with every document, or just one?**  
Any document

**Link to document**  
{Provide a link to the document in question if possible}

**Code snippet**  
async function addStandardFields(docViewer, annotManager) {  
if (templateInfo) {  
const documentURL = templateInfo.downloadUrl;  
let contents = await fileService.getExternalFileBlob(documentURL);  
setFileContent(contents);

```
    await docViewer.loadDocument(contents);

    await docViewer.getAnnotationsLoadedPromise();
    await mergeService.mergeDataIntoForm(annotManager.getFieldManager(), {
        jobsId: jobId,
        filePath: templateInfo.fullPath
    });
}

```

}

function addFields(commentWidgets, Annotations, annotManager) {  
if (wvinstance.current) {  
commentWidgets.forEach((annot: Annotations.TextWidgetAnnotation, index) =\> {  
const field = annot.getField();  
if (field.name === “interior-comments”) {  
field.setValue(props.data?.interiorComments ?? “”);  
}  
if (field.name === “exterior-comments”) {  
field.setValue(props.data?.exteriorComments ?? “”);  
}  
annotManager.addAnnotation(annot);  
annotManager.redrawAnnotation(annot);  
})  
}

}

const handleSubmit = async () =\> {  
const {docViewer, annotManager, Tools, Annotations} = wvinstance.current;  
const fieldManager = annotManager.getFieldManager();

```
await addStandardFields(docViewer, annotManager);

const annotationList = annotManager.getAnnotationsList();

const signatureWidgets = annotationList.filter(el => el.fieldName?.includes("signature"));
const comments = annotationList.filter(el => el.fieldName?.includes("comments"));
addSignatures(signatureWidgets, Annotations, annotManager);
addFields(comments, Annotations, annotManager);

const xfdf = await annotManager.exportAnnotations({links: false, widgets: false});
setAnnotationString(xfdf);

```

}

Thank you

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex031/uploads/pdfjscommunity/original/1X/ffbcd25c7d423db8d5acd5db201c272f4db306dd.png) [@system](https://pdfjs.community/u/system)\
**Post date:** [July 19, 2021, 5:23pm UTC](https://pdfjs.community/t/word-wrap-within-textannotation-widget/893/2 "2021-07-19T17:23:05Z")

</div>

**Hello, I’m Ron, an automated tech support bot 🤖**

While you wait for one of our customer support representatives to get back to you, please check out some of these documentation pages:

Guides:
- [Rich text](https://pdfjs.express/documentation/annotation/rich-text)
- [Customizing WebViewer UI Popups](https://pdfjs.express/documentation/ui-customization/customizing-popup)
- [Add Link to Annotations - Use WebViewer UI to Add Links to Annotations](https://pdfjs.express/documentation/annotation/add-link-to-annotation#use-webviewer-ui-to-add-links-to-annotations)

APIs:
- [Annotations.TextWidgetAnnotation - new TextWidgetAnnotation(field, options)](https://pdfjs.express/api/Annotations.TextWidgetAnnotation.html#TextWidgetAnnotation__anchor)
- [Annotations.WidgetAnnotation - setContents(value)](https://pdfjs.express/api/Annotations.WidgetAnnotation.html#setContents__anchor)
- [Tools.TextAnnotationCreateTool - new TextAnnotationCreateTool(docViewer, textAnnotationPrototype)](https://pdfjs.express/api/Tools.TextAnnotationCreateTool.html#TextAnnotationCreateTool__anchor)

Forums:
- [Add Annotation from top bar](https://pdfjs.community/t/add-annotation-from-top-bar/541/1)
- [Date picker widget dropdown years are too limited](https://pdfjs.community/t/date-picker-widget-dropdown-years-are-too-limited/715/1)
- [update the font-size during resizing the free hand text box to make the text always full fill the whole box](https://pdfjs.community/t/update-the-font-size-during-resizing-the-free-hand-text-box-to-make-the-text-always-full-fill-the-whole-box/136/1)
