Store combined pdf combined by combine_pdf gem

被刻印的时光 ゝ 提交于 2019-12-25 18:49:10

问题


I have combined two pdf files as follows

pdf = CombinePDF.new
pdf << CombinePDF.parse(Net::HTTP.get_response(URI.parse(@task.assignable.pdf_file.try(:file).try(:url))).body, allow_optional_content: true)
pdf << CombinePDF.load(file1_path) # one way to combine, very fast.
pdf.save "combined.pdf"

I can check and see my combined file by downloading as follows:

send_data pdf.to_pdf, filename: "combined.pdf", type: "application/pdf"

This all working fine but I want to store this pdf in @signed_pdf record.

It is allowing to to store the pdf in my record as follow:

@signed_pdf.signed_file = pdf.to_pdf

but it seems not to good approach. I want to store it as object.

@signed_pdf.signed_file = pdf

but in this case using @signed_pdf.signed_file.to_pdf for downloading purpose or any other purpose showing the error:

undefined method `to_pdf' for "#<CombinePDF::PDF:0x000000000dabd5d0>":String Did you mean? to_f to_d

What would be the beeter way to store combined pdf in my record?


回答1:


I think you need to store the pdf on files system or a block storage provider (Amazon S3) and save the path to the db instead.




回答2:


Did you try to parse string first?

CombinePDF.parse(@signed_pdf.signed_file).to_pdf


来源:https://stackoverflow.com/questions/49994433/store-combined-pdf-combined-by-combine-pdf-gem

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!