Formats Chilkat2 Perl Reference Documentation

Chilkat2::Formats

Current Version: 11.7.0

Markdown version of this page for AI tools (v 11.7.0) · all AI docs

Chilkat.Formats

A collection of data-format operations, starting with barcode and QR code generation.

Chilkat.Formats is not string, number or date display formatting. It groups operations on well-defined data formats behind a small number of JSON-driven methods, so the class can grow by adding a method per format family without adding a public class for each feature. Introduced in v11.7.0 with the barcode feature methods Barcode and QrCode.

QR Code generation

Versions 1–40, error-correction levels L/M/Q/H, automatic or explicit version and mask, numeric/alphanumeric/byte modes, ECI, structured append.

Precise rendering

Integer-pixel modules, px/mm/in/pt units with DPI, quiet zone, padding, rotation, colors with opacity, caption text, size limits with shrink-to-fit.

PNG or SVG output

Returned inline as base64 or SVG text, or written to files (numbered file sets for structured append). Optional module bit-matrix and reusable definition.

Measure and validate

measure reports exact geometry without rendering; validate checks a request; capabilities describes what the build supports.

One calling convention: every operation is method(op, jsonIn, jsonOut). Requests are checked strictly (unknown options are rejected, not ignored) and every failure has a stable error code with the JSON Pointer of the offending member.

Object Creation

use Chilkat2;

my $formats = Chilkat2::Formats->new;
# or set properties (and RaiseError) at creation:
# my $formats = Chilkat2::Formats->new(VerboseLogging => 1, RaiseError => 1);
my $formats = Chilkat2::Formats->new(Property => $value, ...);

Creates the object. The optional pairs set writable properties (and RaiseError) in order, as if set one by one; an unknown or read-only name croaks. use Chilkat2; loads every class; the Chilkat2/Formats.pm file holds only this class's documentation (perldoc Chilkat2::Formats).

Perl frees the object when its last reference goes (undef $formats, or the variable going out of scope); there is nothing to close. Objects returned by methods are independent and freed the same way. The class may be subclassed (use parent -norequire, 'Chilkat2::Formats';): an object is a blessed hash reference whose hash is free for the subclass's own fields.

my $boolVal = $formats->RaiseError;
$formats->RaiseError($boolVal);

When false (the default), a method that fails returns false (or undef), and the reason is in LastErrorText. When true, it dies with a Chilkat2::Error instead, as DBI does with its RaiseError. Objects returned by a method inherit the value of the object that returned them.

Errors

A Chilkat2::Error stringifies to the failed call's full LastErrorText, and has the methods text, class ('Chilkat2::Formats'), method (the method name) and object. Methods that look something up and find nothing return undef without dying (each such method says so), methods that answer a question (HasMember, IsUnlocked, ...) return a plain boolean, and property reads and writes never fail for Chilkat reasons.

Misuse always croaks, with your file and line, whatever RaiseError is: a wrong number of arguments, a reference or undef where a string or number is expected, an object of the wrong class, an out-of-range integer, a string containing a NUL character, a wide character in a byte string, or a write to a read-only property.

Strings are Perl character strings in both directions (length, regexes and :encoding layers see characters); binary data (BinData) is a byte string. Unlocking: call Chilkat2::Global->new->UnlockBundle('...') once at startup.

Properties

DebugLogFilePath
# $strVal is a string
my $strVal = $formats->DebugLogFilePath;
$formats->DebugLogFilePath($strVal);

If set to a file path, this property logs the LastErrorText of each Chilkat method or property call to the specified file. This logging helps identify the context and history of Chilkat calls leading up to any crash or hang, aiding in debugging.

Enabling the VerboseLogging property provides more detailed information. This property is mainly used for debugging rare instances where a Chilkat method call causes a hang or crash, which should generally not happen.

Possible causes of hangs include:

  • A timeout property set to 0, indicating an infinite timeout.
  • A hang occurring within an event callback in the application code.
  • An internal bug in the Chilkat code causing the hang.

More Information and Examples
top
LastErrorHtml
# $strVal is a string (read-only)
my $strVal = $formats->LastErrorHtml;

Provides HTML-formatted information about the last called method or property. If a method call fails or behaves unexpectedly, check this property for details. Note that information is available regardless of the method call's success.

top
LastErrorText
# $strVal is a string (read-only)
my $strVal = $formats->LastErrorText;

Provides plain text information about the last called method or property. If a method call fails or behaves unexpectedly, check this property for details. Note that information is available regardless of the method call's success.

top
LastErrorXml
# $strVal is a string (read-only)
my $strVal = $formats->LastErrorXml;

Provides XML-formatted information about the last called method or property. If a method call fails or behaves unexpectedly, check this property for details. Note that information is available regardless of the method call's success.

top
LastMethodSuccess
# $boolVal is a boolean
my $boolVal = $formats->LastMethodSuccess;
$formats->LastMethodSuccess($boolVal);

Indicates the success or failure of the most recent method call: 1 means success, 0 means failure. This property remains unchanged by property setters or getters. This method is present to address challenges in checking for null or Nothing returns in certain programming languages. Note: This property does not apply to methods that return integer values or to boolean-returning methods where the boolean does not indicate success or failure.

top
VerboseLogging
# $boolVal is a boolean
my $boolVal = $formats->VerboseLogging;
$formats->VerboseLogging($boolVal);

If set to 1, then the contents of LastErrorText (or LastErrorXml, or LastErrorHtml) may contain more verbose information. The default value is 0. Verbose logging should only be used for debugging. The potentially large quantity of logged information may adversely affect peformance.

top
Version
# $strVal is a string (read-only)
my $strVal = $formats->Version;

Version of the component/library, such as "10.1.0"

More Information and Examples
top

Methods

Barcode
# $op is a string
# $jsonIn is a Chilkat2::JsonObject
# $jsonOut is a Chilkat2::JsonObject
# $success is true or false
my $success = $formats->Barcode($op, $jsonIn, $jsonOut);
Introduced in version 11.7.0

Runs one barcode operation and returns the result as JSON. $op is the operation: "generate" (encode the payload, lay out the symbol and render a PNG or SVG), "measure" (encode and lay out only, reporting the exact geometry and whether the symbol fits), "validate" (examine a request's definition, capacity or layout) or "capabilities" (describe the symbologies, operations, formats and limits this build implements). $jsonIn is the request: it names the symbology (currently "qr"), the payload (text or base64 binary) and optional encoding, render, output and limits groups. $jsonOut is replaced with the response. Every response carries errors[] and warnings[]; a successful "generate" also returns symbols[] (the encoding actually selected), measurements[] (pixel geometry) and outputs[] (the image as base64 or SVG text, or the path of the file written).

Returns 1 when the operation completed successfully. Returns 0 when the request was rejected or execution failed; errors[0] then holds a stable code, the JSON Pointer path of the offending request member and a message.

The request and response vocabulary (payload types, QR version, error correction, mask, ECI, structured append, module size and physical units, quiet zone, rotation, colors, captions, PNG/SVG output, file writing, limits and error codes) is documented in full, with examples and sample images, at the links below.

Returns true on success, false on failure; LastErrorText says why. With RaiseError on, a failure dies with a Chilkat2::Error instead (it stringifies to the LastErrorText); the object remains usable either way.

top
QrCode
# $op is a string
# $jsonIn is a Chilkat2::JsonObject
# $jsonOut is a Chilkat2::JsonObject
# $success is true or false
my $success = $formats->QrCode($op, $jsonIn, $jsonOut);
Introduced in version 11.7.0

The same as Barcode with the symbology defaulting to "qr", so the smallest request is { "payload": { "text": "..." } }. $op is the operation ("generate", "measure", "validate" or "capabilities"), $jsonIn the request and $jsonOut the response. Identical requests to QrCode and Barcode produce identical results; a request naming a symbology outside the QR family is rejected.

Generates QR Code (Model 2) symbols in versions 1-40 with error-correction levels L, M, Q and H, automatic or explicit version and mask selection, numeric, alphanumeric and byte modes, optional ECI, and structured append of up to 16 symbols. Output is PNG or SVG, returned inline (base64 or SVG text) and/or written to files.

Returns 1 when the operation completed successfully, otherwise 0 with the reason in errors[0] of $jsonOut (code, JSON Pointer path and message). See the links below for the complete documentation of every option, with examples and sample images.

Returns true on success, false on failure; LastErrorText says why. With RaiseError on, a failure dies with a Chilkat2::Error instead (it stringifies to the LastErrorText); the object remains usable either way.

top