Skip to content

Instantly share code, notes, and snippets.

@pietrop
Created June 29, 2014 18:04
Show Gist options
  • Star 22 You must be signed in to star a gist
  • Fork 6 You must be signed in to fork a gist
  • Save pietrop/880a58088c630c960166 to your computer and use it in GitHub Desktop.
Save pietrop/880a58088c630c960166 to your computer and use it in GitHub Desktop.
To download magazine from issuu.com when the download option has been disabled. in practice the script doesn't actually download the pdf, but rather download the images of the pages of the flash object and then combines those into a pdf
require 'mechanize'
require 'prawn'
=begin
running from terminal to download any pdf from issuu.com, given
- magazine name
- page count
- document-id
=end
prompt = "> "
puts "What is the name of the magazine you'd like to download from issuu.com? ps: this will be the name of your pdf file\n"
print prompt
magazine_name = gets.chomp
puts "How many pages does it have?\n ie 104\n"
print prompt
page_number = gets.chomp
puts "document Id? \n to get the 'document-id' inspect page in chrome,\n search for document-id and paste here,\n ie 140601160255-3a4c0f75ec731801ef369f5000f03104\n"
print prompt
document_id = gets.chomp
for i in 1..page_number.to_i
print "downloading\tpage n #{i}\n"
agent = Mechanize.new
link = "http://image.issuu.com/#{document_id.to_s}/jpg/page_#{i.to_s}.jpg"
agent.get(link).save "page_#{i.to_s}.jpg"
print "downloaded\tpage n #{i}\n"
end
print "images from 1 to #{page_number.to_s} downloaded as jpg\n"
########to combine all images into a pdf
Prawn::Document.generate("#{magazine_name}.pdf", :page_layout => :portrait) do |pdf|
for i in 1..page_number.to_i
pdf.image "page_#{i.to_s}.jpg", :at => [0,750], :width => 530
pdf.start_new_page
end#end of loop
end
print "images from 1 to #{page_number.to_s} combined into pdf \n"
########to delete all images, once pdf as been created, to clean up a bit
for i in 1..page_number.to_i
File.delete("page_#{i.to_s}.jpg")
end#end of prawn
print "images from 1 to #{page_number.to_s} deleted \n"
# print "your pdf #{magazine_name}.pdf is in: \n #{Dir.pwd}"
@ahmed0176
Copy link

i'm new to this . can anyone explain where to paste this code ?

@pietrop
Copy link
Author

pietrop commented Jul 23, 2015

Sorry just saw this now, save it as a .rb file, and run it from terminal on your computer.
(you may need to install the mechanize and prawn gem if you don't have them already...)
more on this project here, http://pietropassarelli.com/issuu.html

hope this helps

@71m383nd3r
Copy link

is it possible to make a drop gui with a link, as well to make just a jpg to pdf converter, why am I asking because I have downloaded some jpg before.

@rastiazul
Copy link

there are no results when I search for documentId

@vladox
Copy link

vladox commented Oct 10, 2020

@wyatt-wong
Copy link

use https://issuu.pdf-downloader.com/

The quality of the PDF document is not good enough using https://issuu.pdf-downloader.com/

@HandyHat
Copy link

The document-id doesn't seem to show up on the inspect page anymore

@pietrop
Copy link
Author

pietrop commented Aug 25, 2023

The document-id doesn't seem to show up on the inspect page anymore

The script was written 9 years ago, I suspect that the structure of the issue page might have changed since then.

@HandyHat
Copy link

Haha that's a very good point

@pietrop
Copy link
Author

pietrop commented Aug 25, 2023

Haha that's a very good point

Lol yeah. If it’s helpful this is a blogpost I wrote a while back that walks through how I got to that initial script https://pietrop.github.io/issuu.html

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment