Ruby on rails Datalogics PDF填充Rails

Ruby on rails Datalogics PDF填充Rails,ruby-on-rails,pdf,Ruby On Rails,Pdf,我正在尝试使用datalogicspdf()在我的rails应用程序中填充一个可填充的PDF(由adobeacrobat制作) 我很难弄清楚如何进行api调用。也就是说,我不知道在哪里/如何放置参数。非常感谢您的帮助!谢谢 其中一个例子是使用curl,因此在控制器操作中,我将curlhttps://pdfprocess.datalogics.com/api/actions/render/pages --不安全--form'application={“id”:“xxxxx”,“key”:“xxxx

我正在尝试使用datalogicspdf()在我的rails应用程序中填充一个可填充的PDF(由adobeacrobat制作)

我很难弄清楚如何进行api调用。也就是说,我不知道在哪里/如何放置参数。非常感谢您的帮助!谢谢

其中一个例子是使用curl,因此在控制器操作中,我将
curlhttps://pdfprocess.datalogics.com/api/actions/render/pages --不安全--form'application={“id”:“xxxxx”,“key”:“xxxxxxx”}--form input=@hello\u world.pdf--form inputName=hello\u world.pdf--output flatted.pdf
将pdf hello\u world展平(位于我的rails根目录中)转换为名为flatten.pdf的pdf

但我不知道如何理解这段代码

另外,我考虑过不用控制器,而是使用一个表单,它的动作是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)
#使用我们的URL初始化新的HTTPS请求对象
http=Net::http.new(url.host,url.port)
http.use_ssl=true
http.verify\u mode=OpenSSL::SSL::verify\u NONE
##
#多部分实体的内容类型字段需要一个参数“边界”,
#用于指定封装边界。封装边界
#定义为完全由两个连字符(“-”,十进制代码45)组成的行
#后跟内容类型标题字段中的边界参数值。
边界='BoundaryString'
#初始化新的Post请求
request=Net::HTTP::Post.new(url)
请求['content-type']=“多部分/表单数据;边界=#{boundary}”
#初始化一个新的助手数组以帮助我们设置post reuqest
post_body=[]
#将应用程序数据、键和ID添加到助手数组中

post_body你能告诉我们到目前为止你得到了什么,你得到了什么错误吗?你还尝试了什么等等?(注意:不要把它放在评论中,编辑你的问题并添加到那里,因为这些东西应该是你问题的一部分)