### Install Puppeteer Source: https://github.com/studiosity/grover/blob/main/README.md Install the Google Puppeteer Node.js package, a dependency for Grover. ```bash npm install puppeteer ``` -------------------------------- ### Basic PDF Conversion with Grover Source: https://context7.com/studiosity/grover/llms.txt Demonstrates how to convert a URL or inline HTML string into a PDF document using the Grover gem. Includes examples of saving the PDF to a file or directly to a specified path, with options for formatting like 'A4' or 'Letter'. ```ruby require 'grover' # Convert a URL to PDF grover = Grover.new('https://google.com', format: 'A4') pdf_data = grover.to_pdf # Save to file File.open('output.pdf', 'wb') { |f| f << pdf_data } # Or write directly to path grover.to_pdf('/path/to/output.pdf') # Convert inline HTML to PDF html = '
Generated with Grover
' grover = Grover.new(html, format: 'Letter') pdf_data = grover.to_pdf ``` -------------------------------- ### Install Grover Gem and Puppeteer Source: https://context7.com/studiosity/grover/llms.txt Instructions for installing the Grover Ruby gem and its dependency, Puppeteer, via npm. This is a prerequisite for using Grover's conversion functionalities. ```ruby # Gemfile gem 'grover' ``` ```bash npm install puppeteer ``` -------------------------------- ### Grover Middleware Setup Source: https://github.com/studiosity/grover/blob/main/README.md Integrate Grover's middleware into your Rack or Rails application to generate PDF, PNG, or JPEG views of pages by appending file extensions to URLs. ```APIDOC ## Middleware Grover comes with a middleware that allows users to get a PDF, PNG or JPEG view of any page on your site by appending .pdf, .png or .jpeg/.jpg to the URL. ### Middleware Setup **Non-Rails Rack apps** ```ruby # in config.ru require 'grover' use Grover::Middleware ``` **Rails apps** ```ruby # in application.rb require 'grover' config.middleware.use Grover::Middleware ``` N.B. by default PNG and JPEG are not modified in the middleware to prevent breaking standard behaviours. To enable them, there are configuration options for each image type as well as an option to disable the PDF middleware (on by default). If either of the image handling middleware options are enabled, the [ignore_path](#ignore_path) and/or [ignore_request](#ignore_request) should also be configured, otherwise assets are likely to be handled which would likely result in 404 responses. ### Enabling Image Middleware ```ruby # config/initializers/grover.rb Grover.configure do |config| config.use_png_middleware = true config.use_jpeg_middleware = true config.use_pdf_middleware = false end ``` ``` -------------------------------- ### Grover Middleware Setup for Rack and Rails Apps Source: https://github.com/studiosity/grover/blob/main/README.md Integrate Grover's middleware into your application to enable generating PDF, PNG, or JPEG versions of web pages by appending file extensions to URLs. This setup can be done for non-Rails Rack applications or Rails applications. ```ruby # in config.ru require 'grover' use Grover::Middleware ``` ```ruby # in application.rb require 'grover' config.middleware.use Grover::Middleware ``` -------------------------------- ### Install Grover Gem Source: https://github.com/studiosity/grover/blob/main/README.md Add the Grover gem to your application's Gemfile for installation. ```ruby gem 'grover' ``` -------------------------------- ### Connect to Remote Chromium Instance Source: https://github.com/studiosity/grover/blob/main/README.md Explains how to connect Grover to an external Chromium instance using a WebSocket endpoint and how to install the necessary lightweight dependency. ```ruby grover = Grover.new("https://mysite.com/path/to/thing", browser_ws_endpoint: "ws://localhost:3000/chrome") File.open("grover.png", "wb") { |f| f << grover.to_png } ``` ```shell npm install puppeteer-core ``` -------------------------------- ### Manage Request Cookies Source: https://github.com/studiosity/grover/blob/main/README.md Provides examples for setting static cookies and extracting cookies from an existing request to forward them to Grover. ```ruby myCookies = [ { name: 'sign_username', value: 'any@any.com', domain: 'mydomain' }, { name: '_session_id', value: '9c014df0b699d8dc08d1c472f8cc594c', domain: 'mydomain' } ] Grover.new('