Module: WeasyRb

Defined in:
lib/weasy_rb.rb,
lib/weasy_rb/version.rb,
lib/weasy_rb/executor.rb,
lib/weasy_rb/converter.rb,
lib/weasy_rb/command_builder.rb

Overview

WeasyRb is a Ruby wrapper for the WeasyPrint Python library. It provides a simple interface to convert HTML documents to PDF files.

Examples:

Basic usage

html = "<html><body><h1>Hello, PDF!</h1></body></html>"
WeasyRb.html_to_pdf(html, "/tmp/output.pdf")

With options

options = { format: "A4", media_type: "print" }
WeasyRb.html_to_pdf(html, "/tmp/output.pdf", options)

Defined Under Namespace

Classes: CommandBuilder, CommandError, ConversionError, Converter, Error, Executor

Constant Summary collapse

VERSION =
"0.1.1"

Class Method Summary collapse

Class Method Details

.html_to_pdf(html, output_path, options = {}) ⇒ String

Main entry point for HTML to PDF conversion

Parameters:

  • html (String)

    HTML content to convert

  • output_path (String)

    Path where the PDF will be saved

  • options (Hash) (defaults to: {})

    Additional options for WeasyPrint

Returns:

  • (String)

    Path to the generated PDF file



28
29
30
# File 'lib/weasy_rb.rb', line 28

def self.html_to_pdf(html, output_path, options = {})
  Converter.new.convert(html, output_path, options)
end