Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/tyre/gutenex
Native PDF generation for Elixir
https://github.com/tyre/gutenex
Last synced: 3 months ago
JSON representation
Native PDF generation for Elixir
- Host: GitHub
- URL: https://github.com/tyre/gutenex
- Owner: tyre
- License: mit
- Created: 2014-09-28T21:51:42.000Z (over 10 years ago)
- Default Branch: master
- Last Pushed: 2018-11-09T19:11:02.000Z (about 6 years ago)
- Last Synced: 2024-04-14T04:10:12.987Z (10 months ago)
- Language: Elixir
- Homepage:
- Size: 902 KB
- Stars: 241
- Watchers: 7
- Forks: 35
- Open Issues: 11
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
- freaking_awesome_elixir - Elixir - Native PDF generation for Elixir. (PDF)
- fucking-awesome-elixir - gutenex - Native PDF generation for Elixir. (PDF)
- awesome-elixir - gutenex - Native PDF generation for Elixir. (PDF)
README
# Gutenex
[![Build Status](https://travis-ci.org/SenecaSystems/gutenex.svg?branch=master)](https://travis-ci.org/SenecaSystems/gutenex)
PDF generation!
> So weird that it's still a thing for murderers in horror movies to keep clippings of their crimes. PDF that shit!
> — [Julieanne Smolinkski](https://twitter.com/BoobsRadley)What started out as a wrapper for the Erlang [erlguten](https://github.com/ztmr/erlguten) library has turned into a full rewrite in Elixir.
## Plan
Rewriting the basic PDF functionality means:
* [x] text
* [x] fonts
* [x] images
* [x] rendering/exporting
* [ ] parsing existing PDFs
* [ ] templating
* [ ] documentation# Usage
```elixir
# Load image, get alias
{alpaca_alias, alpaca_rendition} = Gutenex.PDF.Images.load("./test/support/images/alpaca.png"){:ok, pid} = Gutenex.start_link
Gutenex.add_image(pid, alpaca_alias, alpaca_rendition) |>
Gutenex.begin_text |>
Gutenex.set_font("Helvetica", 48) |>
Gutenex.text_position(40, 180) |>
Gutenex.text_render_mode(:fill) |>
Gutenex.write_text("ABC") |>
Gutenex.set_font("Courier", 32) |>
Gutenex.text_render_mode(:stroke) |>
Gutenex.write_text("xyz") |>
Gutenex.end_text |>
Gutenex.move_to(400, 20) |>
Gutenex.draw_image(alpaca_alias, %{
translate_x: 300,
translate_y: 500,
}) |>
Gutenex.export("./tmp/alpaca.pdf") |>
Gutenex.stop
```Now open up that file and you should see some text near the bottom and a picture
of what I believe to be an alpaca. Could also be a llama.By default, coordinates are in units of 1/72 inch as per the PDF
spec. Origin is in lower left corner of the page. This is roughly 1
point in printing terms.```
Gutenex.line_width(pid, 0.01) # very fine line
|> Gutenex.line({{0, 0}, {500, 500}}) # up and to the right
```