Index
- Installation
- Getting Started
- Memory Usage
- Readers and Writers
- The Document Class
- Metadata
- Pages
- Canvas
- Page Layout and Mode
- Viewer Preferences
- Document Outline
- Page Labels
- Actions
- Destinations
- Annotations
- Embedded File Streams
- Colors and Color Spaces
- Page Formats and Boundaries
- Standard and Public Key Encryption
- Fonts and Encodings
- Corrupted Documents
- Reader Enabled Documents
- Refactor Old SetaPDF Code
- API Reference
Getting Started Loading components and error handling
Table of Contents
Loading Components
No file of the SetaPDF 2 components is using include()
, require()
or a simliar statement to load a class/file. All PHP classes/files loading is done via a single autoload function which will be registered with spl_autoload_register when the file /library/SetaPDF/Autoload.php
is required once:
require_once('/absolute/path/to/library/SetaPDF/Autoload.php');
or
require_once('../relative/path/to/library/SetaPDF/Autoload.php');
After that all PHP classes and interfaces will be loaded automatically when they are needed. That's it!
With Composer
If you'd installed the component through Composer you can use the autoloader instance from Composer:
require 'vendor/autoload.php';
Error Handling
In SetaPDF 2 the error handling is done by throwing Exceptions throughout.
All SetaPDF exceptions are based on the SetaPDF_Exception
class.
Furthermore the code will throw exceptions of following types: InvalidArgumentException
, BadMethodCallException
So make sure that you catch at least the global Exception
to keep control over the code flow:
try { ... } catch (\SetaPDF_Exception $e) { // SetaPDF specific error } catch (\Exception $e) { // global exception handling }