Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
186 views
in Technique[技术] by (71.8m points)

ruby on rails - Store combined pdf combined by combine_pdf gem

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?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...