# 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:** 1\
**Showing post:** 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

---

_[View the full topic](https://pdfjs.community/t/word-wrap-within-textannotation-widget/893)._
