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

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, which works fine with normal annotations such as highlights etc. But as I say, input field values don’t get merged.

Hello, I’m Ron, an automated tech support bot :robot:

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

Guides:APIs:Forums:

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

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

uvu_facility_modification_request.pdf (587.7 KB)

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

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/” 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.

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

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.

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

Thanks,
Logan

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:

<?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 (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.

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 (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

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