# How to merge form input field values into a PDF for download?

**URL:** <https://pdfjs.community/t/how-to-merge-form-input-field-values-into-a-pdf-for-download/1429>\
**Category:** Technical Support\
**Created:** [March 1, 2022, 11:00pm UTC](https://pdfjs.community/t/how-to-merge-form-input-field-values-into-a-pdf-for-download/1429 "2022-03-01T23:00:57Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![psilva](https://avatars.discourse-cdn.com/v4/letter/p/d78d45/32.png) [@psilva](https://pdfjs.community/u/psilva)\
**Post date:** [March 1, 2022, 11:00pm UTC](https://pdfjs.community/t/how-to-merge-form-input-field-values-into-a-pdf-for-download/1429/1 "2022-03-01T23:00:57Z")

</div>

**Which product are you using?**  
PDF.js Express Plus  
Version 8.1.1

**Detailed description of issue**  
I’m trying to merge a form PDF for download but I can only get normal annotations to merge. Input fields aren’t merged, and don’t show up in the final PDF (even though they do show up in the XFDF string).

**Does your issue happen with every document, or just one?**  
This happens with every document.

**Code snippet**  
I’m making a simple call to [https://api.pdfjs.express/xfdf/merge](https://api.pdfjs.express/xfdf/merge), which works fine with normal annotations such as highlights etc. But as I say, input field values don’t get merged.

---

<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:** [March 1, 2022, 11:01pm UTC](https://pdfjs.community/t/how-to-merge-form-input-field-values-into-a-pdf-for-download/1429/3 "2022-03-01T23:01:03Z")

</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:
- [Set XFDF using the Express REST API - Body params](https://pdfjs.express/documentation/utils/set#body-params)
- [Migrating from PDF.js Express to PDFTron - 4. Updating merge and extraction code](https://pdfjs.express/documentation/learn-more/pdfjs-express-to-pdftron.8#4.-updating-merge-and-extraction-code)
- [Flatten Annotations](https://pdfjs.express/documentation/advanced/flatten-annotations)

APIs:
- [PDF.js Express Utilities](https://pdfjs.express/api/utils/index.html#__anchor)
- [Core.Annotations.TextWidgetAnnotation - new TextWidgetAnnotation(field, options)](https://pdfjs.express/api/Core.Annotations.TextWidgetAnnotation.html#TextWidgetAnnotation__anchor)
- [ExpressUtils(optionsopt) - # async set() → {Promise.}](https://pdfjs.express/api/utils/ExpressUtils.html#set__anchor)

Forums:
- [How to merge signature annotation with PDF document](https://pdfjs.community/t/how-to-merge-signature-annotation-with-pdf-document/558/1)
- [Load document by Url and save with watermark and html](https://pdfjs.community/t/load-document-by-url-and-save-with-watermark-and-html/502/1)
- [Do annotations from setCustomDrawHandler make it to the downloadable file?](https://pdfjs.community/t/do-annotations-from-setcustomdrawhandler-make-it-to-the-downloadable-file/927/1)

---

<div class="post-metadata">

**Author:** ![Logan](https://yyz1.discourse-cdn.com/flex031/user_avatar/pdfjs.community/logan/32/13_2.png) [@Logan](https://pdfjs.community/u/Logan)\
**Post date:** [March 2, 2022, 4:33pm UTC](https://pdfjs.community/t/how-to-merge-form-input-field-values-into-a-pdf-for-download/1429/4 "2022-03-02T16:33:48Z")

</div>

Hey there!

I cannot reproduce your issue.

Are you able to share the document you are testing with, as well as the code you are using to merge?

Thanks!  
Logan

---

<div class="post-metadata">

**Author:** ![psilva](https://avatars.discourse-cdn.com/v4/letter/p/d78d45/32.png) [@psilva](https://pdfjs.community/u/psilva)\
**Post date:** [March 2, 2022, 5:51pm UTC](https://pdfjs.community/t/how-to-merge-form-input-field-values-into-a-pdf-for-download/1429/5 "2022-03-02T17:51:56Z")

</div>

Here is the PDF form document attached that I’m having this issue with.

[uvu\_facility\_modification\_request.pdf](https://pdfjs.community/uploads/short-url/t2Y8DCrdG1IjNixOaqzTqrzDLB2.pdf) (587.7 KB)

The code is a simple call to the merge endpoint in ruby, which works fine for normal annotations.

```javascript
uri = URI("https://api.pdfjs.express/xfdf/merge")
https = Net::HTTP.new(uri.host, uri.port)
https.use_ssl = true
request = Net::HTTP::Post::Multipart.new(uri, file: file_url, xfdf: params[:xfdf], license: "ourlicense")
response = https.request(request)
render json: response.body

```

And the XFDF string here in params[:xfdf] shows the input field values correctly. Here is an example:

“\<?xml version=\"1.0\" encoding=\"UTF-8\" ?\>\<xfdf xmlns=“[http://ns.adobe.com/xfdf/](http://ns.adobe.com/xfdf/)” xml:space=“preserve”\>\<field name=“project\_number”\>1413434\<field name=“building\_name\_or\_location”\>\<field name=“room\_numbers”\>12345\<field name=“name”\>Lucas Creator\<field name=“department\_title”\>Dept test title\<field name=“name\_of\_department\_head”\>\<field name=“name\_of\_dean”\>\<field name=“name\_of\_vp”\>\<field name=“signature\_3”\>\<field name=“signature\_3\_date”\>\<field name=“signature\_2”\>\<field name=“signature\_2\_date”\>\<field name=“signature\_1”\>\<field name=“signature\_1\_date”\>\<field name=“first\_question”\>qecq ec qec q ec qec q ecqce\<field name=“second\_question”\>q ec qec qec q c qc q ec qec \<field name=“project\_justification”\>qe c qec qe c qec qe c qec q ec qec\<field name=“project\_description”\> er e qer qer q er qer q er qer\<field name=“index\_code”\>134134\<field name=“name\_of\_pm”\>\<field name=“signature\_4”\>\<field name=“signature\_4\_date”\>\<field name=“authorized\_signature\_name”\>\<field name=“signature\_5”\>\<field name=“signature\_5\_date”\>\<field name=“pm\_comments”\>\<defmtx matrix=“1,0,0,-1,0,841.91998” /\>”

But the input values don’t show in the final exported/merged PDF.

---

<div class="post-metadata">

**Author:** ![psilva](https://avatars.discourse-cdn.com/v4/letter/p/d78d45/32.png) [@psilva](https://pdfjs.community/u/psilva)\
**Post date:** [March 9, 2022, 12:42pm UTC](https://pdfjs.community/t/how-to-merge-form-input-field-values-into-a-pdf-for-download/1429/6 "2022-03-09T12:42:27Z")

</div>

Hey Logan, were you able to reproduce with the file I sent? @Logan

---

<div class="post-metadata">

**Author:** ![Logan](https://yyz1.discourse-cdn.com/flex031/user_avatar/pdfjs.community/logan/32/13_2.png) [@Logan](https://pdfjs.community/u/Logan)\
**Post date:** [March 11, 2022, 3:41pm UTC](https://pdfjs.community/t/how-to-merge-form-input-field-values-into-a-pdf-for-download/1429/7 "2022-03-11T15:41:12Z")

</div>

Hey there,

Where are you getting that XFDF from? The XFDF you sent is invalid which is probably why it is not working the way you expect.

 ![image](https://canada1.discourse-cdn.com/flex031/uploads/pdfjscommunity/original/1X/cfb06516da376403387cd903dfce96d7ad34a8ba.png)

You are not closing any of the XML tags and the XML is not properly formatted.

This is what the XFDF _should_ look like:

![image](https://canada1.discourse-cdn.com/flex031/uploads/pdfjscommunity/original/1X/c2a64390430ba309a74d6b3dd5ee6531867cbee8.png)

Thanks,  
Logan

---

<div class="post-metadata">

**Author:** ![psilva](https://avatars.discourse-cdn.com/v4/letter/p/d78d45/32.png) [@psilva](https://pdfjs.community/u/psilva)\
**Post date:** [March 15, 2022, 10:17pm UTC](https://pdfjs.community/t/how-to-merge-form-input-field-values-into-a-pdf-for-download/1429/8 "2022-03-15T22:17:32Z")

</div>

Hey Logan,

Sorry I must’ve copy pasted that wrong. The XFDF string is definitely correct when it’s used in our code, because as I mentioned earlier signatures do work and show up fine in the final merged PDF, but the input fields stay blank. Here is the correct formatted XFDF for a test I just ran:

```javascript
<?xml version="1.0" encoding="UTF-8" ?>
<xfdf
	xmlns="http://ns.adobe.com/xfdf/" xml:space="preserve">
	<fields>
		<field name="project_number">
			<value>1334</value>
		</field>
		<field name="building_name_or_location">
			<value></value>
		</field>
		<field name="room_numbers">
			<value>qecqec</value>
		</field>
		<field name="name">
			<value>qec</value>
		</field>
		<field name="department_title">
			<value>qccq</value>
		</field>
		<field name="name_of_department_head">
			<value>qerqer</value>
		</field>
		<field name="name_of_dean">
			<value></value>
		</field>
		<field name="name_of_vp">
			<value></value>
		</field>
		<field name="signature_3">
			<value></value>
		</field>
		<field name="signature_3_date">
			<value></value>
		</field>
		<field name="signature_2">
			<value></value>
		</field>
		<field name="signature_2_date">
			<value></value>
		</field>
		<field name="signature_1">
			<value></value>
		</field>
		<field name="signature_1_date">
			<value>Mar 15, 2022 7:12 PM</value>
		</field>
		<field name="first_question">
			<value>qefqfe</value>
		</field>
		<field name="second_question">
			<value>qefqef</value>
		</field>
		<field name="project_justification">
			<value>qefqef</value>
		</field>
		<field name="project_description">
			<value></value>
		</field>
		<field name="index_code">
			<value></value>
		</field>
		<field name="name_of_pm">
			<value></value>
		</field>
		<field name="signature_4">
			<value></value>
		</field>
		<field name="signature_4_date">
			<value></value>
		</field>
		<field name="authorized_signature_name">
			<value></value>
		</field>
		<field name="signature_5">
			<value></value>
		</field>
		<field name="signature_5_date">
			<value></value>
		</field>
		<field name="pm_comments">
			<value></value>
		</field>
	</fields>
	<annots>
		<ink page="0" rect="308.963,442.766,361.380,472.088" color="#000000" flags="print" name="18a18011-edef-19d9-fe10-9323b23e035f" title="Guest" subject="Signature" date="D:20220315191251-03'00'" creationdate="D:20220315191251-03'00'">
			<trn-custom-data bytes="{&quot;trn-annot-maintain-aspect-ratio&quot;:&quot;true&quot;}"/>
			<inklist>
				<gesture>334.3160945157527,471.82568728121356;334.3160945157527,471.82568728121356;334.0309719953326,471.5405647607935;333.7458494749125,470.97031971995335;331.1797467911319,466.4083593932322;329.1838891481914,462.7017666277713;324.90705134189034,453.5778459743291;322.9111936989499,450.15637572928824;319.7748459743291,445.024170361727;317.7789883313886,443.0283127187865;313.7872730455076,443.31343523920657;311.7914154025671,445.8795379229872;309.5104352392066,454.1480910151692;309.2253127187865,456.7141936989498;309.5104352392066,461.56127654609105;310.9360478413069,462.7017666277713;320.05996849474917,460.70590898483084;326.04754142357064,457.8546837806301;338.8780548424738,450.15637572928824;344.0102602100351,447.02002800466744;349.99783313885655,443.8836802800467;353.4193033838974,443.0283127187865;358.2663862310386,444.4539253208868;359.40687631271885,445.5944154025671;361.11761143523927,448.7307631271879</gesture>
			</inklist>
		</ink>
	</annots>
	<pages>
		<defmtx matrix="1,0,0,-1,0,841.91998" />
	</pages>
</xfdf>

```

Also here is the final PDF this XFDF is giving me:  
[merged.pdf](https://pdfjs.community/uploads/short-url/zZEptj0zMaByK3occaGrVRH6djJ.pdf) (592.2 KB)

As you can see the signature I added shows up fine, but the input text from other fields in the XFDF don’t show up.

Looking at this XFDF a bit closer I noticed the input fields and the signature are in different sections. The signature is in the “annots” section. Do I have to do something special to merge the field values onto the PDF? Seems like only annotations are getting merged, and none of the field values.

---

<div class="post-metadata">

**Author:** ![Logan](https://yyz1.discourse-cdn.com/flex031/user_avatar/pdfjs.community/logan/32/13_2.png) [@Logan](https://pdfjs.community/u/Logan)\
**Post date:** [March 18, 2022, 2:25pm UTC](https://pdfjs.community/t/how-to-merge-form-input-field-values-into-a-pdf-for-download/1429/9 "2022-03-18T14:25:07Z")

</div>

Hey there!

I tried doing this with your XFDF can I can reproduce your issue. However I still believe your XFDF still is not correct. When I extract the XFDF using our library I get a different result (see attached - it’s zipped because you cannot upload XML files here).

[mine.xml.zip](https://pdfjs.community/uploads/short-url/cznsBf9xsogkTkl2qGrUbLfuk3Y.zip) (2.2 KB)

I believe your XFDF is missing the `ffield` and `widget` tags.

How are you currently producing the XFDF you are using?

Thanks,  
Logan

---

<div class="post-metadata">

**Author:** ![psilva](https://avatars.discourse-cdn.com/v4/letter/p/d78d45/32.png) [@psilva](https://pdfjs.community/u/psilva)\
**Post date:** [March 21, 2022, 3:12pm UTC](https://pdfjs.community/t/how-to-merge-form-input-field-values-into-a-pdf-for-download/1429/10 "2022-03-21T15:12:39Z")

</div>

Hey Logan,

Looks like the issue was that when I pulled the XFDF string I was setting the widgets option to false. Setting it to true I get the `ffield` and `widget` tags and everything works fine.

Thanks for your help.

Lucas
