Code Monkey home page Code Monkey logo

pdf-forms's Introduction

pdf-forms Build Status

http://github.com/jkraemer/pdf-forms/

Description

Fill out PDF forms with pdftk.

Installation

You'll need a working pdftk binary. Either get a binary package from http://www.pdflabs.com/tools/pdftk-server/ and install it, or run apt-get install pdftk if you're on Debian or similar.

After that, add pdf-forms to your Gemfile or manually install the gem. Nothing unusual here.

Using the Java port of PDFTK

The PDFTK package was dropped from most (all?) current versions of major Linux distributions. As contributed in this issue, you can use the Java version of PDFTK with this gem, as well. Just create a small shell script:

#!/bin/sh
MYSELF=`which "$0" 2>/dev/null`
[ $? -gt 0 -a -f "$0" ] && MYSELF="./$0"
java=java
if test -n "$JAVA_HOME"; then
    java="$JAVA_HOME/bin/java"
fi
exec "$java" $java_args -jar $MYSELF "$@"
exit 1

Next, concatenate the wrapper script and the Jar file, and you end up with an executable that can be used with pdf-forms:

cat stub.sh pdftk-all.jar > pdftk.run && chmod +x pdftk.run

Usage

FDF/XFdf creation

require 'pdf_forms'
fdf = PdfForms::Fdf.new :key => 'value', :other_key => 'other value'
# use to_pdf_data if you just want the fdf data, without writing it to a file
puts fdf.to_pdf_data
# write fdf file
fdf.save_to 'path/to/file.fdf'

To generate XFDF instead of FDF instantiate PdfForms::XFdf instead of PdfForms::Fdf

Query form fields and fill out PDF forms with pdftk

require 'pdf_forms'

# adjust the pdftk path to suit your pdftk installation
# add :data_format => 'XFdf' option to generate XFDF instead of FDF when
# filling a form (XFDF is supposed to have better support for non-western
# encodings)
# add :data_format => 'FdfHex' option to generate FDF with values passed in
# UTF16 hexadecimal format (Hexadecimal format has also proven more reliable
# for passing latin accented characters to pdftk)
# add :utf8_fields => true in order to get UTF8 encoded field metadata (this
# will use dump_data_fields_utf8 instead of dump_data_fields in the call to
# pdftk)
pdftk = PdfForms.new('/usr/local/bin/pdftk')

# find out the field names that are present in form.pdf
pdftk.get_field_names 'path/to/form.pdf'

# take form.pdf, set the 'foo' field to 'bar' and save the document to myform.pdf
pdftk.fill_form '/path/to/form.pdf', 'myform.pdf', :foo => 'bar'

# optionally, add the :flatten option to prevent editing of a filled out form.
# Other supported options are :drop_xfa and :drop_xmp.
pdftk.fill_form '/path/to/form.pdf', 'myform.pdf', {:foo => 'bar'}, :flatten => true

# to enable PDF encryption, pass encrypt: true. By default, a random 'owner
# password' will be used, but you can also set one with the :encrypt_pw option.
pdftk.fill_form '/path/to/form.pdf', 'myform.pdf', {foo: 'bar'}, encrypt: true, encrypt_options: 'allow printing'

# you can also protect the PDF even from opening by specifying an additional user_pw option:
pdftk.fill_form '/path/to/form.pdf', 'myform.pdf', {foo: 'bar'}, encrypt: true, encrypt_options: 'user_pw secret'

# if you are facing font issues with your pdf, you can specify :replacement_font option:
pdftk.fill_form '/path/to/form.pdf', 'myform.pdf', {foo: 'bar'}, replacement_font: '/path/to/font'

Any options shown above can also be set when initializing the PdfForms instance. In this case, options given to fill_form will override the global options.

Field names with HTML entities

In case your form's field names contain HTML entities (like Straße Hausnummer), make sure you unescape those before using them, i.e. CGI.unescapeHTML(name). Thanks to @phoet for figuring this out in #65.

Non-ASCII Characters (UTF8 etc) are not displayed in the filled out PDF

First, try to use the replacement_font option and specify the font that's not being displayed. If it doesn't work, check if the field value has been stored properly in the output PDF using pdftk output.pdf dump_data_fields_utf8.

If it has been stored but is not rendered, your input PDF lacks the proper font for your kind of characters. Re-create it and embed any necessary fonts. If the value has not been stored, there is a problem with filling out the form, either on your side, of with this gem.

Also see UTF-8 chars are not displayed in the filled PDF

Prior Art

The FDF generation part is a straight port of Steffen Schwigon's PDF::FDF::Simple perl module. Didn't port the FDF parsing, though ;-)

License

Created by Jens Kraemer and licensed under the MIT License.

pdf-forms's People

Contributors

adelevie avatar antoshalee avatar bliles avatar dmitry-ilyashevich avatar drnic avatar dsisnero avatar edusantana avatar iobaixas avatar jahkeup avatar jkraemer avatar jonrowe avatar konieczkow avatar mikesg avatar mr0grog avatar ndbroadbent avatar netinlet avatar robinator avatar sguha00 avatar smarquez1 avatar tyrro avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

pdf-forms's Issues

Concatenate method throwing error 'undefined method to_str for Hash'

NoMethodError - undefined method to_str' for #<Hash:0x007fc1b1680900>: pdf-forms (1.0.0) lib/pdf_forms/normalize_path.rb:9:innormalize_path'
pdf-forms (1.0.0) lib/pdf_forms/pdftk_wrapper.rb:92:in block in cat' pdf-forms (1.0.0) lib/pdf_forms/pdftk_wrapper.rb:92:incat'

I am trying to use this method to remove pages not combine files like this

@pdftk.cat( {file_input_path => ['1-2', '10-11']}, file_output_path)

I also duplicated your test script for this method and am getting the same error when trying to combine files.

The method works fine for simply combining 2 files like this

@pdftk.cat file_input_path_1, file_input_path_2, file_output_path

The error only arises when passing a Hash with page ranges as an argument

Support foreign characters.

Hey @jkraemer ,

I am trying to generate pdf with foreign characters. It works properly for french, portuguese, etc. But prints ???? for Arabic, Chinese and Hindi languages.

I upgraded this gem and now it points to 1.0.0 version. I used options as encrypt: true, :encrypt_options => 'allow Printing', but nothing works.

Will you please provide any pointers to achieve this i.e to support all languages ?

Thanks

undefined method `Pathname'

/var/lib/gems/2.3.0/gems/pdf-forms-1.1.0/lib/pdf_forms/normalize_path.rb:8:in `normalize_path': undefined method `Pathname' for #<PdfForms::Pdf:0x00000001d3fad0 @options={:utf8_fields=>true}> (NoMethodError)
    from /var/lib/gems/2.3.0/gems/pdf-forms-1.1.0/lib/pdf_forms/pdf.rb:13:in `initialize'
    from /var/lib/gems/2.3.0/gems/limarka-0.2.0/lib/limarka/trabalho.rb:144:in `new'
    from /var/lib/gems/2.3.0/gems/limarka-0.2.0/lib/limarka/trabalho.rb:144:in `ler_configuracao_pdf'
    from /var/lib/gems/2.3.0/gems/limarka-0.2.0/lib/limarka/trabalho.rb:138:in `ler_configuracao'
    from /var/lib/gems/2.3.0/gems/limarka-0.2.0/lib/limarka/trabalho.rb:124:in `atualiza_de_arquivos'
    from /var/lib/gems/2.3.0/gems/limarka-0.2.0/lib/limarka/cli.rb:84:in `exec2'
    from /usr/lib/ruby/vendor_ruby/thor/command.rb:27:in `run'
    from /usr/lib/ruby/vendor_ruby/thor/invocation.rb:126:in `invoke_command'
    from /usr/lib/ruby/vendor_ruby/thor.rb:359:in `dispatch'
    from /usr/lib/ruby/vendor_ruby/thor/base.rb:440:in `start'
    from /var/lib/gems/2.3.0/gems/limarka-0.2.0/exe/limarka:6:in `<top (required)>'
    from /usr/local/bin/limarka:23:in `load'
    from /usr/local/bin/limarka:23:in `<main>'

I'm using ruby 2.3.1p112 (2016-04-26) [x86_64-linux-gnu]

You can see from /var/lib/gems/2.3.0/gems/limarka-0.2.0/lib/limarka/trabalho.rb:144:in `new' it here
I was calling this line:

pdf = PdfForms::Pdf.new file, (PdfForms.new 'pdftk'), utf8_fields: true

PDF Security not working

Hi @jkraemer

Been a long time. Nice to "see" you again :)

I have a problem regarding the security options in PDF-Forms.

When using the options encrypt_password or encrypt_password they are not used. This is because of the Line 43 of current PdftkWrapper:

append_options args, fill_options

The append_options function in fact returns the new args but they are not used. Changing it to

args = append_options args, fill_options

brings up another error. In PdftkWrapperTest#test_fill_form_encrypted_and_flattened_with_encrypt_options it says:

PdfForms::PdftkError: failed to fill form with command
/usr/bin/pdftk test/fixtures/form.pdf fill_form /tmp/pdf_forms-fdf20160301-3337-dzbs59 output output.pdf flatten encrypt_128bit owner_pw /tmp/pdf_forms-fdf20160301-3337-dzbs59 allow printing
command output was:
Error: Unexpected data in output section:
allow printing
Exiting.
Errors encountered. No output created.
Done. Input errors, so no output created.

failing form data has been saved to /tmp/20160301152611.fdf

Executing the same command in a shell works. Also when not using SafeShell gem but unsafe %x(#{pdftk} #{args.flatten.join(' ')}) it works.

Do you have any idea?

Fun fact: The owner password is autmagically set super safe :)

Can't check a checkbox

Hello, I'm having the exact problem as #32. I'm able to fill text fields fine, but buttons don't work properly.

Im using pdf-forms on a specific document: 8850 IRS document. With pdftk I run pdftk f8850.pdf dump_data_fields I receive:

...

---
FieldType: Button
FieldName: topmostSubform[0].Page1[0].c1_1[0]
FieldFlags: 0
FieldJustification: Left
FieldStateOption: 1
FieldStateOption: Off

---
...

When I check the box in OSX preview, save and run pdftk again, I get:

...

---
FieldType: Button
FieldName: topmostSubform[0].Page1[0].c1_1[0]
FieldFlags: 0
FieldValue: 1
FieldJustification: Left
FieldStateOption: 1
FieldStateOption: Off

---
...

Here's how I use pdf-forms to fill out the checkbox:

➜  pdf_tests irb
irb(main):001:0> require 'pdf-forms'
irb(main):006:0> pdftk.get_fields('f8850.pdf').find{ |field| field.name == "topmostSubform[0].Page1[0].c1_2[0]"}
=> #<PdfForms::Field:0x007fe2ec14cdb0 @type="Button", @name="topmostSubform[0].Page1[0].c1_2[0]", @flags="0", @justification="Left", @options=["1", "Off"]>
irb(main):010:0> pdftk.fill_form 'f8850.pdf', 'new_f8850.pdf', {:"topmostSubform[0].Page1[0].c1_2[0]" => 1}

And then opening the new file I can see value is set:

irb(main):011:0> pdftk.get_fields('new_f8850.pdf').find{ |field| field.name == "topmostSubform[0].Page1[0].c1_2[0]"}
=> #<PdfForms::Field:0x007fe2ec1a3bb0 @type="Button", @name="topmostSubform[0].Page1[0].c1_2[0]", @flags="0", @justification="Left", @options=["1", "Off"], @value="1">

But opening the pdf file in OSX preview the checkbox isn't checked. :(

Any suggestions? Thank you!

some tests failing (ruby 2.5.1 / macos 10.13 / pdftk 2.02)

$ ruby -v
ruby 2.5.1p57 (2018-03-29 revision 63029) [x86_64-darwin17]
$ pdftk --version
pdftk 2.02 a Handy Tool for Manipulating PDF Documents

$ bundle exec rake
/Users/drnic/.rvm/rubies/ruby-2.5.1/bin/ruby -I"lib:lib:test" -I"/Users/drnic/.rvm/gems/ruby-2.5.1/gems/rake-10.5.0/lib" "/Users/drnic/.rvm/gems/ruby-2.5.1/gems/rake-10.5.0/lib/rake/rake_test_loader.rb" "test/**/*_test.rb"
Run options: --seed 28636

# Running:

..................F...........F....................

Finished in 17.399337s, 2.9311 runs/s, 6.9543 assertions/s.

  1) Failure:
PdftkWrapperTest#test_fill_form_and_encrypt_for_opening [/Users/drnic/Projects/rubygems/pdf-forms/test/pdftk_wrapper_test.rb:74]:
Expected /OWNER OR USER PASSWORD REQUIRED/ to match "Error: Failed to open PDF file: \n   output.pdf\n   OWNER PASSWORD REQUIRED, but not given (or incorrect)\nDone.  Input errors, so no output created.\n".

  2) Failure:
XfdfPdftkWrapperTest#test_fill_form_and_encrypt_for_opening [/Users/drnic/Projects/rubygems/pdf-forms/test/pdftk_wrapper_test.rb:74]:
Expected /OWNER OR USER PASSWORD REQUIRED/ to match "Error: Failed to open PDF file: \n   output.pdf\n   OWNER PASSWORD REQUIRED, but not given (or incorrect)\nDone.  Input errors, so no output created.\n".

51 runs, 121 assertions, 2 failures, 0 errors, 0 skips
rake aborted!
Command failed with status (1): [ruby -I"lib:lib:test" -I"/Users/drnic/.rvm/gems/ruby-2.5.1/gems/rake-10.5.0/lib" "/Users/drnic/.rvm/gems/ruby-2.5.1/gems/rake-10.5.0/lib/rake/rake_test_loader.rb" "test/**/*_test.rb" ]

`fill_form` with flatten option corrupts PDF file

I'm trying to use pdftk's fill_form functionality with the below PDF along with the flatten option so that values populating text fields can be frozen. However, upon getting the output file, the PDF seems to become corrupted.

For additional context, I've embedded a TrueType font (Lato) into the Input PDF (using Apache PDFBox), and set the font_name on the appearance objects for all the text fields in the input document.

Input PDF: http://www.filedropper.com/prefilled

Output PDF (Cannot be opened): http://www.filedropper.com/output

handling field names with a space

I have a fillable PDF with field names with spaces; e.g A field name like Employee Name
The following syntax is invalid because of the space between employee and name
pdftk.fill_form '/sample.pdf', 'myform.pdf', :employee name => 'Arnold'

How do you handle such field names.

Many thanks

Accented letters

When I try to fill forms using some accented letters (à,ò, ecc...) these are missing from the PDF.

Rails 5.0.0.1
Ruby 2.3.1
pdf-forms 1.1.1

pdftk 2.02

pdf 1.6 generated with Acrobat DC

Option to disable saving fdf data upon failure when filling out forms

Hey, thanks for building this wrapper around pdftk! I am currently using it to prefill a pdf form and it works great.

What: Adding an option to disable saving the fdf data upon failure when filling out a pdf.

Why: We log the errors and can reproduce them locally, we don't want to save the .fdf to the disk on production/staging machines.

Edit: Happy to make PR for it if you are on board with adding it.

Several issues (including CLI injections)

Hi!

I've looked into this gem and have several issues with it.

  def test_fill_form_cli_injection
    @pdftk.fill_form 'test/fixtures/form.pdf', 'output.pdf"; touch "test/cli_injection', 'program_name' => 'SOME TEXT' rescue nil
    refute File.exist?('test/cli_injection'), "CLI injection successful"
  ensure
    FileUtils.rm 'output.pdf' if File.exist?('output.pdf')
    FileUtils.rm 'test/cli_injection' if File.exist?('test/cli_injection')
  end

This test fails (so I injected something in the CLI successfully), and I'm sure there are more examples of this. Don't use %x #{command} #{args.join ' '}, use system(command, *args)

  1. Don't rescue Exception. You can rescue things that should fail, even syntax errors in included files. Rescue StandardError (which is the default) or a specific subclass.

  2. protected has a different meaning in Ruby compared to most other languages, I think you want to use private everywhere. Not a real problem, though.

  3. The gemspec is encoded with UTF-8, but the comment says ISO-8895-1. Causes rubygems.org to display your name with funny symbols.

fill_form hangs for minutes until interrupted

When I try to fill a form, it just hangs for minutes until I interrupt it. I am using this form, which is just a random form I found online. And here's my code:

pdftk = PdfForms.new('/usr/local/bin/pdftk')

pdftk.get_field_names '/tmp/example.pdf'
=> ["Given Name Text Box", "Family Name Text Box", ...]

pdftk.fill_form '/tmp/example.pdf', '/tmp/filled.pdf', 'Given Name Text Box' => "Steve", 'Family Name Text Box' => "Hanson"
# just hangs for minutes

If I interrupt, I get:

from /~/dev/my-app/vendor/bundle/gems/safe_shell-1.0.3/lib/safe_shell.rb:12:in `read'

It was also hanging on get_field_names for another form I was trying to use. Am I just doing something wrong? Would appreciate any advice.

I'm on Mac OS X El Capitan and installed pdftk using brew install https://raw.github.com/quantiverge/homebrew-binary/pdftk/pdftk.rb

German umlauts are not displayed in the filled PDF

Hi,

I have a PDF Template with the following exif data: https://gist.github.com/andywenk/93a0de7fae2c89d08e28

I am filling in data retrieved from a MySQL database. The encoding is utf8_unicode_ci for all fields. The template filler class is basically this:

class Pdf::TemplateFiller
  attr_reader :template_base_path, :template, :output, :output_base_path, :attributes, :pdftk

  def initialize
    @attributes         = {}
    @template           = ''
    @output             = ''
    @template_base_path = [Rails.root, APP_CONFIG[:pdf][:template_base_path]].join('/')
    @output_base_path   = [Rails.root, APP_CONFIG[:pdf][:output_base_path]].join('/')
    @pdftk              = PdfForms.new(APP_CONFIG[:pdf][:pdftk_binary], utf8_fields: true)
    fill_template
  end

  def generate
    pdftk.fill_form template_path, output_path, attributes, encrypt: true, flatten: true, encrypt_options: 'allow printing'
    output_path
  end

  def get_field_names
    pdftk.get_field_names template_path
  end

The fill_template method in another class looks like this:

def fill_template
  fill :anrede, @player.salutation
  fill :kundennummer, @player.customer_id
  fill :vorname, @player.first_name
  fill :name, @player.last_name
  fill :strasse, [@player.street, @player.house_number].join(' ')
  fill :ort, [@player.zip_code, @player.city].join(' ')
  fill :geburtsdatum, I18n.l(@player.date_of_birth)
end

When a name has german Umlauts like Andräs Müller the fields in the PDF only has Andr s M ller . But the field :strasse filled with Voßkamp is resulting in Voßkamp even though, ß is also a special character (but a German Umlaut).

Any idea what the problem is here? The exact same PDF form is used in another application based on Perl (with PDF::API2::Simple) and is working with German umlauts.

Thanks for any help or experience ...

`fill_form` not working

I'm trying to programmatically fill out this PDF: http://www.irs.gov/pub/irs-pdf/f1065sk1.pdf

and I'm seeing if your gem can help me. Here's the test script I'm using:

#!/usr/bin/env ruby

require 'pdf_forms'
require 'pry'

pdftk = PdfForms::PdftkWrapper.new('/usr/local/bin/pdftk')
pdf   = PdfForms::Pdf.new('2014_k1.pdf', pdftk)

field_names = pdf.fields.map(&:name)

field_values = field_names.map do |name|
  ret = {}
  ret[ name ] = name
  ret
end

pdftk.fill_form '2014_k1.pdf', 'filledout_k1.pdf', field_values

A PDF named filledout_k1.pdf is written to disk, but it doesn't have any fields filled out.

Do I need to convert the PDF to some other format to be able to fill it? I haven't done much with PDFs so I'm not sure how to go about it.

Field values containing `:` don't read in properly

Calling pdftk.get_fields returns incorrect values when a property's value (e.g. the name_alt) has a colon in it.

For example (pdftk output):


---
FieldType: Text
FieldName: Date
FieldNameAlt: Date: most recent
FieldFlags: 0
FieldValue: 
FieldJustification: Left

---

UTF-8 chars are not displayed in the filled PDF

Hi,

I have test pdf: http://s000.tinyupload.com/?file_id=77431117353383489288

I am filling in data with small script:

require "pp"

template_file = File.join(Rails.root, "form_example.pdf")
output_file = "output.pdf"

pdftk = PdfForms.new(`which pdftk`.chomp, utf8_fields: false, data_format: "XFdf")

pp pdftk.get_field_names template_file

pdf_data = {
  "name" => "różowy słoń ma usiąść na tępych gwoździach"
}

pdftk.fill_form template_file, output_file, pdf_data

After run got: http://take.ms/DrupC all utf8 letters dissapear (except ó)
Also attached generated pdf file: http://s000.tinyupload.com/index.php?file_id=32840734551043583650

Any idea what the problem is here? Why UTF-8 chars are not displayed?
Thanks for any help or experience.

insert image into one of fields

Is it possible to insert image into the fields. I don't see it mentioned in Readme file.
If yes how do I accomplish it?
Thanks

pdftk not supported on more and more platforms

Is anything being done to deal with the fact that pdftk is not well supported? For instance, it's not supported on aws linux without a lot of additional hassle. It seems that the library is not well maintained at this point

Cant get Hebrew to fill Correctly

Ive been looking through the issues here, and ive seen a lot of people complain about this, but it gets closed and not resolved.

Im literally trying to input Hebrew text into a PDF form, that has the exact same line of text as the one im trying to 'fill' in. So the PDF MUST have the font and characters, because its literally displaying it.

Nothing i can do from any of the the suggestions has been able to get non english to fill, even when you are trying to fill in a word that is present in the PDF, hence it has the needed embedded files.

Checked the dump_data_fields_utf8 on the PDF, and its fine.

If i add 'need_appearances' to the end of the command line, i end up with a pdf file that has blank forms, but if i click on one of the forms, i see the hebrew text. If i then simply add any character to the end of the string(via a external pdf editor), all of sudden functions.

This seems to have nothing to do with fonts, because once you do the trick ^ above, they even have the correct fonts.

Partially-filled PDF loses field data

When filling out a PDF using PdfForms (using latest master), the resulting PDF file loses its field data, even when explicitly passing the option flatten: false. This makes it impossible to fill out the PDF a second time (i.e. if the user only partially filled it out and wanted to return to it later).

Filling out the same PDF using pdftk on the command line, the data fields are retained on the resulting PDF file (verified via dump_data_fields command).

Any thoughts?

Corrupt PDF after flatten

I have a PDF containing form elements that I've processed using this command:

pdftk input.pdf output output.pdf flatten

It seems to work properly, but I can't read the resulting output PDF in Adobe Acrobat on MacOS X (Acrobat version is 15.20.20042.205528). When opening the file, Acrobat complains

"An error exists on this page. Acrobat may not display the page correctly. Please contact the person who created the PDF document to correct the problem.".

The PDF displays somewhat properly, except that form fields that were updated in the original PDF seem to be missing.

The output PDF does display correctly in the OS X "Preview" app.

Is there perhaps something else I need to do to "flatten" the PDF?

SafeShell breaks JRUBY

Version 1.02 of safeshell calls fork, causing this issue. Can you look into a temporary fix until they have 1.03, or otherwise be on the lookout for them to do that?

IOError

Hi,

I don't know what is wrong with my setup but I cannot read any pdf file apparently !
I initiate without any problem pdftk = PdfForms.new('/usr/local/bin/pdftk') but then I cannot get the pdf fields, either with a local pdf or one hosted on the web, I keep getting an IOError.

My controller :
def dossier_cpf @pdftk = PdfForms.new(Cliver.detect('pdftk')) @fields = @pdftk.get_field_names "#{Rails.root}/assets/images/dossier_cpf.pdf" end

Thanks for your help

Missing Options (drop_xfa)

I used the pdf-forms gem to populate a PDF file, which apparently had XFA data. The output file is not showing filled in form fields when I open it with Adobe Reader (no problem when a PDF viewer such as xpdf). The problem goes away when I add "drop_xfa" to the pdftk command, but AFAIK the gem doesn't support appending any options aside from flatten.

I made a small change in one of the source files (lib/pdf_forms/pdftk_wrapper.rb) where I enabled appending the "drop_xfa" option on my local branch and it's working.

Please advise. I can make a pull request with my changes. It seems that there are other missing options so they can be included too.

Thanks

utf8 field names changed with ruby 2.6.4

i was updating our app to ruby 2.6.4 when tests started failing on circleci, while they still work on OSX. field names are no longer parsed correctly:

"StraßeHausnummer", 
"Stra?eHausnummer", 

when sshing into the circle machine, i inspected the file with pdftk in order to check if that dependency was somehow misbehaving, but it looks fine:

circleci@b7c91700d2d9:~/repo$ pdftk test/fixtures/files/9ed34f0b050a833d8d3aeb063e789ece.pdf dump_data_fields_utf8

---
FieldType: Text
FieldName: StraßeHausnummer
FieldNameAlt: Straße/Hausnummer
FieldFlags: 0
FieldValue: StraßeHausnummer
FieldJustification: Left

any ideas?

Can't check a checkbox in the PDF

Hello. I seem to be having a similar issue to #22. I haven't been able to solve it using the solution there.

By running pdftk with dump_data_fields I'm able to see the following. I also opened up the PDF (it is a IRS W9 form) in OS X Preview, checked the box, ran pdftk again and see the same FieldStateOption values (it was suggested as a verification in the other issue).

FieldType: Button
FieldName: topmostSubform[0].Page1[0].FederalClassification[0].c1_1[0]
FieldFlags: 0
FieldValue: 1
FieldJustification: Left
FieldStateOption: 1
FieldStateOption: Off

I keep filling the checkbox with '1' per the FieldStateOption value I want (checked) but I'm not able to see the checkbox get checked in the PDF that is created.

Any other tips or suggestions? Thanks.

Pdf form

I have issue in the getting the field names from my pdf form. I did the following

pdftk = PdfForms.new('/usr/local/bin/pdftk')
pdftk.get_field_names("/home/my_user/my_form.pdf")

its return [].I have that form
my_form.pdf

undefined local variable or method `files' in cat method

Line 68 in /pdf-forms/blob/master/lib/pdf_forms/pdftk_wrapper.rb references the "files" array which is undefined.

You can dupe with:

pdftk = PdfForms.new('/usr/local/bin/pdftk')
pdftk.cat("file1.pdf","file2.pdf","output.pdf")

A quick look at the source indicates that "files" should be "input" instead. I'll try and fix and send a pull request, but wanted to report the issue first.

Cant fill field names with html escape characters

Firstly thanks a lot for this gem. It has been great to use.

I have a form that I am trying to fill using pdftk, and some of the field names are as follows:

Other Tests &#8211; one test per line, Row 15
Other Tests &#8211; one test per line, Throat

Unfortunately I cannot change the field names and pdftk doesn't seem to be able to fill them out. I also tried escaping the string, typing the actual character (en dash), but no success.. All the other fields get filled in fine but these fields I cannot seem to fill in no matter what I try..

Hyphen being replaced with question mark in PDF

I have a line on a PDF form which is being filled with the following text or text of a similar format: Lansing, MI 48901‑0726. In the PDF form itself, the line reads Lansing, MI 48901?0726. I've confirmed that the text doesn't have a question mark prior to being sent to fill_form, but after that I'm not sure what's happening to translate the hyphen to a question mark.

How to check checkbox

I have look deep into the gem but Could not found any method that check the checkbox.
So could you please let me know how can I check the checkbox.

Document supported distributions

Please document supported OS distributions this project is targeting.

Enterprise users may be interested to know that the latest version of CentOS (version 7) does not support pdftk, a dependency of this project.

Adding dynamic data to PDF

Hey @jkraemer ,

I have a very simple requirement that I am suppose to create PDF from dynamic/runtime-generated data into a PDF. Is this possible with this library ?
It seems we need to mention the necessary variables before filling up the pdf.

Any help on this will help alot

Thanks.

PDFTK Fill form not working - PDFTK (2.02) Mac OS (10.11.4) & Cent OS 7

Is there any issues with PDF form or I am doing something wrong?
I am using Mac on El Capitan

PdfForms::PdftkError - failed to fill form with command
"/usr/local/bin/pdftk" "/Users/bahire/Documents/NetbeansProjects/onboarding/lib/pdf_templates/IBC Resale Certificates.pdf" fill_form "/var/folders/7w/b15y7t8j6010_x6hkw53h93mzjc4qr/T/pdf_forms-fdf20150729-65729-13927kb" output "/Users/bahire/Documents/NetbeansProjects/onboarding/tmp/pdfs/IBC Resale Certificates_filled.pdf" flatten 2>&1
command output was:

failing form data has been saved to /var/folders/7w/b15y7t8j6010_x6hkw53h93mzjc4qr/T/20150729162322.fdf:

Another tool for PDF?

Are there any plans to make this gem compatible with another PDF tool? It seems PDFtk is not available in Linux distros like Fedora.

No exception if giving a non existing path to PdfForms.new

1.9.3p125 :013 > pdftk = PdfForms.new 'foobar'
 => #<PdfForms::PdftkWrapper:0x000001008ba5a0 @pdftk="foobar", @options={}> 
1.9.3p125 :014 > pdftk.get_field_names 'some_file.pdf'
 => []

Instead of returning an empty array this should raise an exception.

Permissions

Hi, Perhaps a newbie question but I need some help.

I'm on OSX and I installed PDFtk Server from here and, of course, the pdf-forms gem itself.

I jump in to irb to do some manual tests of the functionality and the first thing I encounter is a permissions error.

2.2.1 :001 > require 'pdf_forms'
 => true 
2.2.1 :002 > pdftk = PdfForms.new('/opt/pdflabs/pdftk/')
Errno::EACCES: Permission denied - /opt/pdflabs/pdftk/
    from /Users/thomas/.rvm/gems/ruby-2.2.1/gems/safe_shell-1.0.3/lib/safe_shell.rb:10:in `spawn'
    from /Users/thomas/.rvm/gems/ruby-2.2.1/gems/safe_shell-1.0.3/lib/safe_shell.rb:10:in `execute'
        ....

Any ideas?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.