简体   繁体   English

Datalogics PDF填写Rails

[英]Datalogics PDF Fill in Rails

I'm trying to use the Datalogics PDF ( https://api.datalogics-cloud.com/docs#fillform ) to fill in a fillable pdf (made with adobe acrobat) in my rails app. 我正在尝试使用Datalogics PDF( https://api.datalogics-cloud.com/docs#fillform )在我的rails应用程序中填写一份可填写的pdf(用adobe acrobat制作)。

I'm having difficulty figuring out how to make the api call. 我很难搞清楚如何拨打api电话。 Ie I can't figure out where/how to put the parameters. 即我无法弄清楚在哪里/如何放置参数。 Any help is much appreciated! 任何帮助深表感谢! Thanks! 谢谢!

One of the examples is using curl, so in a 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.pdf Which flattens the pdf hello_world (located in my rails root) into a pdf named flattened.pdf. 其中一个例子是使用curl,所以在控制器动作中我放了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.pdf将pdf hello_world(位于我的rails根目录中)展平为一个名为flattened的pdf .PDF。

I'm not sure how to understand this code though. 我不知道如何理解这段代码。

Also, I've thought about instead of using the controller, use a form whose action is the url and has tags of the various fields, is that a valid possibility? 另外,我考虑过不使用控制器,使用一个动作为url且有各种字段标签的表单,这是否有效?

For the fill form, I'm attempting this curl command: 对于填充表单,我正在尝试这个curl命令:

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

You can use an HTTP request to do this. 您可以使用HTTP请求执行此操作。 I put together some code that you can see below. 我把一些代码放在一起,你可以在下面看到。 Your request will need need to be a multi part one, and that's why you will have to define a boundary. 您的请求需要是多部分的,这就是您必须定义边界的原因。 The request I have below is for the DocumentProperties service. 我在下面的请求是针对DocumentProperties服务的。 You will need to modify it slightly to add the values for filling the form. 您需要稍微修改它以添加填充表单的值。 Note that you will need to use "File.read()" to read the file with the values when passing it in. 请注意,在传递文件时,您需要使用“File.read()”来读取包含值的文件。

You can see the relevant 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)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM