module Prawn::QRCode
Constants
- DEFAULT_DOTSIZE
DEFAULT_DOTSIZE
defines the default size for QR Code modules in multiples of 1/72 in- VERSION
Public Class Methods
dotsize calculates the required dotsize for a QR code to be rendered with the given extent and the module size @since 0.5.0
@param [RQRCode::QRCode] qr_code QR code to render @param [Integer/Float] extent Size of QR code given in pt (1 pt == 1/72 in) @param [Integer] margin Width of margin as number of modules (defaults to 4 modules)
@return [Float] size of dot in pt (1/72 in)
# File lib/prawn/qrcode.rb, line 61 def self.dotsize(qr_code, extent, margin = 4) extent.to_f / (2 * margin + qr_code.modules.length).to_f end
Creates a QRCode
with a minimal size to fit the data with the requested error correction level. @since 0.5.0
@param [string] content The string to render as content of the QR Code @param [Integer] qr_version Optional number of modules to use initially. Will use more if input overflows module size (Default: 0) @param [symbol] level Optional Error correction level to use. One of: (:l, :m, :h, :q), Defaults to :m @param [symbol] mode Optional mode. One of (:number, :alphanumeric, :byte_8bit, :kanji), Defaults to :alphanumeric or :byte_8bit
@return [RQRCode::QRCode] QR code that can hold the specified data with the desired error correction level
@raise [RQRCodeCore::QRCodeRunTimeError] if the data specified will not fit in the largest QR code (QR version 40) with the given error correction level
# File lib/prawn/qrcode.rb, line 45 def self.min_qrcode(content, qr_version = 0, level: :m, mode: nil, **) qr_version += 1 RQRCode::QRCode.new(content, size: qr_version, level: level, mode: mode) rescue RQRCodeCore::QRCodeRunTimeError retry if qr_version < 40 raise end
Public Instance Methods
Prints a QR Code to the PDF document. The QR Code creation happens on the fly.
@param [string] content The string to render as content of the QR Code @param [symbol] level Error correction level to use. One of: (:l, :m, :h, :q), Defaults to :m @param [symbol] mode Optional mode. One of (:number, :alphanumeric, :byte_8bit, :kanji), Defaults to :alphanumeric or :byte_8bit @param [Array] pos Two-element array containing the position at which the QR-Code should be rendered. Defaults to [0,cursor] @param [Hash] options additional options that are passed on to Prawn::QRCode::Renderer
@see Renderer
# File lib/prawn/qrcode.rb, line 75 def print_qr_code(content, level: :m, mode: nil, pos: [0, cursor], **options) qr_code = Prawn::QRCode.min_qrcode(content, level: level, mode: mode) render_qr_code(qr_code, pos: pos, **options) end
Renders a prepared QR code (RQRCode::QRCode) int the pdf. @since 0.5.0
@param [RQRCode::QRCode] qr_code The QR code (an RQRCode::QRCode) to render @param [Hash] options additional options that are passed on to Prawn::QRCode::Renderer
@see Renderer
# File lib/prawn/qrcode.rb, line 88 def render_qr_code(qr_code, **options) renderer = Renderer.new(qr_code, **options) renderer.render(self) end