gpt4 book ai didi

ruby-on-rails - Datalogics PDF 填写 Rails

转载 作者:行者123 更新时间:2023-12-03 15:48:33 27 4
gpt4 key购买 nike

我正在尝试使用 Datalogics PDF ( https://api.datalogics-cloud.com/docs#fillform ) 在我的 rails 应用程序中填写可填写的 pdf(使用 adobe acrobat 制作)。

我很难弄清楚如何进行 api 调用。 IE。我不知道在哪里/如何放置参数。任何帮助深表感谢!谢谢!

示例之一是使用 curl,因此在 Controller 操作中我放置了 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。

我不确定如何理解这段代码。

另外,我考虑过不使用 Controller ,而是使用一个表单,其操作是 url 并具有各个字段的标签,这是一种有效的可能性吗?

对于填写表格,我正在尝试这个 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`

最佳答案

您可以使用 HTTP 请求来执行此操作。我整理了一些您可以在下面看到的代码。您的请求需要是多部分的,这就是您必须定义边界的原因。我下面的请求是针对 DocumentProperties 服务的。您需要稍微修改它以添加用于填写表单的值。请注意,在传入文件时,您需要使用“File.read()”来读取带有值的文件。

你可以看到下面的相关代码。

# 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)

关于ruby-on-rails - Datalogics PDF 填写 Rails,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31016628/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com