<?xml version='1.0' encoding='utf-8' ?>

<rss version='2.0' xmlns:lj='http://www.livejournal.org/rss/lj/1.0/' xmlns:atom10='http://www.w3.org/2005/Atom'>
<channel>
  <title>Matthew&apos;s Journal</title>
  <link>https://emperor.dreamwidth.org/</link>
  <description>Matthew&apos;s Journal - Dreamwidth Studios</description>
  <lastBuildDate>Tue, 15 May 2018 18:09:42 GMT</lastBuildDate>
  <generator>LiveJournal / Dreamwidth Studios</generator>
  <lj:journal>emperor</lj:journal>
  <lj:journaltype>personal</lj:journaltype>
  <image>
    <url>https://v2.dreamwidth.org/34327/59046</url>
    <title>Matthew&apos;s Journal</title>
    <link>https://emperor.dreamwidth.org/</link>
    <width>84</width>
    <height>96</height>
  </image>

<item>
  <guid isPermaLink='true'>https://emperor.dreamwidth.org/682924.html</guid>
  <pubDate>Tue, 15 May 2018 18:09:42 GMT</pubDate>
  <title>Filling in PDF forms from the linux command line</title>
  <link>https://emperor.dreamwidth.org/682924.html</link>
  <description>I needed to fill in a PDF form recently (the proper editable sort, not a flat PDF with empty spaces); me being me I wanted to use Free tools, and ideally do so in a way that I could use version control on the bits I was adding to the form.&lt;br /&gt;&lt;br /&gt;Thankfully, with &lt;code&gt;pdftk&lt;/code&gt;, this is pretty doable. It was mostly only a bit fiddly because there wasn&apos;t a coherent answer to some of the edge cases (e.g. round tick boxes). Basically, the process is:&lt;br /&gt;&lt;br /&gt;&lt;ol&gt;&lt;br /&gt;&lt;li&gt;&lt;code&gt;pdftk generate_fdf&lt;/code&gt; to get the file you want to edit&lt;/li&gt;&lt;li&gt;&lt;code&gt;pdftk dump_data_fields&lt;/code&gt; if necessary to learn about tickboxes&lt;/li&gt;&lt;li&gt;edit the fdf file&lt;/li&gt;&lt;li&gt;&lt;code&gt;pdftk fill_form&lt;/code&gt; to fill the form in&lt;/li&gt;&lt;br /&gt;&lt;/ol&gt;&lt;br /&gt;&lt;br /&gt;As an example form, &lt;a href=&quot;https://www.gov.uk/government/uploads/system/uploads/attachment_data/file/688390/n1-eng.pdf&quot;&gt;here&lt;/a&gt;&apos;s a publically-available one. If you run &lt;code&gt;pdftk n1-eng.pdf generate_fdf output fields.fdf&lt;/code&gt;, you get an .fdf (Form Data Format) file. It looks a bit weird, but basically you can edit the relevant bits of contents as text.&lt;br /&gt;&lt;br /&gt;An excerpt:&lt;br /&gt;&lt;pre&gt;
&amp;lt;&amp;lt;
/V ()
/T (In the)
&amp;gt;&amp;gt; 
&amp;lt;&amp;lt;
/V /
/T (Check Box34)
&amp;gt;&amp;gt; 
&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;So if you put some text in the parentheses above &quot;In the&quot;, then that text appears in the relevant box on the form. In this case, it&apos;s pretty obvious where on the form that&apos;s going to be, but not all the fields are so obvious - where is &lt;code&gt;Text28&lt;/code&gt;, for example?&lt;br /&gt;&lt;br /&gt;You can, obviously, put dummy data in each place, fill the form out and observe the results. That&apos;s fine, but obviously doesn&apos;t help with the Check Boxes. To find out more, you want &lt;code&gt;pdftk dump_data_fields&lt;/code&gt;, which includes for this form:&lt;br /&gt;&lt;br /&gt;&lt;pre&gt;
---
FieldType: Text
FieldName: Text28
FieldNameAlt: Brief details of claim
FieldFlags: 12587008
FieldJustification: Left
---
FieldType: Button
FieldName: Check Box34
FieldFlags: 0
FieldJustification: Left
FieldStateOption: Off
FieldStateOption: tickbox No - Does, or will, your claim include any issues under the Human Rights Act 1998?
FieldStateOption: tickbox Yes - Does, or will, your claim include any issues under the Human Rights Act 1998?
---
&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;From this, we can see that &lt;code&gt;Text28&lt;/code&gt; is where we put the &quot;Brief details of claim&quot;. It also tells us how to tick the relevant tickbox about the HRA 1998, though it&apos;s a bit non-obvious. What you do is include &lt;em&gt;the entire FieldStateOption of the box you want&lt;/em&gt;, thus:&lt;br /&gt;&lt;br /&gt;&lt;pre&gt;
&amp;lt;&amp;lt;
/V (tickbox No - Does, or will, your claim include any issues under the Human Rights Act 1998?)
/T (Check Box34)
&amp;gt;&amp;gt; 
&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;So you can edit everything into the FDF file, and keep it in git (and get useful diffs), and then turn it into a filled-out PDF with &lt;code&gt;pdftk form.pdf fill_form data.fdf output form.filled.pdf&lt;/code&gt; - the form is neatly filled out, including the tick-boxes!&lt;br /&gt;&lt;br /&gt;&lt;img src=&quot;https://www.dreamwidth.org/tools/commentcount?user=emperor&amp;ditemid=682924&quot; width=&quot;30&quot; height=&quot;12&quot; alt=&quot;comment count unavailable&quot; style=&quot;vertical-align: middle;&quot;/&gt; comments</description>
  <comments>https://emperor.dreamwidth.org/682924.html</comments>
  <category>pdf</category>
  <category>nargery</category>
  <lj:security>public</lj:security>
  <lj:reply-count>1</lj:reply-count>
</item>
</channel>
</rss>
