Replies: 3 comments 15 replies
-
|
See the Ferrum docs. There's a Docker section in the readme. https://github.com/rubycdp/ferrum We're just a layer on top. 👍 |
Beta Was this translation helpful? Give feedback.
-
|
Hi everyone! I'm use Grover with a chrome on external machine to create PDF. For my context, user requests a PDF from page and it download the file generated in same request. Below, that's my files used in development environment pseudo- services:
web:
<<: *app-build
command: bash -c "./bin/dev"
volumes:
- .:/myapp:cached
- bundle:/usr/local/bundle
- node_modules:/myapp/node_modules
ports:
- "3000:3000"
depends_on:
- db
- redis
environment:
RAILS_ENV: development
SERVER_KIND: web
extra_hosts:
- "host.docker.internal:host-gateway"
pdf:
image: browserless/chrome:latest
ports:
- "3001:3000"
restart: always
environment:
MAX_CONCURRENT_SESSIONS: 5
CONCURRENT: 5
CONNECTION_TIMEOUT: 10000
TIMEOUT: 10000
LOG_LEVEL: info
ENABLE_HTTP: "true"
QUEUED: 10
PREBOOT_CHROME: "true"
CHROME_FLAGS: >
--no-sandbox
--disable-setuid-sandbox
--disable-dev-shm-usage
--disable-gpu
--no-first-run
--disable-sync
--disable-features=HttpsUpgrades
healthcheck:
test: [ "CMD", "curl", "--fail", "http://localhost:3000/metrics" ]
interval: 30s
timeout: 5s
retries: 3Always when I need generate pdf, I start My grove initializer: Grover.configure do |config|
app_url = ENV.fetch("APP_URL", "http://web:3000")
options = {
format: "A4",
print_background: true,
margin: { top: "2mm", bottom: "2mm", left: "0mm", right: "0mm" },
browser_ws_endpoint: ENV.fetch("BROWSER_WS_ENDPOINT", "ws://pdf:3000"),
display_url: app_url,
skip_chromium_download: true,
timeout: Rails.env.production? ? 30_000 : 10_000,
viewport: { width: 1280, height: 800 },
puppeteer: {
args: %w[
--no-sandbox
--disable-setuid-sandbox
--disable-dev-shm-usage
--disable-gpu
--no-first-run
--disable-sync
--disable-features=HttpsUpgrades
],
},
}
Rails.logger.info "INITIALIZING GROVER WITH OPTIONS: #{options}"
config.options = options
config.root_url = app_url
endand finally, the def render_to_pdf(options)
filename = options.delete(:filename)
html = render_to_string(**options)
# this is to assets requests work
if Rails.env.development?
app_url = ENV.fetch("APP_URL", "http://web:3000")
html = html.gsub("http://localhost:3000", app_url)
end
# skip robots indexing for PDF files
response.set_header("X-Robots-Tag", "noindex, noarchive, nosnippet")
send_data Grover.new(html).to_pdf,
filename: filename,
type: "application/pdf",
disposition: "inline"
end |
Beta Was this translation helpful? Give feedback.
-
|
Hello,
docker-compose.yml You can checkout the chrome instance in your favorite browser with http://localhost:9222/json/version Then you can setup a custom browser for your FerrumPdf config: note that for your custom browser to be able to instanciate, you'll need to retrieve some data from your chrome container: don't hesitate to comment on it if you know better ways of if it helped you :) |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
Just wondering if Ferrum supports connecting to a remote chromium instance?
I'm using Kamal for deployment and currently generate PDF's with grover configured to connect to a Kamal accessory that just runs a chromium server. It works quite well but grover still depends on node for this even though it doesn't install chrome locally:
https://github.com/Studiosity/grover?tab=readme-ov-file#remote-chromium
I'd like to get rid of node as a runtime dependency as it makes my builds really large.
Beta Was this translation helpful? Give feedback.
All reactions