{"id":16856527,"url":"https://github.com/hassox/hpdf","last_synced_at":"2025-04-11T07:40:03.254Z","repository":{"id":57505463,"uuid":"112141664","full_name":"hassox/hpdf","owner":"hassox","description":"PDF printing using headless chrome","archived":false,"fork":false,"pushed_at":"2019-12-01T06:35:12.000Z","size":15,"stargazers_count":12,"open_issues_count":2,"forks_count":3,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-03-25T05:12:18.986Z","etag":null,"topics":["chrome","elixir","pdf"],"latest_commit_sha":null,"homepage":null,"language":"Elixir","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/hassox.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2017-11-27T03:17:05.000Z","updated_at":"2023-09-10T08:49:29.000Z","dependencies_parsed_at":"2022-08-22T08:50:48.508Z","dependency_job_id":null,"html_url":"https://github.com/hassox/hpdf","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hassox%2Fhpdf","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hassox%2Fhpdf/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hassox%2Fhpdf/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hassox%2Fhpdf/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/hassox","download_url":"https://codeload.github.com/hassox/hpdf/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247980830,"owners_count":21027803,"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":["chrome","elixir","pdf"],"created_at":"2024-10-13T14:04:33.106Z","updated_at":"2025-04-11T07:40:02.997Z","avatar_url":"https://github.com/hassox.png","language":"Elixir","funding_links":[],"categories":[],"sub_categories":[],"readme":"# HPDF\n\nHeadless PDF printing (with Chrome)\n\nUse Chrome in Headless mode to print pages to PDF.\nEach page is loaded in it's own browser context, similar to an Incognito window.\n\nPages may be printed that require authentication allowing you to print pages that are behind login wall.\n\nWhen using HPDF you need to have a headless chrome running.\nYou can get a headless chrome browser by using a docker container.\nA public container can be found at: https://hub.docker.com/r/justinribeiro/chrome-headless/\n\nBy default HPDF will look for chrome at `http://localhost:9222`.\nThis can be configured in your configuration files by using:\n\n```elixir\nconfig :hpdf, HPDF,\n  address: \"http://my_custom_domain:9222\"\n```\n\n```sh\ndocker run -d -p 9222:9222 --cap-add=SYS_ADMIN justinribeiro/chrome-headless\n```\n\n### Example\n\n```elixir\ncase HPDF.print_pdf!(my_url, timeout: 30_000) do\n  {:ok, pdf_data} -\u003e do_stuff_with_the_pdf_binary_data(pdf_data)\n  {:error, error_type, reason} -\u003e #Handle error\n  {:error, reason} -\u003e # Handle error\n```\n\nCommon error types provided by HPDF\n* `:page_error` - An error was returned by the browser\n* `:page_redirected` - The URL was redirected\n* `:page_load_failure` - The page loaded with a non 200 status code\n* `:crashed` - The browser crashed\n\n### Using header authentication\n\nWhen printing a page using header authentication,\nusually it's not only the original page, but all AJAX requests made within it that need to have the authentication header included.\n\nAssuming you have a token\n\n```elixir\nheader_value = get_my_auth_header()\nheaders = %{\"authorization\" =\u003e header_value}\n\ncase HPDF.print_pdf!(my_url, timeout: 30_000, page_headers: headers) do\n  {:ok, pdf_data} -\u003e do_stuff_with_the_pdf_binary_data(pdf_data)\n  {:error, error_type, reason} -\u003e #Handle error\n  {:error, reason} -\u003e # Handle error\nend\n```\n\n### Using cookie authentication\nAn initiating cookie can be used to access pages.\n\n```elixir\ncookie = %{\n  name: \"_cookie_name\",\n  value: cookie_value,\n  domain: \"your.domain\",\n  path: \"/\",\n  secure: true,\n  httpOnly: true,\n}\n\n{:ok, data} = HPDF.print_pdf!(url, timeout: 30_000, cookie: cookie)\n```\n\n### Calling `print_pdf!`\n\nPrints a PDF file with the provided options.\nThe HPDF.Application must be running before calling this function\n\n### Options\n\n* `timeout` - The timeout for the call. Default 5_000\n* `after_load_delay` - The time to wait after the page finishes loading. Allowing for dynamic JS calls and rendering.\n* `cookie` - Supply a cookie for the page to be loaded with. See https://chromedevtools.github.io/devtools-protocol/tot/Network/#method-setCookie\n* `page_headers` - A map of headers to supply to the page\n* `include_headers_on_same_domain` - A bool. Default True. If true, all requests to the same domain will include the same headers as the main page\n* `print_options` - A map of options to the print method. See https://chromedevtools.github.io/devtools-protocol/tot/Page/#method-printToPDF\n* `max_wait_time` - A time in miliseconds after which the page will be forcefully printed even if there are outstanding requests\n\n## Installation\n\nIf [available in Hex](https://hex.pm/docs/publish), the package can be installed\nby adding `hpdf` to your list of dependencies in `mix.exs`:\n\n```elixir\ndef deps do\n  [{:hpdf, \"~\u003e 0.3.1\"}]\nend\n\ndef application do\n  # Specify extra applications you'll use from Erlang/Elixir\n  [extra_applications: [:hpdf],\nend\n```\n\nDocumentation can be generated with [ExDoc](https://github.com/elixir-lang/ex_doc)\nand published on [HexDocs](https://hexdocs.pm). Once published, the docs can\nbe found at [https://hexdocs.pm/hpdf](https://hexdocs.pm/hpdf).\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fhassox%2Fhpdf","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fhassox%2Fhpdf","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fhassox%2Fhpdf/lists"}