Datalogics PDF Fill in Rails

I am trying to use Datalogics PDF ( https://api.datalogics-cloud.com/docs#fillform ) to fill out a fillable pdf (made with adobe acrobat) in my rails.

It's hard for me to figure out how to make an api call. That is, I can not understand where / how to put the parameters. Any help is much appreciated! Thank!

One example is the use of curl, so in the controller action I put curl https://pdfprocess.datalogics.com/api/actions/render/pages --insecure --form 'application={"id": "xxxxx", "key": "xxxxxxx"}' --form input=@hello_world.pdf --form inputName=hello_world.pdf --output flattened.pdfthat aligns pdf hello_world (located in my rails root) into a pdf named flattened.pdf.

I am not sure how to understand this code.

In addition, I was thinking about using a form instead of using a controller whose action is a URL and has tags of different fields, is this a valid option?

For the fill form, I am trying to execute this curl command:

`curl https://pdfprocess.datalogics.com/api/actions/fill/form --insecure --form 'application={"id": "xxxxx", "key": "xxxxxx"}' --form input=@private/fillable/CG1218_6-95.pdf --form filename=@input.json --output flattened.pdf`
+4
source share
1 answer

You can use an HTTP request for this. I have compiled the code, which you can see below. Your query should be needed for several parts, and so you will need to define a boundary. The query that I have below relates to the DocumentProperties service. You will need to modify it a bit to add values ​​to fill out the form. Note that you will need to use "File.read ()" to read the file with the values ​​when it is passed.

You can see the corresponding code below.

# Initialize a new HTTPS request object with our URL
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
http.verify_mode = OpenSSL::SSL::VERIFY_NONE

##
# The Content-Type field for multipart entities requires one parameter, "boundary",
# which is used to specify the encapsulation boundary. The encapsulation boundary
# is defined as a line consisting entirely of two hyphen characters ("-", decimal code 45)
# followed by the boundary parameter value from the Content-Type header field.

BOUNDARY = 'BoundaryString'

# Initialize a new Post request
request = Net::HTTP::Post.new(url)
request['content-type'] = "multipart/form-data; boundary=#{BOUNDARY}"


# Initialize a new helper array to aid us set up the post reuqest
post_body = []

# Add the application data, key and ID to the helper array
post_body << "--#{BOUNDARY}\r\n"
post_body << "Content-Disposition: form-data; name=\"application\"\r\n\r\n"
post_body << "{\"id\":\"#{app_id}\", \"key\":\"#{key}\"}"
post_body << "\r\n--#{BOUNDARY}\r\n"


# Add the file Data to the helper array
post_body << "--#{BOUNDARY}\r\n"
post_body << "Content-Disposition: form-data; name=\"input\"; filename=\"#{File.basename(file)}\"\r\n"
post_body << "Content-Type: application/pdf\r\n\r\n"

# Read the file data to the helper array
# Note that this reads the complete file in memory, and might not work well for large files
post_body << File.read(file)
post_body << "\r\n\r\n--#{BOUNDARY}--\r\n"

# Create the request body by joining all fields of the helper array together
request.body = post_body.join

# Submit the post request
response = http.request(request)
0
source

All Articles