
How to take screenshots and generate PDFs in Elixir
How to Take Screenshots and Generate PDFs in Elixir Elixir has no native headless browser. Teams that need screenshots or PDFs typically shell out to a wkhtmltopdf binary, run a Node.js Puppeteer subprocess, or use chrome_remote_interface — a Chromium binding that requires a running Chrome instance. None of these are easy to supervise in an OTP application. Here's the simpler path: one HTTP call, binary response. Works in any Mix project or Phoenix endpoint. Using Req (recommended) Req is the modern Elixir HTTP client. Add it to mix.exs : defp deps do [ { :req , "~> 0.5" } ] end defmodule PageBolt do @base_url "https://pagebolt.dev/api/v1" defp api_key , do : System . fetch_env! ( "PAGEBOLT_API_KEY" ) def screenshot ( url ) do Req . post! ( " #{ @base_url } /screenshot" , headers: [{ "x-api-key" , api_key ()}], json: %{ url: url , fullPage: true , blockBanners: true } ) . body end def pdf_from_url ( url ) do Req . post! ( " #{ @base_url } /pdf" , headers: [{ "x-api-key" , api_key ()}],
Continue reading on Dev.to Webdev
Opens in a new tab




