scribd.com - many people know that Scribd allows you to download up to 50,000 files for free and converts them to pdf + provides a good widget for displaying files.
But how to make it so that the document was visible only to parts of users, and the other part could see only a small piece of the document? Of course, everything is extremely simple, as is almost always the case with Ruby and Rails.
The whole process will take 2 iterations, which should be stuffed into the Background job - any one of your choice. Imagine that a file of any format is already on your server — for example, you used Carrierwave to download a file or something your soul likes. Here it is worth clarifying that the file may not be exactly any format, but only - (doc, docx, ppt, pptx, pps, ppsx, xls, xlsx, pdf, ps, odt, odp, sxw, sxi, txt, rtf, epub). Next, we need to add to the bundler:
gem 'rscribd' gem 'prawn'
')
and don't forget bundle install.
After that, you need to register in Scribd and get the key and secret, which are placed in initializers / scribd.rb (for example) in the form:
Scribd::API.instance.key = 'xxxxxxxxxxxxxx' Scribd::API.instance.secret = 'xxxxxxxxxxxxxx'
Everything is ready, now let's move on to the main iterations.
1 iteration - loading on scribd of a document that you received in its pure form:
The output of the function is written to the scribd variable, which contains doc_id and access_key
We save these variables and with the help of them we can then show a clean document to users.
scribd.doc_id
scribd.access_key
Great, we have a clean document uploaded to the Scrybd. Now the second iteration - creating a document with stubs - for partial display.
Here, the Prawn and the second delay job come into force in all its glory. Her call is worth adding to the end of the first.
So we have scribd_id of your file. - find it in the scribde -
scribd = Scribd::Document.find scribd_id
Next, download the pdf version of your document to your server via the link that scribd kindly provides us with:
scribd.download_url 'pdf'
After that use prawn to add a stub file:
Prawn::Document.generate(path_to_template_file, :template => path_to_real_file) do |doc| (1..doc.page_count).each do |page_number| doc.image(path_to_gap, :vposition => :center, :position => :center, :width => x, :height => y) end end
path_to_template_file - the path to the file that will be saved with the stubs (it does not exist yet, but prawn will create it for us)
path_to_real_file is the path to a real clean file that we downloaded from scribd in pdf format.
path_to_gap - the path to the picture stub
Well, do not forget to put the width and height of this stub (x, y)
Great, now we have a stub file that we upload to the scribed and pick up the id and secret_key, as is the case with the clean file.
Now we have 2 sets of key / secret for displaying the file in its pure form and with stubs, and we can decide which option to show to whom.
Clearly these things are as follows:

This option of working with scribd I personally see, probably, the most promising, because the user will see the entire file, even if with stubs that do not show him all the content, and will block the main part (the size of the part depends on your choice of the stub).