Skip to content

Commit

Permalink
v0.5.5:
Browse files Browse the repository at this point in the history
- improved documentation on `prefer_system_executable: true` for chrome
- improved documentation on `no_sandbox: true` for chrome in dockerized environment (running as root)
- log call options as debug info to Logger
  • Loading branch information
gutschilla committed Jun 18, 2019
1 parent c714705 commit 2c23bb8
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 18 deletions.
5 changes: 5 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
# Changes

- 0.5.5
- improved documentation on `prefer_system_executable: true` for chrome
- improved documentation on `no_sandbox: true` for chrome in dockerized
environment (running as root)
- log call options as debug info to Logger
- 0.5.4
- **BUGFIX** introduced in 0.5.0 that would crash `PdfGenerator.PathAgent`
when chrome isn't found on path in certain situation. Thanks to
Expand Down
32 changes: 22 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,13 @@ encryption) for use in Elixir projects.
{:ok, pdf} = PdfGenerator.generate_binary("<html><body><h1>Yay!</h1></body></html>")
```

# Latest release v0.5.4 on 2019-05-14
# Latest release v0.5.5 on 2019-06-18

- 0.5.4
- **BUGFIX** introduced in 0.5.0 that would crash `PdfGenerator.PathAgent`
when chrome isn't found on path in certain situation. Thanks to
[@radditude](https://github.com/radditude) for submitting a patch.
- 0.5.5
- improved documentation on `prefer_system_executable: true` for chrome
- improved documentation on `no_sandbox: true` for chrome in dockerized
environment (running as root)
- log call options as debug info to Logger

For a proper changelog, see [CHANGES](CHANGES.md)

Expand Down Expand Up @@ -93,7 +94,7 @@ Add this to your dependencies in your mix.exs:
defp deps do
[
# ... whatever else
{ :pdf_generator, ">=0.5.3" }, # <-- and this
{ :pdf_generator, ">=0.5.5" }, # <-- and this
]
end
```
Expand All @@ -114,15 +115,26 @@ filename = PdfGenerator.generate!(html, generator: :chrome)

Or, pass some URL

```
```Elixir
PdfGenerator.generate {:url, "http://google.com"}, page_size: "A5"
```

Or, use chrome-headless
Or, use **chrome-headless** – if you're (most probably) using this as
dependency, chrome won't be installed to this project directory but globally. We
currently need to tell PdfGenerator this by setting the
`prefer_system_executable: true` option. This will be default by v0.6.0.

```
```Elixir
html_works_too = "<html><body><h1>Minimalism!"
{:ok, filename} = PdfGenerator.generate html_works_too, generator: :chrome
{:ok, filename} = PdfGenerator.generate html_works_too, generator: :chrome, prefer_system_executable: true
```

If using chrome in a superuser/root environment (read: **docker**), make sure to
pass an option to chrome to disable sandboxing. And be aware of the implications.

```Elixir
html_works_too = "<html><body><h1>I need Docker, baby docker is what I need!"
{:ok, filename} = PdfGenerator.generate html_works_too, generator: :chrome, no_sandbox: true
```

Or use the bang-methods:
Expand Down
20 changes: 13 additions & 7 deletions lib/pdf_generator.ex
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
defmodule PdfGenerator do

@vsn "0.5.0"
require Logger

@vsn "0.5.5"

@moduledoc """
# PdfGenerator
Expand Down Expand Up @@ -205,7 +207,8 @@ defmodule PdfGenerator do
more_params,
if(disable_sandbox, do: ["--chrome-option", "--no-sandbox"], else: [])
])
{executable, arguments} # |> IO.inspect()
{executable, arguments} |> inspect() |> Logger.debug()
{executable, arguments}
end

def make_command(:wkhtmltopdf, options, content, {html_path, pdf_path}) do
Expand All @@ -222,11 +225,14 @@ defmodule PdfGenerator do
source, pdf_path
])
# for wkhtmltopdf we support prefixes like ["xvfb-run", "-a"] to precede the actual command
case get_command_prefix(options) do
nil -> {executable, arguments}
[prefix | prefix_args] -> {prefix, prefix_args ++ [executable] ++ arguments}
prefix -> {prefix, [executable | arguments]}
end
{executable, arguments} =
case get_command_prefix(options) do
nil -> {executable, arguments}
[prefix | prefix_args] -> {prefix, prefix_args ++ [executable] ++ arguments}
prefix -> {prefix, [executable | arguments]}
end
{executable, arguments} |> inspect() |> Logger.debug()
{executable, arguments}
end

defp maybe_delete_temp(true, file), do: File.rm(file)
Expand Down
2 changes: 1 addition & 1 deletion mix.exs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ defmodule PdfGenerator.Mixfile do
[
app: :pdf_generator,
name: "PDF Generator",
version: "0.5.4",
version: "0.5.5",
elixir: ">= 1.1.0",
deps: deps(),
description: description(),
Expand Down

0 comments on commit 2c23bb8

Please sign in to comment.