• This repository has been archived on 19/Jun/2023
  • Stars
    star
    22
  • Rank 1,048,934 (Top 21 %)
  • Language
    Crystal
  • License
    MIT License
  • Created almost 8 years ago
  • Updated over 4 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Crystal C bindings and wrapper for libwkhtmltox library

WkHtmlToPdf for Crystal - PROJECT UNMAINTAINED Build Status

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

Requirements

  • libwkhtmltox must be installed
  • pkg-config must be available

Installation

  • Add this to your application's shard.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:

require "wkhtmltopdf-crystal"
Wkhtmltopdf::WkPdf.new( "test.pdf" ).convert( "<h3>Just a test</h3>" )

Fetch URL content and convert it to JPG:

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):

require "wkhtmltopdf-crystal"
pdf = Wkhtmltopdf::WkPdf.new
pdf.convert "<h3>Just a test</h3>"
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

More examples

See 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:
require "wkhtmltopdf-crystal"
pdf = Wkhtmltopdf::WkPdf.new "", true
at_exit do
  pdf.deinitialize
end

pdf.set_output "test1.pdf"
pdf.convert "<h3>Just a test 1</h3>"

pdf.set_output "test2.pdf"
pdf.convert "<h3>Just a test 2</h3>"

Contributors

More Repositories

1

activeadmin_quill_editor

Quill Rich Text Editor for ActiveAdmin
JavaScript
148
star
2

activeadmin_dynamic_fields

ActiveAdmin plugin to add dynamic behaviors to fields
Ruby
115
star
3

magickwand-crystal

Crystal C bindings for MagickWand library
Crystal
67
star
4

prawn-html

HTML to PDF renderer using Prawn PDF
Ruby
59
star
5

kemal-rest-api

Crystal library to create REST API with Kemal
Crystal
55
star
6

activeadmin_blaze_theme

A theme for Active Admin based on Blaze CSS 3.x
SCSS
46
star
7

activeadmin_froala_editor

Froala WYSIWYG editor for ActiveAdmin
CSS
42
star
8

rails_admin_material

Material Design theme for RailsAdmin
Ruby
37
star
9

active_storage_db

An ActiveStorage service plugin to store files in a PostgreSQL / MySQL / MSSQL database (for Rails 6/7)
Ruby
37
star
10

activeadmin_trumbowyg

Trumbowyg Editor for ActiveAdmin
JavaScript
31
star
11

administrate_ransack

A plugin for Administrate to use Ransack for filtering resources
Ruby
31
star
12

activeadmin_active_resource

Active Admin + Active Resource: to use a REST API in place of a local database as data source
Ruby
29
star
13

activeadmin_medium_editor

Medium Editor for ActiveAdmin
JavaScript
29
star
14

sinatra-rest-api

Sinatra REST API generator
Ruby
26
star
15

activeadmin_select_many

ActiveAdmin plugin for one-to-many / many-to-many / many-to-one associations
Ruby
25
star
16

activeadmin_selectize

Selectize.js for ActiveAdmin
Ruby
24
star
17

administrate-bootstrap-theme

A Bootstrap 5 theme for Administrate
SCSS
23
star
18

administrate-materialize-theme

A Material Design theme for Administrate based on Materialize framework
JavaScript
15
star
19

curl-crystal

Crystal C bindings for libcurl
Crystal
14
star
20

activeadmin_materialize_theme

A theme for Active Admin based on Materialize framework
JavaScript
13
star
21

prawn-styled-text

Prawn PDF component which adds basic HTML support
Ruby
13
star
22

activeadmin_jfu_upload

An ActiveAdmin plugin to use jQuery-File-Upload for file uploads in forms
Ruby
12
star
23

tiny_admin

A compact and composable dashboard component for Ruby
Ruby
11
star
24

rails-vue-example

Starter project for Vue.js in Rails 4.x
Ruby
9
star
25

eventish

A simple and composable event library
Ruby
8
star
26

activeadmin_simple_form

An ActiveAdmin 1.x plugin to use Simple Form in place of Formtastic in edit views
Ruby
8
star
27

just-pico

Simple Pico CMS theme made with PureCSS
CSS
6
star
28

rails_admin_mydash

RailsAdmin alternative dashboard
HTML
4
star
29

ruby_experiments

Some Ruby experiments
Ruby
3
star
30

http-mock-server

A Ruby HTTP Mock Server based on Sinatra
Ruby
3
star
31

rubocop-rbs

RucoCop extension that check RBS signatures
Ruby
3
star
32

contents_core

Simple structure to manage contents in a flexible way
Ruby
3
star
33

gumbo-crystal

Crystal C bindings for Gumbo library
Crystal
3
star
34

pinfo-rails

Command line utility to collect informations from a Ruby on Rails project
Ruby
2
star
35

active_job_store

Store jobs' state and custom data on DB
Ruby
2
star
36

editable_components

UI components editable from the front-end for Rails
JavaScript
2
star
37

phantomjs-sitemap-generator

nodejs module to generate sitemaps using PhantomJS
JavaScript
2
star
38

pico_debug

Debugging tool for Pico CMS
PHP
2
star
39

rails_full_page_cache

Sample project to use full page caching on Rails
Ruby
1
star
40

auto-seeding

Auto generate seeding data with ActiveRecord
Ruby
1
star
41

grape_by_examples

Some Grape experiments
Ruby
1
star
42

wordpress_category_featured_images

Wordpress plugin that allows to set featured images for categories
PHP
1
star
43

grape-starter-kit

A grape starter project
Ruby
1
star
44

rails_admin_extended_fields

RailsAdmin plugin to add more options to fields
Ruby
1
star