Skip to content

neroist/nim-wkhtmltox

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

22 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

nim-wkhtmltox

Nim bindings to wkhtmltox.

Distributing

This library depends on the wkhtmltox DLL, so please package it when distributing your application.

You can use -d:wkImageLib and -d:wkPdfLib to control what directory the DLLs are looked for, for the image and pdf submodules respectively.

Get Started

You can get started with the examples listed here or in the examples/ directory.

Documentation

Follow libwkhtmltox's directly here (Archive)

Examples

To PDF:

import nimwkhtmltox/pdf

initPdf()

# from w3schools
let content = """
<!DOCTYPE html>
<html>
<head>
  <style>
    h1 {
      color: blue;
      font-family: verdana;
      font-size: 300%;
    }

    p  {
      color: red;
      font-family: courier;
      font-size: 160%;
    }
  </style>
</head>
<body>

  <h1>This is a heading</h1>
  <p>This is a paragraph.</p>

</body>
</html>
"""

let settings = createGlobalSettings()
settings.setGlobalSetting("out", "./index.pdf")

let conv =  createConverter(settings)

let objSettings = createObjectSettings()

conv.addObject(objSettings, content)

conv.convert()

deinitPdf()
import nimwkhtmltox/pdf

initPDF()

toPDF(
  "https://wkhtmltopdf.org/libwkhtmltox/pagesettings.html",
  createGlobalSettings({
    "out": "pagesettings.pdf"
  })
)

deinitPDF()

To Image:

import nimwkhtmltox/image

initImage()

let settings = createGlobalSettings()
settings.setGlobalSettings({
  "in": "https://spdx.org/licenses/LGPL-3.0-or-later.html",
  "out": "license.png",
  "fmt": "png"
})

let conv = createConverter(settings, "")

conv.convert()

deinitImage()
import nimwkhtmltox/image

initImage()

toImage(
  "https://github.com/neroist/nim-wkhtmltox",
  createGlobalSettings({
    "out": "nim-wkhtmltox.png",
    "fmt": "png"
  })
)

deinitImage()