Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/blocknotes/wkhtmltopdf-crystal
Crystal C bindings and wrapper for libwkhtmltox library
https://github.com/blocknotes/wkhtmltopdf-crystal
crystal wkhtmltopdf wkhtmltox
Last synced: 3 months ago
JSON representation
Crystal C bindings and wrapper for libwkhtmltox library
- Host: GitHub
- URL: https://github.com/blocknotes/wkhtmltopdf-crystal
- Owner: blocknotes
- License: mit
- Archived: true
- Created: 2016-12-29T17:17:13.000Z (about 8 years ago)
- Default Branch: master
- Last Pushed: 2020-04-12T15:59:40.000Z (almost 5 years ago)
- Last Synced: 2024-08-01T17:33:07.756Z (6 months ago)
- Topics: crystal, wkhtmltopdf, wkhtmltox
- Language: Crystal
- Homepage:
- Size: 82 KB
- Stars: 22
- Watchers: 3
- Forks: 6
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
Awesome Lists containing this project
- awesome-crystal - wkhtmltopdf-crystal - Bindings / wrapper for libwkhtmltox (HTML to PDF / image converter) (Converters)
- awesome-crystal - wkhtmltopdf-crystal - Bindings / wrapper for libwkhtmltox (HTML to PDF / image converter) (Converters)
README
# WkHtmlToPdf for Crystal - PROJECT UNMAINTAINED [![Build Status](https://travis-ci.org/blocknotes/wkhtmltopdf-crystal.svg)](https://travis-ci.org/blocknotes/wkhtmltopdf-crystal)
> *This project is not maintained anymore*
>
> *If you like it or continue to use it fork it please.** * *
* * *Crystal wrapper for libwkhtmltox C library.
*wkhtmltopdf* and *wkhtmltoimage* permit to render HTML into PDF and various image formats using the Qt WebKit rendering engine - see [wkhtmltopdf.org](http://wkhtmltopdf.org)
## Requirements
- *libwkhtmltox* must be installed
- *pkg-config* must be available## Installation
- Add this to your application's `shard.yml`:
```yml
dependencies:
wkhtmltopdf-crystal:
github: blocknotes/wkhtmltopdf-crystal
```- If wkhtmltox library is installed but missing for Crystal compiler: copy *wkhtmltox.pc* (from lib/wkhtmltopdf-crystal folder) in a pkg-config folder (ex. /usr/local/lib/pkgconfig) or set the environment variable PKG_CONFIG_PATH with the path to *wkhtmltox.pc* before compiling
- Optinally edit *wkhtmltox.pc* with the correct path to wkhtmltox (default headers path: /usr/local/include/wkhtmltox)## Usage
HTML to PDF:
```ruby
require "wkhtmltopdf-crystal"
Wkhtmltopdf::WkPdf.new( "test.pdf" ).convert( "Just a test
" )
```Fetch URL content and convert it to JPG:
```ruby
require "wkhtmltopdf-crystal"
img = Wkhtmltopdf::WkImage.new
img.set_url "http://www.google.com"
img.set_output "test.jpg"
img.set "quality", "90"
img.convert
```Write to buffer (only if no output is specified):
```ruby
require "wkhtmltopdf-crystal"
pdf = Wkhtmltopdf::WkPdf.new
pdf.convert "Just a test
"
pdf.object_setting "footer.right", "[page] / [topage]" # Set page counter on footer
unless pdf.buffer.nil?
puts "PDF buffer size: " + pdf.buffer.try( &.size ).to_s
end
```Lib settings (available with `set` / `object_setting` methods on wrappers): [libwkhtmltox pagesettings](http://wkhtmltopdf.org/libwkhtmltox/pagesettings.html)
## More examples
See [examples](https://github.com/blocknotes/wkhtmltopdf-crystal/tree/master/examples) folder. Includes a Kemal example to print an ECR view in PDF.
## Troubleshooting
#### Invalid memory access
- If this component needs to be called multiple times it's necessary to initialize the library in the constructor and call deinitialize when all is done.
Example:```ruby
require "wkhtmltopdf-crystal"
pdf = Wkhtmltopdf::WkPdf.new "", true
at_exit do
pdf.deinitialize
endpdf.set_output "test1.pdf"
pdf.convert "Just a test 1
"pdf.set_output "test2.pdf"
pdf.convert "Just a test 2
"
```## Contributors
- [Mattia Roccoberton](http://blocknot.es) - creator, maintainer