pdfio(3)

NAME
pdfio - pdf read/write library

Introduction

PDFio is a simple C library for reading and writing PDF files. The primary goals of pdfio are:

•

Read any PDF file with or without encryption or linearization

•

Write PDF files without encryption or linearization

•

Extract or embed useful metadata (author, creator, page information, etc.)

•

"Filter" PDF files, for example to extract a range of pages or to embed fonts that are missing from a PDF

•

Provide access to objects used for each page

PDFio is not
 concerned with rendering or viewing a PDF file, although a PDF RIP or viewer could be written using it.

PDFio is Copyright © 2021 by Michael R Sweet and is licensed under the Apache License Version 2.0 with an (optional) exception to allow linking against GPL2/LGPL2 software. See the files "LICENSE" and "NOTICE" for more information.

  Requirements

PDFio requires the following to build the software:

•

A C99 compiler such as Clang, GCC, or MS Visual C

•

A POSIX-compliant make program

•

ZLIB (https://www.zlib.net) 1.0 or higher

IDE files for Xcode (macOS/iOS) and Visual Studio (Windows) are also provided.

  Installing pdfio

PDFio comes with a portable makefile that will work on any POSIX-compliant system with ZLIB installed. To make it, run:
    make all

To test it, run:
    make test

To install it, run:
    make install

If you want a shared library, run:
    make all-shared
    make install-shared

The default installation location is "/usr/local". Pass the prefix variable to make to install it to another location:
    make install prefix=/some/other/directory

The makefile installs the pdfio header to "${prefix}/include", the library to "${prefix}/lib", the pkg-config file to "${prefix}/lib/pkgconfig", the man page to "${prefix}/share/man/man3", and the documentation to "${prefix}/share/doc/pdfio".

The makefile supports the following variables that can be specified in the make command or as environment variables:

•

AR: the library archiver (default "ar")

•

ARFLAGS: options for the library archiver (default "cr")

•

CC: the C compiler (default "cc")

•

CFLAGS: options for the C compiler (default "")

•

CODESIGN_IDENTITY: the identity to use when code signing the shared library on macOS (default "Developer ID")

•

COMMONFLAGS: options for the C compiler and linker (typically architecture and optimization options, default is "-Os -g")

•

CPPFLAGS: options for the C preprocessor (default "")

•

DESTDIR" and "DSTROOT: specifies a root directory when installing (default is "", specify only one)

•

DSOFLAGS: options for the C compiler when linking the shared library (default "")

•

LDFLAGS: options for the C compiler when linking the test programs (default "")

•

LIBS: library options when linking the test programs (default "-lz")

•

RANLIB: program that generates a table-of-contents in a library (default "ranlib")

•

prefix: specifies the installation directory (default "/usr/local")

  Visual Studio Project

Note: I haven't yet added this...

The Visual Studio solution ("pdfio.sln") is provided for Windows developers generates both a static library and DLL.

  Xcode Project

There is also an Xcode project ("pdfio.xcodeproj") you can use on macOS which generates a static library that will be installed under "/usr/local" with:
    sudo xcodebuild install

You can reproduce this with the makefile using:
    sudo make 'COMMONFLAGS="-Os -mmacosx-version-min=10.14 -arch x86_64 -arch arm64"' install

  Detecting PDFio

PDFio can be detected using the pkg-config command, for example:
    if pkg-config --exists pdfio; then
        ...
    fi

In a makefile you can add the necessary compiler and linker options with:
    CFLAGS  +=      `pkg-config --cflags pdfio`
    LIBS    +=      `pkg-config --libs pdfio`

  Header Files

PDFio provides a primary header file that is always used:
    #include <pdfio.h>

PDFio also provides content helper functions that are defined in a separate header file:
    #include <pdfio-content.h>

API Overview

PDFio exposes several types:

•

pdfio_file_t: A PDF file (for reading or writing)

•

pdfio_array_t: An array of values

•

pdfio_dict_t: A dictionary of key/value pairs in a PDF file, object, etc.

•

pdfio_obj_t: An object in a PDF file

•

pdfio_stream_t: An object stream

  PDF Files

  PDF Values

  PDF Objects

  PDF Streams

ENUMERATIONS

  pdfio_filter_e
Compression/decompression filters for streams

PDFIO_FILTER_ASCII85
    ASCII85Decode filter (reading only)

PDFIO_FILTER_ASCIIHEX
    ASCIIHexDecode filter (reading only)

PDFIO_FILTER_CCITTFAX
    CCITTFaxDecode filter

PDFIO_FILTER_CRYPT
    Encryption filter

PDFIO_FILTER_DCT
    DCTDecode (JPEG) filter

PDFIO_FILTER_FLATE
    FlateDecode filter

PDFIO_FILTER_JBIG2
    JBIG2Decode filter

PDFIO_FILTER_JPX
    JPXDecode filter (reading only)

PDFIO_FILTER_LZW
    LZWDecode filter (reading only)

PDFIO_FILTER_NONE
    No filter

PDFIO_FILTER_RUNLENGTH
    RunLengthDecode filter (reading only)

  pdfio_valtype_e
PDF value types

PDFIO_VALTYPE_ARRAY
    Array

PDFIO_VALTYPE_BINARY
    Binary data

PDFIO_VALTYPE_BOOLEAN
    Boolean

PDFIO_VALTYPE_DATE
    Date/time

PDFIO_VALTYPE_DICT
    Dictionary

PDFIO_VALTYPE_INDIRECT
    Indirect object (N G obj)

PDFIO_VALTYPE_NAME
    Name

PDFIO_VALTYPE_NONE
    No value, not set

PDFIO_VALTYPE_NULL
    Null object

PDFIO_VALTYPE_NUMBER
    Number (integer or real)

PDFIO_VALTYPE_STRING
    String

FUNCTIONS

  pdfioArrayAppendArray
Add an array value to an array.

bool  pdfioArrayAppendArray (
    pdfio_array_t *a,
    pdfio_array_t *value
);

  pdfioArrayAppendBinary
Add a binary string value to an array.

bool  pdfioArrayAppendBinary (
    pdfio_array_t *a,
    const unsigned char *value,
    size_t valuelen
);

  pdfioArrayAppendBoolean
Add a boolean value to an array.

bool  pdfioArrayAppendBoolean (
    pdfio_array_t *a,
    bool value
);

  pdfioArrayAppendDict
Add a dictionary to an array.

bool  pdfioArrayAppendDict (
    pdfio_array_t *a,
    pdfio_dict_t *value
);

  pdfioArrayAppendName
Add a name to an array.

bool  pdfioArrayAppendName (
    pdfio_array_t *a,
    const char *value
);

  pdfioArrayAppendNumber
Add a number to an array.

bool  pdfioArrayAppendNumber (
    pdfio_array_t *a,
    double value
);

  pdfioArrayAppendObj
Add an indirect object reference to an array.

bool  pdfioArrayAppendObj (
    pdfio_array_t *a,
    pdfio_obj_t *value
);

  pdfioArrayAppendString
Add a string to an array.

bool  pdfioArrayAppendString (
    pdfio_array_t *a,
    const char *value
);

  pdfioArrayCopy
Copy an array.

pdfio_array_t * pdfioArrayCopy (
    pdfio_file_t *pdf,
    pdfio_array_t *a
);

  pdfioArrayCreate
Create an empty array.

pdfio_array_t * pdfioArrayCreate (
    pdfio_file_t *pdf
);

  pdfioArrayCreateCalibratedColorFromMatrix
Create a calibrated color space array using a CIE XYZ transform matrix.

pdfio_array_t * pdfioArrayCreateCalibratedColorFromMatrix (
    pdfio_file_t *pdf,
    size_t num_colors,
    double gamma,
    const double matrix[3][3],
    const double white_point[3]
);

  pdfioArrayCreateCalibratedColorFromPrimaries
Create a calibrated color sapce array using CIE xy primary chromacities.

pdfio_array_t * pdfioArrayCreateCalibratedColorFromPrimaries (
    pdfio_file_t *pdf,
    size_t num_colors,
    double gamma,
    double wx,
    double wy,
    double rx,
    double ry,
    double gx,
    double gy,
    double bx,
    double by
);

  pdfioArrayCreateICCBasedColor
Create an ICC-based color space array.

pdfio_array_t * pdfioArrayCreateICCBasedColor (
    pdfio_file_t *pdf,
    pdfio_obj_t *icc_object
);

  pdfioArrayCreateIndexedColor
Create an indexed color space array.

pdfio_array_t * pdfioArrayCreateIndexedColor (
    pdfio_file_t *pdf,
    size_t num_colors,
    const unsigned char *colors
);

  pdfioArrayGetArray
Get an array value from an array.

pdfio_array_t * pdfioArrayGetArray (
    pdfio_array_t *a,
    size_t n
);

  pdfioArrayGetBinary
Get a binary string value from an array.

unsigned char * pdfioArrayGetBinary (
    pdfio_array_t *a,
    size_t n,
    size_t *length
);

  pdfioArrayGetBoolean
Get a boolean value from an array.

bool  pdfioArrayGetBoolean (
    pdfio_array_t *a,
    size_t n
);

  pdfioArrayGetDict
Get a dictionary value from an array.

pdfio_dict_t * pdfioArrayGetDict (
    pdfio_array_t *a,
    size_t n
);

  pdfioArrayGetName
Get a name value from an array.

const char * pdfioArrayGetName (
    pdfio_array_t *a,
    size_t n
);

  pdfioArrayGetNumber
Get a number from an array.

double  pdfioArrayGetNumber (
    pdfio_array_t *a,
    size_t n
);

  pdfioArrayGetObj
Get an indirect object reference from an array.

pdfio_obj_t * pdfioArrayGetObj (
    pdfio_array_t *a,
    size_t n
);

  pdfioArrayGetSize
Get the length of an array.

size_t  pdfioArrayGetSize (
    pdfio_array_t *a
);

  pdfioArrayGetString
Get a string value from an array.

const char * pdfioArrayGetString (
    pdfio_array_t *a,
    size_t n
);

  pdfioArrayGetType
Get a value type from an array.

pdfio_valtype_t  pdfioArrayGetType (
    pdfio_array_t *a,
    size_t n
);

  pdfioContentClip
Clip output to the current path.

bool  pdfioContentClip (
    pdfio_stream_t *st,
    bool even_odd
);

  pdfioContentDrawImage
Draw an image object.

bool  pdfioContentDrawImage (
    pdfio_stream_t *st,
    const char *name,
    double x,
    double y,
    double width,
    double height
);

The object name must be part of the page dictionary resources, typically using the pdfioPageDictAddImage function.

  pdfioContentFill
Fill the current path.

bool  pdfioContentFill (
    pdfio_stream_t *st,
    bool even_odd
);

  pdfioContentFillAndStroke
Fill and stroke the current path.

bool  pdfioContentFillAndStroke (
    pdfio_stream_t *st,
    bool even_odd
);

  pdfioContentMatrixConcat
Concatenate a matrix to the current graphics state.

bool  pdfioContentMatrixConcat (
    pdfio_stream_t *st,
    pdfio_matrix_t m
);

  pdfioContentMatrixRotate
Rotate the current transform matrix.

bool  pdfioContentMatrixRotate (
    pdfio_stream_t *st,
    double degrees
);

  pdfioContentMatrixScale
Scale the current transform matrix.

bool  pdfioContentMatrixScale (
    pdfio_stream_t *st,
    double sx,
    double sy
);

  pdfioContentMatrixTranslate
Translate the current transform matrix.

bool  pdfioContentMatrixTranslate (
    pdfio_stream_t *st,
    double tx,
    double ty
);

  pdfioContentPathClose
Close the current path.

bool  pdfioContentPathClose (
    pdfio_stream_t *st
);

  pdfioContentPathCurve
Add a Bezier curve with two control points.

bool  pdfioContentPathCurve (
    pdfio_stream_t *st,
    double x1,
    double y1,
    double x2,
    double y2,
    double x3,
    double y3
);

  pdfioContentPathCurve13
Add a Bezier curve with an initial control point.

bool  pdfioContentPathCurve13 (
    pdfio_stream_t *st,
    double x1,
    double y1,
    double x3,
    double y3
);

  pdfioContentPathCurve23
Add a Bezier curve with a trailing control point.

bool  pdfioContentPathCurve23 (
    pdfio_stream_t *st,
    double x2,
    double y2,
    double x3,
    double y3
);

  pdfioContentPathLineTo
Add a straight line to the current path.

bool  pdfioContentPathLineTo (
    pdfio_stream_t *st,
    double x,
    double y
);

  pdfioContentPathMoveTo
Start a new subpath.

bool  pdfioContentPathMoveTo (
    pdfio_stream_t *st,
    double x,
    double y
);

  pdfioContentPathRect
Add a rectangle to the current path.

bool  pdfioContentPathRect (
    pdfio_stream_t *st,
    double x,
    double y,
    double width,
    double height
);

  pdfioContentRestore
Restore a previous graphics state.

bool  pdfioContentRestore (
    pdfio_stream_t *st
);

  pdfioContentSave
Save the current graphics state.

bool  pdfioContentSave (
    pdfio_stream_t *st
);

  pdfioContentSetDashPattern
Set the stroke pattern.

bool  pdfioContentSetDashPattern (
    pdfio_stream_t *st,
    int phase,
    int on,
    int off
);

  pdfioContentSetFillColorDeviceCMYK
Set device CMYK fill color.

bool  pdfioContentSetFillColorDeviceCMYK (
    pdfio_stream_t *st,
    double c,
    double m,
    double y,
    double k
);

  pdfioContentSetFillColorDeviceGray
Set the device gray fill color.

bool  pdfioContentSetFillColorDeviceGray (
    pdfio_stream_t *st,
    double g
);

  pdfioContentSetFillColorDeviceRGB
Set the device RGB fill color.

bool  pdfioContentSetFillColorDeviceRGB (
    pdfio_stream_t *st,
    double r,
    double g,
    double b
);

  pdfioContentSetFillColorGray
Set the calibrated gray fill color.

bool  pdfioContentSetFillColorGray (
    pdfio_stream_t *st,
    double g
);

  pdfioContentSetFillColorRGB
Set the calibrated RGB fill color.

bool  pdfioContentSetFillColorRGB (
    pdfio_stream_t *st,
    double r,
    double g,
    double b
);

  pdfioContentSetFillColorSpace
Set the fill colorspace.

bool  pdfioContentSetFillColorSpace (
    pdfio_stream_t *st,
    const char *name
);

  pdfioContentSetFlatness
Set the flatness tolerance.

bool  pdfioContentSetFlatness (
    pdfio_stream_t *st,
    double flatness
);

  pdfioContentSetLineCap
Set the line ends style.

bool  pdfioContentSetLineCap (
    pdfio_stream_t *st,
    pdfio_linecap_t lc
);

  pdfioContentSetLineJoin
Set the line joining style.

bool  pdfioContentSetLineJoin (
    pdfio_stream_t *st,
    pdfio_linejoin_t lj
);

  pdfioContentSetLineWidth
Set the line width.

bool  pdfioContentSetLineWidth (
    pdfio_stream_t *st,
    double width
);

  pdfioContentSetMiterLimit
Set the miter limit.

bool  pdfioContentSetMiterLimit (
    pdfio_stream_t *st,
    double limit
);

  pdfioContentSetStrokeColorDeviceCMYK
Set the device CMYK stroke color.

bool  pdfioContentSetStrokeColorDeviceCMYK (
    pdfio_stream_t *st,
    double c,
    double m,
    double y,
    double k
);

  pdfioContentSetStrokeColorDeviceGray
Set the device gray stroke color.

bool  pdfioContentSetStrokeColorDeviceGray (
    pdfio_stream_t *st,
    double g
);

  pdfioContentSetStrokeColorDeviceRGB
Set the device RGB stroke color.

bool  pdfioContentSetStrokeColorDeviceRGB (
    pdfio_stream_t *st,
    double r,
    double g,
    double b
);

  pdfioContentSetStrokeColorGray
Set the calibrated gray stroke color.

bool  pdfioContentSetStrokeColorGray (
    pdfio_stream_t *st,
    double g
);

  pdfioContentSetStrokeColorRGB
Set the calibrated RGB stroke color.

bool  pdfioContentSetStrokeColorRGB (
    pdfio_stream_t *st,
    double r,
    double g,
    double b
);

  pdfioContentSetStrokeColorSpace
Set the stroke color space.

bool  pdfioContentSetStrokeColorSpace (
    pdfio_stream_t *st,
    const char *name
);

  pdfioContentSetTextCharacterSpacing
Set the spacing between characters.

bool  pdfioContentSetTextCharacterSpacing (
    pdfio_stream_t *st,
    double spacing
);

  pdfioContentSetTextFont
Set the text font and size.

bool  pdfioContentSetTextFont (
    pdfio_stream_t *st,
    const char *name,
    double size
);

  pdfioContentSetTextLeading
Set text leading (line height) value.

bool  pdfioContentSetTextLeading (
    pdfio_stream_t *st,
    double leading
);

  pdfioContentSetTextMatrix
Set the text transform matrix.

bool  pdfioContentSetTextMatrix (
    pdfio_stream_t *st,
    pdfio_matrix_t m
);

  pdfioContentSetTextRenderingMode
Set the text rendering mode.

bool  pdfioContentSetTextRenderingMode (
    pdfio_stream_t *st,
    pdfio_textrendering_t mode
);

  pdfioContentSetTextRise
Set the text baseline offset.

bool  pdfioContentSetTextRise (
    pdfio_stream_t *st,
    double rise
);

  pdfioContentSetTextWordSpacing
Set the inter-word spacing.

bool  pdfioContentSetTextWordSpacing (
    pdfio_stream_t *st,
    double spacing
);

  pdfioContentSetTextXScaling
Set the horizontal scaling value.

bool  pdfioContentSetTextXScaling (
    pdfio_stream_t *st,
    double percent
);

  pdfioContentStroke
Stroke the current path.

bool  pdfioContentStroke (
    pdfio_stream_t *st
);

  pdfioContentTextBegin
Begin a text block.

bool  pdfioContentTextBegin (
    pdfio_stream_t *st
);

  pdfioContentTextEnd
End a text block.

bool  pdfioContentTextEnd (
    pdfio_stream_t *st
);

  pdfioContentTextMoveLine
Move to the next line and offset.

bool  pdfioContentTextMoveLine (
    pdfio_stream_t *st,
    double tx,
    double ty
);

  pdfioContentTextMoveTo
Offset within the current line.

bool  pdfioContentTextMoveTo (
    pdfio_stream_t *st,
    double tx,
    double ty
);

  pdfioContentTextNextLine
Move to the next line.

bool  pdfioContentTextNextLine (
    pdfio_stream_t *st
);

  pdfioContentTextShow
Show text.

bool  pdfioContentTextShow (
    pdfio_stream_t *st,
    const char *s
);

  pdfioContentTextShowJustified
Show justified text.

bool  pdfioContentTextShowJustified (
    pdfio_stream_t *st,
    size_t num_fragments,
    const double *offsets,
    const char *const *fragments
);

  pdfioContentTextShowf

bool  pdfioContentTextShowf (
    pdfio_stream_t *st,
    const char *format,
    ...
);

  pdfioDictCopy
Copy a dictionary to a PDF file.

pdfio_dict_t * pdfioDictCopy (
    pdfio_file_t *pdf,
    pdfio_dict_t *dict
);

  pdfioDictCreate
Create a dictionary to hold key/value pairs.

pdfio_dict_t * pdfioDictCreate (
    pdfio_file_t *pdf
);

  pdfioDictGetArray
Get a key array value from a dictionary.

pdfio_array_t * pdfioDictGetArray (
    pdfio_dict_t *dict,
    const char *key
);

  pdfioDictGetBinary
Get a key binary string value from a dictionary.

unsigned char * pdfioDictGetBinary (
    pdfio_dict_t *dict,
    const char *key,
    size_t *length
);

  pdfioDictGetBoolean
Get a key boolean value from a dictionary.

bool  pdfioDictGetBoolean (
    pdfio_dict_t *dict,
    const char *key
);

  pdfioDictGetDict
Get a key dictionary value from a dictionary.

pdfio_dict_t * pdfioDictGetDict (
    pdfio_dict_t *dict,
    const char *key
);

  pdfioDictGetName
Get a key name value from a dictionary.

const char * pdfioDictGetName (
    pdfio_dict_t *dict,
    const char *key
);

  pdfioDictGetNumber
Get a key number value from a dictionary.

double  pdfioDictGetNumber (
    pdfio_dict_t *dict,
    const char *key
);

  pdfioDictGetObj
Get a key indirect object value from a dictionary.

pdfio_obj_t * pdfioDictGetObj (
    pdfio_dict_t *dict,
    const char *key
);

  pdfioDictGetRect
Get a key rectangle value from a dictionary.

pdfio_rect_t * pdfioDictGetRect (
    pdfio_dict_t *dict,
    const char *key,
    pdfio_rect_t *rect
);

  pdfioDictGetString
Get a key string value from a dictionary.

const char * pdfioDictGetString (
    pdfio_dict_t *dict,
    const char *key
);

  pdfioDictGetType
Get a key value type from a dictionary.

pdfio_valtype_t  pdfioDictGetType (
    pdfio_dict_t *dict,
    const char *key
);

  pdfioDictSetArray
Set a key array in a dictionary.

bool  pdfioDictSetArray (
    pdfio_dict_t *dict,
    const char *key,
    pdfio_array_t *value
);

  pdfioDictSetBinary
Set a key binary string in a dictionary.

bool  pdfioDictSetBinary (
    pdfio_dict_t *dict,
    const char *key,
    const unsigned char *value,
    size_t valuelen
);

  pdfioDictSetBoolean
Set a key boolean in a dictionary.

bool  pdfioDictSetBoolean (
    pdfio_dict_t *dict,
    const char *key,
    bool value
);

  pdfioDictSetDict
Set a key dictionary in a dictionary.

bool  pdfioDictSetDict (
    pdfio_dict_t *dict,
    const char *key,
    pdfio_dict_t *value
);

  pdfioDictSetName
Set a key name in a dictionary.

bool  pdfioDictSetName (
    pdfio_dict_t *dict,
    const char *key,
    const char *value
);

  pdfioDictSetNull
Set a key null in a dictionary.

bool  pdfioDictSetNull (
    pdfio_dict_t *dict,
    const char *key
);

  pdfioDictSetNumber
Set a key number in a dictionary.

bool  pdfioDictSetNumber (
    pdfio_dict_t *dict,
    const char *key,
    double value
);

  pdfioDictSetObj
Set a key indirect object reference in a dictionary.

bool  pdfioDictSetObj (
    pdfio_dict_t *dict,
    const char *key,
    pdfio_obj_t *value
);

  pdfioDictSetRect
Set a key rectangle in a dictionary.

bool  pdfioDictSetRect (
    pdfio_dict_t *dict,
    const char *key,
    pdfio_rect_t *value
);

  pdfioDictSetString
Set a key literal string in a dictionary.

bool  pdfioDictSetString (
    pdfio_dict_t *dict,
    const char *key,
    const char *value
);

  pdfioDictSetStringf
Set a key formatted string in a dictionary.

bool  pdfioDictSetStringf (
    pdfio_dict_t *dict,
    const char *key,
    const char *format,
    ...
);

  pdfioFileClose
Close a PDF file and free all memory used for it.

bool  pdfioFileClose (
    pdfio_file_t *pdf
);

  pdfioFileCreate
Create a PDF file.

pdfio_file_t * pdfioFileCreate (
    const char *filename,
    const char *version,
    pdfio_rect_t *media_box,
    pdfio_rect_t *crop_box,
    pdfio_error_cb_t error_cb,
    void *error_data
);

  pdfioFileCreateBaseFontObj
Create one of the base 14 PDF fonts.

pdfio_obj_t * pdfioFileCreateBaseFontObj (
    pdfio_file_t *pdf,
    const char *name
);

This function creates one of the base 14 PDF fonts. The "name" parameter specifies the font nane:

•   Courier

•   Courier-Bold

•   Courier-BoldItalic

•   Courier-Italic

•   Helvetica

•   Helvetica-Bold

•   Helvetica-BoldOblique

•   Helvetica-Oblique

•   Symbol

•   Times-Bold

•   Times-BoldItalic

•   Times-Italic

•   Times-Roman

•   ZapfDingbats</li> </ul>

  pdfioFileCreateFontObj
Add a font object to a PDF file.

pdfio_obj_t * pdfioFileCreateFontObj (
    pdfio_file_t *pdf,
    const char *filename,
    bool unicode
);

  pdfioFileCreateICCProfileObj
Add an ICC profile object to a PDF file.

pdfio_obj_t * pdfioFileCreateICCProfileObj (
    pdfio_file_t *pdf,
    const char *filename
);

  pdfioFileCreateImageObj
Add an image object to a PDF file.

pdfio_obj_t * pdfioFileCreateImageObj (
    pdfio_file_t *pdf,
    const char *filename,
    bool interpolate
);

Currently only GIF, JPEG, and PNG files are supported.

  pdfioFileCreateObj
Create a new object in a PDF file.

pdfio_obj_t * pdfioFileCreateObj (
    pdfio_file_t *pdf,
    pdfio_dict_t *dict
);

  pdfioFileCreatePage
Create a page in a PDF file.

pdfio_stream_t * pdfioFileCreatePage (
    pdfio_file_t *pdf,
    pdfio_dict_t *dict
);

  pdfioFileFindObj
Find an object using its object number.

pdfio_obj_t * pdfioFileFindObj (
    pdfio_file_t *pdf,
    size_t number
);

This differs from pdfioFileGetObj which takes an index into the list of objects while this function takes the object number.

  pdfioFileGetID
Get the PDF file's ID strings.

pdfio_array_t * pdfioFileGetID (
    pdfio_file_t *pdf
);

  pdfioFileGetName
Get a PDF's filename.

const char * pdfioFileGetName (
    pdfio_file_t *pdf
);

  pdfioFileGetNumObjs
Get the number of objects in a PDF file.

size_t  pdfioFileGetNumObjs (
    pdfio_file_t *pdf
);

  pdfioFileGetNumPages
Get the number of pages in a PDF file.

size_t  pdfioFileGetNumPages (
    pdfio_file_t *pdf
);

  pdfioFileGetObj
Get an object from a PDF file.

pdfio_obj_t * pdfioFileGetObj (
    pdfio_file_t *pdf,
    size_t n
);

  pdfioFileGetPage
Get a page object from a PDF file.

pdfio_obj_t * pdfioFileGetPage (
    pdfio_file_t *pdf,
    size_t n
);

  pdfioFileGetVersion
Get the PDF version number for a PDF file.

const char * pdfioFileGetVersion (
    pdfio_file_t *pdf
);

  pdfioFileOpen
Open a PDF file for reading.

pdfio_file_t * pdfioFileOpen (
    const char *filename,
    pdfio_error_cb_t error_cb,
    void *error_data
);

  pdfioImageGetBytesPerLine
Get the number of bytes to read for each line.

size_t  pdfioImageGetBytesPerLine (
    pdfio_obj_t *obj
);

  pdfioImageGetHeight
Get the height of an image object.

double  pdfioImageGetHeight (
    pdfio_obj_t *obj
);

  pdfioImageGetWidth
Get the width of an image object.

double  pdfioImageGetWidth (
    pdfio_obj_t *obj
);

  pdfioObjClose
Close an object, writing any data as needed to the PDF file.

bool  pdfioObjClose (
    pdfio_obj_t *obj
);

  pdfioObjCopy
Copy an object to another PDF file.

pdfio_obj_t * pdfioObjCopy (
    pdfio_file_t *pdf,
    pdfio_obj_t *srcobj
);

  pdfioObjCreateStream
Create an object (data) stream for writing.

pdfio_stream_t * pdfioObjCreateStream (
    pdfio_obj_t *obj,
    pdfio_filter_t filter
);

  pdfioObjGetArray
Get the array associated with an object.

pdfio_array_t * pdfioObjGetArray (
    pdfio_obj_t *obj
);

  pdfioObjGetDict
Get the dictionary associated with an object.

pdfio_dict_t * pdfioObjGetDict (
    pdfio_obj_t *obj
);

  pdfioObjGetGeneration
Get the object's generation number.

unsigned short  pdfioObjGetGeneration (
    pdfio_obj_t *obj
);

  pdfioObjGetLength
Get the length of the object's (data) stream.

size_t  pdfioObjGetLength (
    pdfio_obj_t *obj
);

  pdfioObjGetNumber
Get the object's number.

size_t  pdfioObjGetNumber (
    pdfio_obj_t *obj
);

  pdfioObjGetSubtype
Get an object's subtype.

const char * pdfioObjGetSubtype (
    pdfio_obj_t *obj
);

  pdfioObjGetType
Get an object's type.

const char * pdfioObjGetType (
    pdfio_obj_t *obj
);

  pdfioObjOpenStream
Open an object's (data) stream for reading.

pdfio_stream_t * pdfioObjOpenStream (
    pdfio_obj_t *obj,
    bool decode
);

  pdfioPageCopy
Copy a page to a PDF file.

bool  pdfioPageCopy (
    pdfio_file_t *pdf,
    pdfio_obj_t *srcpage
);

  pdfioPageDictAddColorSpace
Add a color space to the page dictionary.

bool  pdfioPageDictAddColorSpace (
    pdfio_dict_t *dict,
    const char *name,
    pdfio_array_t *data
);

This function adds a named color space to the page dictionary.

The names "DefaultCMYK", "DefaultGray", and "DefaultRGB" specify the default device color space used for the page.

The "data" array contains a calibrated, indexed, or ICC-based color space array that was created using the pdfioArrayCreateCalibratedColorFromMatrix, pdfioArrayCreateCalibratedColorFromPrimaries, pdfioArrayCreateICCBasedColor, or pdfioArrayCreateIndexedColor functions.

  pdfioPageDictAddFont
Add a font object to the page dictionary.

bool  pdfioPageDictAddFont (
    pdfio_dict_t *dict,
    const char *name,
    pdfio_obj_t *obj
);

  pdfioPageDictAddImage
Add an image object to the page dictionary.

bool  pdfioPageDictAddImage (
    pdfio_dict_t *dict,
    const char *name,
    pdfio_obj_t *obj
);

  pdfioStreamClose
Close a (data) stream in a PDF file.

bool  pdfioStreamClose (
    pdfio_stream_t *st
);

  pdfioStreamConsume
Consume bytes from the stream.

bool  pdfioStreamConsume (
    pdfio_stream_t *st,
    size_t bytes
);

  pdfioStreamGetToken
Read a single PDF token from a stream.

bool  pdfioStreamGetToken (
    pdfio_stream_t *st,
    char *buffer,
    size_t bufsize
);

  pdfioStreamPeek
Peek at data in a stream.

ssize_t  pdfioStreamPeek (
    pdfio_stream_t *st,
    void *buffer,
    size_t bytes
);

  pdfioStreamPrintf
Write a formatted string to a stream.

bool  pdfioStreamPrintf (
    pdfio_stream_t *st,
    const char *format,
    ...
);

  pdfioStreamPuts
Write a literal string to a stream.

bool  pdfioStreamPuts (
    pdfio_stream_t *st,
    const char *s
);

  pdfioStreamRead
Read data from a stream.

ssize_t  pdfioStreamRead (
    pdfio_stream_t *st,
    void *buffer,
    size_t bytes
);

This function reads data from a stream. When reading decoded image data from a stream, you must read whole scanlines. The pdfioImageGetBytesPerLine function can be used to determine the proper read length.

  pdfioStreamWrite
Write data to a stream.

bool  pdfioStreamWrite (
    pdfio_stream_t *st,
    const void *buffer,
    size_t bytes
);

  pdfioStringCreate
Create a durable literal string.

char * pdfioStringCreate (
    pdfio_file_t *pdf,
    const char *s
);

This function creates a literal string associated with the PDF file "pwg". The "s" string points to a nul-terminated C string.

NULL is returned on error, otherwise a char * that is valid until pdfioFileClose is called.

  pdfioStringCreatef
Create a durable formatted string.

char * pdfioStringCreatef (
    pdfio_file_t *pdf,
    const char *format,
    ...
);

This function creates a formatted string associated with the PDF file "pwg". The "format" string contains printf-style format characters.

NULL is returned on error, otherwise a char * that is valid until pdfioFileClose is called.

STRUCTURES

  pdfio_rect_s
PDF rectangle

struct pdfio_rect_s
{
  double x1;
  double x2;
  double y1;
  double y2;
};

TYPES

  pdf_value_t
PDF value of any type

typedef struct _pdfio_value_s pdf_value_t;

  pdfio_array_t
Array of PDF values

typedef struct _pdfio_array_s pdfio_array_t;

  pdfio_dict_t
Key/value dictionary

typedef struct _pdfio_dict_s pdfio_dict_t;

  pdfio_error_cb_t
Error callback

typedef bool(*)(pdfio_file_t *pdf, const char *message, void *data) pdfio_error_cb_t;

  pdfio_file_t
PDF file

typedef struct _pdfio_file_s pdfio_file_t;

  pdfio_filter_t
Compression/decompression filters for streams

typedef enum pdfio_filter_e pdfio_filter_t;

  pdfio_obj_t
Numbered object in PDF file

typedef struct _pdfio_obj_s pdfio_obj_t;

  pdfio_rect_t
PDF rectangle

typedef struct pdfio_rect_s pdfio_rect_t;

  pdfio_stream_t
Object data stream in PDF file

typedef struct _pdfio_stream_s pdfio_stream_t;

  pdfio_valtype_t
PDF value types

typedef enum pdfio_valtype_e pdfio_valtype_t;

AUTHOR

Michael R Sweet

COPYRIGHT

Copyright (c) 2021 by Michael R Sweet