{"id":13463189,"url":"https://github.com/adjust/shrimp","last_synced_at":"2025-03-25T06:31:37.564Z","repository":{"id":5986387,"uuid":"7208700","full_name":"adjust/shrimp","owner":"adjust","description":"a phantomjs based pdf renderer","archived":true,"fork":false,"pushed_at":"2017-05-05T16:49:05.000Z","size":356,"stargazers_count":284,"open_issues_count":19,"forks_count":72,"subscribers_count":74,"default_branch":"master","last_synced_at":"2024-10-29T13:50:32.434Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Ruby","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/adjust.png","metadata":{"files":{"readme":"README.md","changelog":"ChangeLog.md","contributing":null,"funding":null,"license":"LICENSE.txt","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2012-12-17T17:12:01.000Z","updated_at":"2024-09-23T11:23:55.000Z","dependencies_parsed_at":"2022-08-21T01:20:16.065Z","dependency_job_id":null,"html_url":"https://github.com/adjust/shrimp","commit_stats":null,"previous_names":["adeven/shrimp"],"tags_count":4,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/adjust%2Fshrimp","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/adjust%2Fshrimp/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/adjust%2Fshrimp/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/adjust%2Fshrimp/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/adjust","download_url":"https://codeload.github.com/adjust/shrimp/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":245413937,"owners_count":20611354,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-07-31T13:00:47.643Z","updated_at":"2025-03-25T06:31:37.164Z","avatar_url":"https://github.com/adjust.png","language":"Ruby","readme":"# Shrimp\n[![Build Status](https://travis-ci.org/adjust/shrimp.png?branch=master)](https://travis-ci.org/adjust/shrimp)\nCreates PDFs from URLs using phantomjs\n\nRead our [blogpost](http://big-elephants.com/2012-12/pdf-rendering-with-phantomjs/) about how it works.\n\n## Installation\n\nAdd this line to your application's Gemfile:\n\n    gem 'shrimp'\n\nAnd then execute:\n\n    $ bundle\n\nOr install it yourself as:\n\n    $ gem install shrimp\n\n\n### Phantomjs\n\n    See http://phantomjs.org/download.html on how to install phantomjs\n\n## Usage\n\n```\nrequire 'shrimp'\nurl     = 'http://www.google.com'\noptions = { :margin =\u003e \"1cm\"}\nShrimp::Phantom.new(url, options).to_pdf(\"~/output.pdf\")\n```\n## Configuration\n\n```\nShrimp.configure do |config|\n\n  # The path to the phantomjs executable\n  # defaults to `where phantomjs`\n  # config.phantomjs = '/usr/local/bin/phantomjs'\n\n  # the default pdf output format\n  # e.g. \"5in*7.5in\", \"10cm*20cm\", \"A4\", \"Letter\"\n  # config.format           = 'A4'\n\n  # the default margin\n  # config.margin           = '1cm'\n\n  # the zoom factor\n  # config.zoom             = 1\n\n  # the page orientation 'portrait' or 'landscape'\n  # config.orientation      = 'portrait'\n\n  # a temporary dir used to store tempfiles\n  # config.tmpdir           = Dir.tmpdir\n\n  # the default rendering time in ms\n  # increase if you need to render very complex pages\n  # config.rendering_time   = 1000\n\n  # change the viewport size.  If you rendering pages that have\n  # flexible page width and height then you may need to set this\n  # to enforce a specific size\n  # config.viewport_width     = 600\n  # config.viewport_height    = 600\n\n  # the timeout for the phantomjs rendering process in ms\n  # this needs always to be higher than rendering_time\n  # config.rendering_timeout  = 90000\n\n  # maximum number of redirects to follow\n  # by default Shrimp does not follow any redirects which means that\n  # if the server responds with non HTTP 200 an error will be returned\n  # config.max_redirect_count = 0\n\n  # the path to a json configuration file for command-line options\n  # config.command_config_file = \"#{Rails.root.join('config', 'shrimp', 'config.json')}\"\nend\n```\n\n### Command Configuration\n\n```\n{\n    \"diskCache\": false,\n    \"ignoreSslErrors\": false,\n    \"loadImages\": true,\n    \"outputEncoding\": \"utf8\",\n    \"webSecurity\": true\n}\n```\n\n## Middleware\n\nShrimp comes with a middleware that allows users to get a PDF view of any page on your site by appending .pdf to the URL.\n\n### Middleware Setup\n\n**Non-Rails Rack apps**\n\n    # in config.ru\n    require 'shrimp'\n    use Shrimp::Middleware\n\n**Rails apps**\n\n    # in application.rb(Rails3) or environment.rb(Rails2)\n    require 'shrimp'\n    config.middleware.use Shrimp::Middleware\n\n**With Shrimp options**\n\n    # options will be passed to Shrimp::Phantom.new\n    config.middleware.use Shrimp::Middleware, :margin =\u003e '0.5cm', :format =\u003e 'Letter'\n\n**With conditions to limit routes that can be generated in pdf**\n\n    # conditions can be regexps (either one or an array)\n    config.middleware.use Shrimp::Middleware, {}, :only =\u003e %r[^/public]\n    config.middleware.use Shrimp::Middleware, {}, :only =\u003e [%r[^/invoice], %r[^/public]]\n\n    # conditions can be strings (either one or an array)\n    config.middleware.use Shrimp::Middleware, {}, :only =\u003e '/public'\n    config.middleware.use Shrimp::Middleware, {}, :only =\u003e ['/invoice', '/public']\n\n    # conditions can be regexps (either one or an array)\n    config.middleware.use Shrimp::Middleware, {}, :except =\u003e [%r[^/prawn], %r[^/secret]]\n\n    # conditions can be strings (either one or an array)\n    config.middleware.use Shrimp::Middleware, {}, :except =\u003e ['/secret']\n\n\n### Polling\n\nTo avoid deadlocks Shrimp::Middleware renders the pdf in a separate process retuning a 503 Retry-After response Header.\nyou can setup the polling interval and the polling offset in seconds.\n\n    config.middleware.use Shrimp::Middleware, :polling_interval =\u003e 1, :polling_offset =\u003e 5\n\n### Caching\n\nTo avoid rendering the page on each request you can setup some the cache ttl in seconds\n\n    config.middleware.use Shrimp::Middleware, :cache_ttl =\u003e 3600, :out_path =\u003e \"my/pdf/store\"\n\n\n### Ajax requests\n\nTo include some fancy Ajax stuff with jquery\n\n```js\n\n var url = '/my_page.pdf'\n var statusCodes = {\n      200: function() {\n        return window.location.assign(url);\n      },\n      504: function() {\n       console.log(\"Shit's being wired\")\n      },\n      503: function(jqXHR, textStatus, errorThrown) {\n        var wait;\n        wait = parseInt(jqXHR.getResponseHeader('Retry-After'));\n        return setTimeout(function() {\n          return $.ajax({\n            url: url,\n            statusCode: statusCodes\n          });\n        }, wait * 1000);\n      }\n  }\n  $.ajax({\n    url: url,\n    statusCode: statusCodes\n  })\n\n```\n\n## Contributing\n\n1. Fork it\n2. Create your feature branch (`git checkout -b my-new-feature`)\n3. Commit your changes (`git commit -am 'Add some feature'`)\n4. Push to the branch (`git push origin my-new-feature`)\n5. Create new Pull Request\n\n## Copyright\nShrimp is Copyright © 2012 adeven (Manuel Kniep). It is free software, and may be redistributed under the terms\nspecified in the LICENSE file.\n","funding_links":[],"categories":["Documents \u0026 Reports","Ruby","PDF"],"sub_categories":["PDF Generation"],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fadjust%2Fshrimp","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fadjust%2Fshrimp","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fadjust%2Fshrimp/lists"}