pdfio/doc/pdfio.3

3752 lines
87 KiB
Groff
Raw Normal View History

.TH pdfio 3 "pdf read/write library" "2024-12-19" "pdf read/write library"
2021-05-30 03:21:45 +02:00
.SH NAME
pdfio \- pdf read/write library
.SH Introduction
.PP
PDFio is a simple C library for reading and writing PDF files. The primary goals of pdfio are:
2021-05-30 03:21:45 +02:00
.IP \(bu 5
.PP
2021-10-26 04:00:25 +02:00
Read and write any version of PDF file
2021-05-30 03:21:45 +02:00
.IP \(bu 5
.PP
2021-10-26 04:00:25 +02:00
Provide access to pages, objects, and streams within a PDF file
.IP \(bu 5
.PP
Support reading and writing of encrypted PDF files
2021-05-30 03:21:45 +02:00
.IP \(bu 5
.PP
Extract or embed useful metadata (author, creator, page information, etc.)
.IP \(bu 5
.PP
"Filter" PDF files, for example to extract a range of pages or to embed fonts that are missing from a PDF
.IP \(bu 5
.PP
Provide access to objects used for each page
.PP
PDFio is
2021-05-30 03:21:45 +02:00
.I not
concerned with rendering or viewing a PDF file, although a PDF RIP or viewer could be written using it.
.PP
PDFio is Copyright \[co] 2021\-2024 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.
.SS Requirements
.PP
PDFio requires the following to build the software:
.IP \(bu 5
.PP
A C99 compiler such as Clang, GCC, or MS Visual C
.IP \(bu 5
.PP
A POSIX\-compliant make program
2023-12-06 00:39:20 +01:00
.IP \(bu 5
.PP
A POSIX\-compliant sh program
.IP \(bu 5
.PP
ZLIB (https://www.zlib.net) 1.0 or higher
.PP
IDE files for Xcode (macOS/iOS) and Visual Studio (Windows) are also provided.
.SS Installing PDFio
.PP
2023-12-06 00:39:20 +01:00
PDFio comes with a configure script that creates a portable makefile that will work on any POSIX\-compliant system with ZLIB installed. To make it, run:
.nf
2023-12-06 00:39:20 +01:00
\./configure
make
.fi
.PP
To test it, run:
.nf
make test
.fi
.PP
To install it, run:
.nf
2023-12-06 00:39:20 +01:00
sudo make install
.fi
.PP
If you want a shared library, run:
.nf
2023-12-06 00:39:20 +01:00
\./configure \-\-enable\-shared
make
sudo make install
.fi
.PP
2023-12-06 00:39:20 +01:00
The default installation location is "/usr/local". Pass the \-\-prefix option to make to install it to another location:
.nf
2023-12-06 00:39:20 +01:00
\./configure \-\-prefix=/some/other/directory
.fi
.PP
2023-12-06 00:39:20 +01:00
Other configure options can be found using the \-\-help option:
.nf
2023-12-06 00:39:20 +01:00
\./configure \-\-help
.fi
.SS Visual Studio Project
.PP
2021-06-07 23:06:13 +02:00
The Visual Studio solution ("pdfio.sln") is provided for Windows developers and generates both a static library and DLL.
.SS Xcode Project
.PP
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:
.nf
sudo xcodebuild install
.fi
.SS Detecting PDFio
.PP
PDFio can be detected using the pkg\-config command, for example:
.nf
if pkg\-config \-\-exists pdfio; then
2021-10-19 05:08:13 +02:00
...
fi
.fi
.PP
In a makefile you can add the necessary compiler and linker options with:
.nf
CFLAGS += `pkg\-config \-\-cflags pdfio`
LIBS += `pkg\-config \-\-libs pdfio`
.fi
2021-06-07 23:06:13 +02:00
.PP
2021-09-27 14:11:53 +02:00
On Windows, you need to link to the PDFIO1.LIB (DLL) library and include the zlib_native NuGet package dependency. You can also use the published pdfio_native NuGet package.
.SS Header Files
.PP
PDFio provides a primary header file that is always used:
.nf
#include <pdfio.h>
.fi
.PP
2021-07-24 19:08:46 +02:00
PDFio also provides PDF content helper functions for producing PDF content that are defined in a separate header file:
.nf
#include <pdfio\-content.h>
.fi
2024-10-25 23:50:51 +02:00
.SS Understanding PDF Files
.PP
A PDF file provides data and commands for displaying pages of graphics and text, and is structured in a way that allows it to be displayed in the same way across multiple devices and platforms. The following is a PDF which shows "Hello, World!" on one page:
.nf
%PDF\-1.0 % Header starts here
%âãÏÓ
1 0 obj % Body starts here
<<
/Kids [2 0 R]
/Count 1
/Type /Pages
>>
endobj
2 0 obj
<<
/Rotate 0
/Parent 1 0 R
/Resources 3 0 R
/MediaBox [0 0 612 792]
/Contents [4 0 R]/Type /Page
>>
endobj
3 0 obj
<<
/Font
<<
/F0
<<
/BaseFont /Times\-Italic
/Subtype /Type1
/Type /Font
>>
>>
>>
endobj
4 0 obj
<<
/Length 65
>>
stream
1. 0. 0. 1. 50. 700. cm
BT
/F0 36. Tf
(Hello, World!) Tj
ET
endstream
endobj
5 0 obj
<<
/Pages 1 0 R
/Type /Catalog
>>
endobj
xref % Cross\-reference table starts here
0 6
0000000000 65535 f
0000000015 00000 n
0000000074 00000 n
0000000192 00000 n
0000000291 00000 n
0000000409 00000 n
trailer % Trailer starts here
<<
/Root 5 0 R
/Size 6
>>
startxref
459
%%EOF
2024-10-25 23:50:51 +02:00
.fi
.PP
Header
.PP
The header is the first line of a PDF file that specifies the version of the PDF format that has been used, for example %PDF\-1.0\.
.PP
Since PDF files almost always contain binary data, they can become corrupted if line endings are changed. For example, if the file is transferred using FTP in text mode or is edited in Notepad on Windows. To allow legacy file transfer programs to determine that the file is binary, the PDF standard recommends including some bytes with character codes higher than 127 in the header, for example:
.nf
%âãÏÓ
.fi
.PP
The percent sign indicates a comment line while the other few bytes are arbitrary character codes in excess of 127. So, the whole header in our example is:
.nf
%PDF\-1.0
%âãÏÓ
.fi
.PP
Body
.PP
The file body consists of a sequence of objects, each preceded by an object number, generation number, and the obj keyword on one line, and followed by the endobj keyword on another. For example:
.nf
1 0 obj
<<
/Kids [2 0 R]
/Count 1
/Type /Pages
>>
endobj
2024-10-25 23:50:51 +02:00
.fi
.PP
In this example, the object number is 1 and the generation number is 0, meaning it is the first version of the object. The content for object 1 is between the initial 1 0 obj and trailing endobj lines. In this case, the content is the dictionary <</Kids [2 0 R] /Count 1 /Type /Pages>>\.
.PP
Cross\-Reference Table
.PP
The cross\-reference table lists the byte offset of each object in the file body. This allows random access to objects, meaning they don't have to be read in order. Objects that are not used are never read, making the process efficient. Operations like counting the number of pages in a PDF document are fast, even in large files.
.PP
Each object has an object number and a generation number. Generation numbers are used when a cross\-reference table entry is reused. For simplicity, we will assume generation numbers to be always zero and ignore them. The cross\-reference table consists of a header line that indicates the number of entries, a free entry line for object 0, and a line for each of the objects in the file body. For example:
.nf
0 6 % Six entries in table, starting at 0
0000000000 65535 f % Free entry for object 0
0000000015 00000 n % Object 1 is at byte offset 15
0000000074 00000 n % Object 2 is at byte offset 74
0000000192 00000 n % etc...
0000000291 00000 n
0000000409 00000 n % Object 5 is at byte offset 409
.fi
.PP
Trailer
.PP
The first line of the trailer is just the trailer keyword. This is followed by the trailer dictionary which contains at least the /Size entry specifying the number of entries in the cross\-reference table and the /Root entry which references the object for the document catalog which is the root element of the graph of objects in the body.
.PP
There follows a line with just the startxref keyword, a line with a single number specifying the byte offset of the start of the cross\-reference table within the file, and then the line %%EOF which signals the end of the PDF file.
.nf
trailer % Trailer keyword
<< % The trailer dictinonary
/Root 5 0 R
/Size 6
>>
startxref % startxref keyword
459 % Byte offset of cross\-reference table
%%EOF % End\-of\-file marker
2024-10-25 23:50:51 +02:00
.fi
.SH API Overview
.PP
PDFio exposes several types:
.IP \(bu 5
.PP
pdfio_file_t: A PDF file (for reading or writing)
.IP \(bu 5
.PP
pdfio_array_t: An array of values
.IP \(bu 5
.PP
pdfio_dict_t: A dictionary of key/value pairs in a PDF file, object, etc.
.IP \(bu 5
.PP
pdfio_obj_t: An object in a PDF file
.IP \(bu 5
.PP
pdfio_stream_t: An object stream
2021-06-07 23:06:13 +02:00
.SS Reading PDF Files
.PP
You open an existing PDF file using the pdfioFileOpen function:
.nf
pdfio_file_t *pdf =
pdfioFileOpen("myinputfile.pdf", password_cb, password_data,
error_cb, error_data);
2021-06-07 23:06:13 +02:00
.fi
.PP
2023-12-06 01:22:47 +01:00
where the five arguments to the function are the filename ("myinputfile.pdf"), an optional password callback function (password_cb) and data pointer value (password_data), and an optional error callback function (error_cb) and data pointer value (error_data). The password callback is called for encrypted PDF files that are not using the default password, for example:
.nf
const char *
password_cb(void *data, const char *filename)
{
(void)data; // This callback doesn't use the data pointer
(void)filename; // This callback doesn't use the filename
// Return a password string for the file...
return ("Password42");
}
.fi
.PP
The error callback is called for both errors and warnings and accepts the pdfio_file_t pointer, a message string, and the callback pointer value, for example:
2021-06-07 23:06:13 +02:00
.nf
bool
error_cb(pdfio_file_t *pdf, const char *message, void *data)
{
(void)data; // This callback does not use the data pointer
2021-06-07 23:06:13 +02:00
fprintf(stderr, "%s: %s\\n", pdfioFileGetName(pdf), message);
2021-06-07 23:06:13 +02:00
// Return false to treat warnings as errors
return (false);
}
.fi
.PP
The default error callback (NULL) does the equivalent of the above.
.PP
Each PDF file contains one or more pages. The pdfioFileGetNumPages function returns the number of pages in the file while the pdfioFileGetPage function gets the specified page in the PDF file:
.nf
pdfio_file_t *pdf; // PDF file
size_t i; // Looping var
size_t count; // Number of pages
pdfio_obj_t *page; // Current page
2021-06-07 23:06:13 +02:00
// Iterate the pages in the PDF file
for (i = 0, count = pdfioFileGetNumPages(pdf); i < count; i ++)
{
page = pdfioFileGetPage(pdf, i);
// do something with page
}
.fi
.PP
Each page is represented by a "page tree" object (what pdfioFileGetPage returns) that specifies information about the page and one or more "content" objects that contain the images, fonts, text, and graphics that appear on the page. Use the pdfioPageGetNumStreams and pdfioPageOpenStream functions to access the content streams for each page, and pdfioObjGetDict to get the associated page object dictionary. For example, if you want to display the media and crop boxes for a given page:
.nf
pdfio_file_t *pdf; // PDF file
size_t i; // Looping var
size_t count; // Number of pages
pdfio_obj_t *page; // Current page
pdfio_dict_t *dict; // Current page dictionary
pdfio_array_t *media_box; // MediaBox array
double media_values[4]; // MediaBox values
pdfio_array_t *crop_box; // CropBox array
double crop_values[4]; // CropBox values
// Iterate the pages in the PDF file
for (i = 0, count = pdfioFileGetNumPages(pdf); i < count; i ++)
{
page = pdfioFileGetPage(pdf, i);
dict = pdfioObjGetDict(page);
media_box = pdfioDictGetArray(dict, "MediaBox");
media_values[0] = pdfioArrayGetNumber(media_box, 0);
media_values[1] = pdfioArrayGetNumber(media_box, 1);
media_values[2] = pdfioArrayGetNumber(media_box, 2);
media_values[3] = pdfioArrayGetNumber(media_box, 3);
crop_box = pdfioDictGetArray(dict, "CropBox");
crop_values[0] = pdfioArrayGetNumber(crop_box, 0);
crop_values[1] = pdfioArrayGetNumber(crop_box, 1);
crop_values[2] = pdfioArrayGetNumber(crop_box, 2);
crop_values[3] = pdfioArrayGetNumber(crop_box, 3);
printf("Page %u: MediaBox=[%g %g %g %g], CropBox=[%g %g %g %g]\\n",
(unsigned)(i + 1),
media_values[0], media_values[1], media_values[2], media_values[3],
crop_values[0], crop_values[1], crop_values[2], crop_values[3]);
}
.fi
.PP
Page object dictionaries have several (mostly optional) key/value pairs, including:
.IP \(bu 5
.PP
"Annots": An array of annotation dictionaries for the page; use pdfioDictGetArray to get the array
.IP \(bu 5
.PP
"CropBox": The crop box as an array of four numbers for the left, bottom, right, and top coordinates of the target media; use pdfioDictGetArray to get a pointer to the array of numbers
.IP \(bu 5
.PP
"Dur": The number of seconds the page should be displayed; use pdfioDictGetNumber to get the page duration value
.IP \(bu 5
.PP
"Group": The dictionary of transparency group values for the page; use pdfioDictGetDict to get a pointer to the resources dictionary
.IP \(bu 5
.PP
"LastModified": The date and time when this page was last modified; use pdfioDictGetDate to get the Unix time_t value
.IP \(bu 5
.PP
"Parent": The parent page tree node object for this page; use pdfioDictGetObj to get a pointer to the object
.IP \(bu 5
.PP
"MediaBox": The media box as an array of four numbers for the left, bottom, right, and top coordinates of the target media; use pdfioDictGetArray to get a pointer to the array of numbers
.IP \(bu 5
.PP
"Resources": The dictionary of resources for the page; use pdfioDictGetDict to get a pointer to the resources dictionary
.IP \(bu 5
.PP
"Rotate": A number indicating the number of degrees of counter\-clockwise rotation to apply to the page when viewing; use pdfioDictGetNumber to get the rotation angle
.IP \(bu 5
.PP
"Thumb": A thumbnail image object for the page; use pdfioDictGetObj to get a pointer to the thumbnail image object
.IP \(bu 5
.PP
"Trans": The page transition dictionary; use pdfioDictGetDict to get a pointer to the dictionary
2021-06-07 23:06:13 +02:00
.PP
The pdfioFileClose function closes a PDF file and frees all memory that was used for it:
.nf
pdfioFileClose(pdf);
.fi
.SS Writing PDF Files
.PP
You create a new PDF file using the pdfioFileCreate function:
.nf
pdfio_rect_t media_box = { 0.0, 0.0, 612.0, 792.0 }; // US Letter
2021-07-24 19:08:46 +02:00
pdfio_rect_t crop_box = { 36.0, 36.0, 576.0, 756.0 }; // w/0.5" margins
pdfio_file_t *pdf = pdfioFileCreate("myoutputfile.pdf", "2.0",
&media_box, &crop_box,
error_cb, error_data);
2021-06-07 23:06:13 +02:00
.fi
.PP
2021-07-24 19:08:46 +02:00
where the six arguments to the function are the filename ("myoutputfile.pdf"), PDF version ("2.0"), media box (media_box), crop box (crop_box), an optional error callback function (error_cb), and an optional pointer value for the error callback function (error_data). The units for the media and crop boxes are points (1/72nd of an inch).
2021-06-07 23:06:13 +02:00
.PP
2021-09-27 14:11:53 +02:00
Alternately you can stream a PDF file using the pdfioFileCreateOutput function:
.nf
pdfio_rect_t media_box = { 0.0, 0.0, 612.0, 792.0 }; // US Letter
pdfio_rect_t crop_box = { 36.0, 36.0, 576.0, 756.0 }; // w/0.5" margins
pdfio_file_t *pdf = pdfioFileCreateOutput(output_cb, output_ctx, "2.0",
&media_box, &crop_box,
error_cb, error_data);
2021-09-27 14:11:53 +02:00
.fi
.PP
2021-06-07 23:06:13 +02:00
Once the file is created, use the pdfioFileCreateObj, pdfioFileCreatePage, and pdfioPageCopy functions to create objects and pages in the file.
.PP
Finally, the pdfioFileClose function writes the PDF cross\-reference and "trailer" information, closes the file, and frees all memory that was used for it.
.SS PDF Objects
2021-06-07 23:06:13 +02:00
.PP
PDF objects are identified using two numbers \- the object number (1 to N) and the object generation (0 to 65535) that specifies a particular version of an object. An object's numbers are returned by the pdfioObjGetNumber and pdfioObjGetGeneration functions. You can find a numbered object using the pdfioFileFindObj function.
.PP
Objects contain values (typically dictionaries) and usually an associated data stream containing images, fonts, ICC profiles, and page content. PDFio provides several accessor functions to get the value(s) associated with an object:
.IP \(bu 5
.PP
pdfioObjGetArray returns an object's array value, if any
.IP \(bu 5
.PP
pdfioObjGetDict returns an object's dictionary value, if any
.IP \(bu 5
.PP
pdfioObjGetLength returns the length of the data stream, if any
.IP \(bu 5
.PP
pdfioObjGetSubtype returns the sub\-type name of the object, for example "Image" for an image object.
.IP \(bu 5
.PP
pdfioObjGetType returns the type name of the object, for example "XObject" for an image object.
.SS PDF Streams
2021-07-24 19:08:46 +02:00
.PP
Some PDF objects have an associated data stream, such as for pages, images, ICC color profiles, and fonts. You access the stream for an existing object using the pdfioObjOpenStream function:
.nf
pdfio_file_t *pdf = pdfioFileOpen(...);
pdfio_obj_t *obj = pdfioFileFindObj(pdf, number);
pdfio_stream_t *st = pdfioObjOpenStream(obj, true);
.fi
.PP
The first argument is the object pointer. The second argument is a boolean value that specifies whether you want to decode (typically decompress) the stream data or return it as\-is.
.PP
When reading a page stream you'll use the pdfioPageOpenStream function instead:
.nf
pdfio_file_t *pdf = pdfioFileOpen(...);
pdfio_obj_t *obj = pdfioFileGetPage(pdf, number);
pdfio_stream_t *st = pdfioPageOpenStream(obj, 0, true);
.fi
.PP
2021-07-24 19:08:46 +02:00
Once you have the stream open, you can use one of several functions to read from it:
.IP \(bu 5
.PP
pdfioStreamConsume reads and discards a number of bytes in the stream
.IP \(bu 5
.PP
pdfioStreamGetToken reads a PDF token from the stream
.IP \(bu 5
.PP
pdfioStreamPeek peeks at the next stream data without advancing or "consuming" it
.IP \(bu 5
.PP
pdfioStreamRead reads a buffer of data
.PP
When you are done reading from the stream, call the pdfioStreamClose function:
.nf
pdfioStreamClose(st);
.fi
.PP
To create a stream for a new object, call the pdfioObjCreateStream function:
.nf
pdfio_file_t *pdf = pdfioFileCreate(...);
pdfio_obj_t *obj = pdfioFileCreateObj(pdf, ...);
pdfio_stream_t *st = pdfioObjCreateStream(obj, PDFIO_FILTER_FLATE);
2021-07-24 19:08:46 +02:00
.fi
.PP
The first argument is the newly created object. The second argument is either PDFIO_FILTER_NONE to specify that any encoding is done by your program or PDFIO_FILTER_FLATE to specify that PDFio should Flate compress the stream.
.PP
To create a page content stream call the pdfioFileCreatePage function:
.nf
pdfio_file_t *pdf = pdfioFileCreate(...);
pdfio_dict_t *dict = pdfioDictCreate(pdf);
\... set page dictionary keys and values ...
pdfio_stream_t *st = pdfioFileCreatePage(pdf, dict);
.fi
.PP
2021-07-24 19:08:46 +02:00
Once you have created the stream, use any of the following functions to write to the stream:
.IP \(bu 5
.PP
pdfioStreamPrintf writes a formatted string to the stream
.IP \(bu 5
.PP
pdfioStreamPutChar writes a single character to the stream
.IP \(bu 5
.PP
pdfioStreamPuts writes a C string to the stream
.IP \(bu 5
.PP
pdfioStreamWrite writes a buffer of data to the stream
.PP
The PDF content helper functions provide additional functions for writing specific PDF page stream commands.
.PP
When you are done writing the stream, call pdfioStreamClose to close both the stream and the object.
2021-06-07 23:06:13 +02:00
.SS PDF Content Helper Functions
2021-07-24 19:08:46 +02:00
.PP
2023-12-05 19:49:58 +01:00
PDFio includes many helper functions for embedding or writing specific kinds of content to a PDF file. These functions can be roughly grouped into five categories:
2021-07-24 19:08:46 +02:00
.IP \(bu 5
.PP
Color Space Functions
.IP \(bu 5
.PP
Font Object Functions
.IP \(bu 5
.PP
Image Object Functions
.IP \(bu 5
.PP
Page Stream Functions
.IP \(bu 5
.PP
Page Dictionary Functions
.PP
Color Space Functions
.PP
PDF color spaces are specified using well\-known names like "DeviceCMYK", "DeviceGray", and "DeviceRGB" or using arrays that define so\-called calibrated color spaces. PDFio provides several functions for embedding ICC profiles and creating color space arrays:
.IP \(bu 5
.PP
pdfioArrayCreateColorFromICCObj creates a color array for an ICC color profile object
.IP \(bu 5
.PP
pdfioArrayCreateColorFromMatrix creates a color array using a CIE XYZ color transform matrix, a gamma value, and a CIE XYZ white point
.IP \(bu 5
.PP
pdfioArrayCreateColorFromPalette creates an indexed color array from an array of sRGB values
.IP \(bu 5
.PP
pdfioArrayCreateColorFromPrimaries creates a color array using CIE XYZ primaries and a gamma value
2021-08-30 17:22:35 +02:00
.IP \(bu 5
.PP
pdfioArrayCreateColorFromStandard creates a color array for a standard color space
2021-07-24 19:08:46 +02:00
.PP
You can embed an ICC color profile using the pdfioFileCreateICCObjFromFile function:
.nf
pdfio_file_t *pdf = pdfioFileCreate(...);
pdfio_obj_t *icc = pdfioFileCreateICCObjFromFile(pdf, "filename.icc");
.fi
.PP
where the first argument is the PDF file and the second argument is the filename of the ICC color profile.
.PP
PDFio also includes predefined constants for creating a few standard color spaces:
.nf
pdfio_file_t *pdf = pdfioFileCreate(...);
2021-07-24 19:08:46 +02:00
// Create an AdobeRGB color array
pdfio_array_t *adobe_rgb =
pdfioArrayCreateColorFromStandard(pdf, 3, PDFIO_CS_ADOBE);
2021-07-24 19:08:46 +02:00
// Create an Display P3 color array
pdfio_array_t *display_p3 =
pdfioArrayCreateColorFromStandard(pdf, 3, PDFIO_CS_P3_D65);
2021-07-24 19:08:46 +02:00
// Create an sRGB color array
pdfio_array_t *srgb =
pdfioArrayCreateColorFromStandard(pdf, 3, PDFIO_CS_SRGB);
2021-07-24 19:08:46 +02:00
.fi
.PP
Font Object Functions
.PP
PDF supports many kinds of fonts, including PostScript Type1, PDF Type3, TrueType/OpenType, and CID. PDFio provides two functions for creating font objects. The first is pdfioFileCreateFontObjFromBase which creates a font object for one of the base PDF fonts:
.IP \(bu 5
.PP
"Courier"
.IP \(bu 5
.PP
"Courier\-Bold"
.IP \(bu 5
.PP
"Courier\-BoldItalic"
.IP \(bu 5
.PP
"Courier\-Italic"
.IP \(bu 5
.PP
"Helvetica"
.IP \(bu 5
.PP
"Helvetica\-Bold"
.IP \(bu 5
.PP
"Helvetica\-BoldOblique"
.IP \(bu 5
.PP
"Helvetica\-Oblique"
.IP \(bu 5
.PP
"Symbol"
.IP \(bu 5
.PP
"Times\-Bold"
.IP \(bu 5
.PP
"Times\-BoldItalic"
.IP \(bu 5
.PP
"Times\-Italic"
.IP \(bu 5
.PP
"Times\-Roman"
.IP \(bu 5
.PP
"ZapfDingbats"
.PP
Except for Symbol and ZapfDingbats (which use a custom 8\-bit character set), PDFio always uses the Windows CP1252 subset of Unicode for these fonts.
2021-07-24 19:08:46 +02:00
.PP
The second function is pdfioFileCreateFontObjFromFile which creates a font object from a TrueType/OpenType font file, for example:
.nf
pdfio_file_t *pdf = pdfioFileCreate(...);
pdfio_obj_t *arial =
pdfioFileCreateFontObjFromFile(pdf, "OpenSans\-Regular.ttf", false);
2021-07-24 19:08:46 +02:00
.fi
.PP
will embed an OpenSans Regular TrueType font using the Windows CP1252 subset of Unicode. Pass true for the third argument to embed it as a Unicode CID font instead, for example:
.nf
pdfio_file_t *pdf = pdfioFileCreate(...);
pdfio_obj_t *arial =
pdfioFileCreateFontObjFromFile(pdf, "NotoSansJP\-Regular.otf", true);
2021-07-24 19:08:46 +02:00
.fi
.PP
will embed the NotoSansJP Regular OpenType font with full support for Unicode.
.PP
Note: Not all fonts support Unicode, and most do not contain a full complement of Unicode characters. pdfioFileCreateFontObjFromFile does not perform any character subsetting, so the entire font file is embedded in the PDF file.
2023-12-05 19:49:58 +01:00
2021-07-24 19:08:46 +02:00
.PP
Image Object Functions
.PP
2021-07-24 21:28:47 +02:00
PDF supports images with many different color spaces and bit depths with optional transparency. PDFio provides two helper functions for creating image objects that can be referenced in page streams. The first function is pdfioFileCreateImageObjFromData which creates an image object from data in memory, for example:
.nf
pdfio_file_t *pdf = pdfioFileCreate(...);
unsigned char data[1024 * 1024 * 4]; // 1024x1024 RGBA image data
pdfio_obj_t *img =
pdfioFileCreateImageObjFromData(pdf, data, /*width*/1024,
/*height*/1024, /*num_colors*/3,
/*color_data*/NULL, /*alpha*/true,
/*interpolate*/false);
2021-07-24 21:28:47 +02:00
.fi
.PP
will create an object for a 1024x1024 RGBA image in memory, using the default color space for 3 colors ("DeviceRGB"). We can use one of the color space functions to use a specific color space for this image, for example:
.nf
pdfio_file_t *pdf = pdfioFileCreate(...);
2021-07-24 21:28:47 +02:00
// Create an AdobeRGB color array
pdfio_array_t *adobe_rgb =
pdfioArrayCreateColorFromMatrix(pdf, 3, pdfioAdobeRGBGamma,
pdfioAdobeRGBMatrix,
pdfioAdobeRGBWhitePoint);
2021-07-24 21:28:47 +02:00
// Create a 1024x1024 RGBA image using AdobeRGB
unsigned char data[1024 * 1024 * 4]; // 1024x1024 RGBA image data
pdfio_obj_t *img =
pdfioFileCreateImageObjFromData(pdf, data, /*width*/1024,
/*height*/1024, /*num_colors*/3,
/*color_data*/adobe_rgb,
/*alpha*/true,
/*interpolate*/false);
2021-07-24 21:28:47 +02:00
.fi
.PP
The "interpolate" argument specifies whether the colors in the image should be smoothed/interpolated when scaling. This is most useful for photographs but should be false for screenshot and barcode images.
.PP
If you have a JPEG or PNG file, use the pdfioFileCreateImageObjFromFile function to copy the image into a PDF image object, for example:
.nf
pdfio_file_t *pdf = pdfioFileCreate(...);
pdfio_obj_t *img =
pdfioFileCreateImageObjFromFile(pdf, "myphoto.jpg",
/*interpolate*/true);
2021-07-24 21:28:47 +02:00
.fi
.PP
Note: Currently pdfioFileCreateImageObjFromFile does not support 12 bit JPEG files or PNG files with an alpha channel.
2021-07-24 21:28:47 +02:00
.PP
2021-07-24 19:08:46 +02:00
Page Dictionary Functions
.PP
PDF pages each have an associated dictionary to specify the images, fonts, and color spaces used by the page. PDFio provides functions to add these resources to the dictionary:
.IP \(bu 5
.PP
pdfioPageDictAddColorSpace adds a named color space to the page dictionary
.IP \(bu 5
.PP
pdfioPageDictAddFont adds a named font to the page dictionary
.IP \(bu 5
.PP
pdfioPageDictAddImage adds a named image to the page dictionary
2021-07-24 19:08:46 +02:00
.PP
Page Stream Functions
.PP
PDF page streams contain textual commands for drawing on the page. PDFio provides many functions for writing these commands with the correct format and escaping, as needed:
.IP \(bu 5
.PP
pdfioContentClip clips future drawing to the current path
.IP \(bu 5
.PP
pdfioContentDrawImage draws an image object
.IP \(bu 5
.PP
pdfioContentFill fills the current path
.IP \(bu 5
.PP
pdfioContentFillAndStroke fills and strokes the current path
.IP \(bu 5
.PP
pdfioContentMatrixConcat concatenates a matrix with the current transform matrix
.IP \(bu 5
.PP
pdfioContentMatrixRotate concatenates a rotation matrix with the current transform matrix
.IP \(bu 5
.PP
pdfioContentMatrixScale concatenates a scaling matrix with the current transform matrix
.IP \(bu 5
.PP
pdfioContentMatrixTranslate concatenates a translation matrix with the current transform matrix
.IP \(bu 5
.PP
pdfioContentPathClose closes the current path
.IP \(bu 5
.PP
pdfioContentPathCurve appends a Bezier curve to the current path
.IP \(bu 5
.PP
pdfioContentPathCurve13 appends a Bezier curve with 2 control points to the current path
.IP \(bu 5
.PP
pdfioContentPathCurve23 appends a Bezier curve with 2 control points to the current path
.IP \(bu 5
.PP
pdfioContentPathLineTo appends a line to the current path
.IP \(bu 5
.PP
pdfioContentPathMoveTo moves the current point in the current path
.IP \(bu 5
.PP
pdfioContentPathRect appends a rectangle to the current path
.IP \(bu 5
.PP
pdfioContentRestore restores a previous graphics state
.IP \(bu 5
.PP
pdfioContentSave saves the current graphics state
.IP \(bu 5
.PP
pdfioContentSetDashPattern sets the line dash pattern
.IP \(bu 5
.PP
pdfioContentSetFillColorDeviceCMYK sets the current fill color using a device CMYK color
.IP \(bu 5
.PP
pdfioContentSetFillColorDeviceGray sets the current fill color using a device gray color
.IP \(bu 5
.PP
pdfioContentSetFillColorDeviceRGB sets the current fill color using a device RGB color
.IP \(bu 5
.PP
pdfioContentSetFillColorGray sets the current fill color using a calibrated gray color
.IP \(bu 5
.PP
pdfioContentSetFillColorRGB sets the current fill color using a calibrated RGB color
.IP \(bu 5
.PP
pdfioContentSetFillColorSpace sets the current fill color space
.IP \(bu 5
.PP
pdfioContentSetFlatness sets the flatness for curves
.IP \(bu 5
.PP
pdfioContentSetLineCap sets how the ends of lines are stroked
.IP \(bu 5
.PP
pdfioContentSetLineJoin sets how connections between lines are stroked
.IP \(bu 5
.PP
pdfioContentSetLineWidth sets the width of stroked lines
.IP \(bu 5
.PP
pdfioContentSetMiterLimit sets the miter limit for stroked lines
.IP \(bu 5
.PP
pdfioContentSetStrokeColorDeviceCMYK sets the current stroke color using a device CMYK color
.IP \(bu 5
.PP
pdfioContentSetStrokeColorDeviceGray sets the current stroke color using a device gray color
.IP \(bu 5
.PP
pdfioContentSetStrokeColorDeviceRGB sets the current stroke color using a device RGB color
.IP \(bu 5
.PP
pdfioContentSetStrokeColorGray sets the current stroke color using a calibrated gray color
.IP \(bu 5
.PP
pdfioContentSetStrokeColorRGB sets the current stroke color using a calibrated RGB color
.IP \(bu 5
.PP
pdfioContentSetStrokeColorSpace sets the current stroke color space
.IP \(bu 5
.PP
pdfioContentSetTextCharacterSpacing sets the spacing between characters for text
.IP \(bu 5
.PP
pdfioContentSetTextFont sets the font and size for text
.IP \(bu 5
.PP
pdfioContentSetTextLeading sets the line height for text
.IP \(bu 5
.PP
pdfioContentSetTextMatrix concatenates a matrix with the current text matrix
.IP \(bu 5
.PP
pdfioContentSetTextRenderingMode sets the text rendering mode
.IP \(bu 5
.PP
pdfioContentSetTextRise adjusts the baseline for text
.IP \(bu 5
.PP
pdfioContentSetTextWordSpacing sets the spacing between words for text
.IP \(bu 5
.PP
pdfioContentSetTextXScaling sets the horizontal scaling for text
.IP \(bu 5
.PP
pdfioContentStroke strokes the current path
.IP \(bu 5
.PP
pdfioContentTextBegin begins a block of text
.IP \(bu 5
.PP
pdfioContentTextEnd ends a block of text
.IP \(bu 5
.PP
pdfioContentTextMoveLine moves to the next line with an offset in a text block
.IP \(bu 5
.PP
pdfioContentTextMoveTo moves within the current line in a text block
.IP \(bu 5
.PP
2023-12-05 19:49:58 +01:00
pdfioContentTextNewLine moves to the beginning of the next line in a text block
.IP \(bu 5
.PP
pdfioContentTextNewLineShow moves to the beginning of the next line in a text block and shows literal text with optional word and character spacing
.IP \(bu 5
.PP
pdfioContentTextNewLineShowf moves to the beginning of the next line in a text block and shows formatted text with optional word and character spacing
.IP \(bu 5
.PP
pdfioContentTextShow draws a literal string in a text block
.IP \(bu 5
.PP
pdfioContentTextShowf draws a formatted string in a text block
.IP \(bu 5
.PP
pdfioContentTextShowJustified draws an array of literal strings with offsets between them
.SH Examples
.SS Read PDF Metadata
.PP
The pdfioinfo.c example program opens a PDF file and prints the title, author, creation date, and number of pages:
.nf
#include <pdfio.h>
#include <time.h>
int // O \- Exit status
main(int argc, // I \- Number of command\-line arguments
char *argv[]) // Command\-line arguments
{
const char *filename; // PDF filename
pdfio_file_t *pdf; // PDF file
time_t creation_date; // Creation date
struct tm *creation_tm; // Creation date/time information
char creation_text[256]; // Creation date/time as a string
// Get the filename from the command\-line...
if (argc != 2)
{
fputs("Usage: ./pdfioinfo FILENAME.pdf\\n", stderr);
return (1);
}
filename = argv[1];
// Open the PDF file with the default callbacks...
pdf = pdfioFileOpen(filename, /*password_cb*/NULL,
/*password_cbdata*/NULL, /*error_cb*/NULL,
/*error_cbdata*/NULL);
if (pdf == NULL)
return (1);
// Get the creation date and convert to a string...
creation_date = pdfioFileGetCreationDate(pdf);
creation_tm = localtime(&creation_date);
strftime(creation_text, sizeof(creation_text), "%c", creation_tm);
// Print file information to stdout...
printf("%s:\\n", filename);
printf(" Title: %s\\n", pdfioFileGetTitle(pdf));
printf(" Author: %s\\n", pdfioFileGetAuthor(pdf));
printf(" Created On: %s\\n", creation_text);
printf(" Number Pages: %u\\n", (unsigned)pdfioFileGetNumPages(pdf));
// Close the PDF file...
pdfioFileClose(pdf);
return (0);
}
.fi
.SS Create PDF File With Text and Image
.PP
The image2pdf.c example code creates a PDF file containing a JPEG or PNG image file and optional caption on a single page. The create_pdf_image_file function creates the PDF file, embeds a base font and the named JPEG or PNG image file, and then creates a page with the image centered on the page with any text centered below:
.nf
#include <pdfio.h>
#include <pdfio\-content.h>
#include <string.h>
bool // O \- True on success, false on failure
create_pdf_image_file(
const char *pdfname, // I \- PDF filename
const char *imagename, // I \- Image filename
const char *caption) // I \- Caption filename
{
pdfio_file_t *pdf; // PDF file
pdfio_obj_t *font; // Caption font
pdfio_obj_t *image; // Image
pdfio_dict_t *dict; // Page dictionary
pdfio_stream_t *page; // Page stream
double width, height; // Width and height of image
double swidth, sheight; // Scaled width and height on page
double tx, ty; // Position on page
// Create the PDF file...
pdf = pdfioFileCreate(pdfname, /*version*/NULL, /*media_box*/NULL,
/*crop_box*/NULL, /*error_cb*/NULL,
/*error_cbdata*/NULL);
if (!pdf)
return (false);
// Create a Courier base font for the caption
font = pdfioFileCreateFontObjFromBase(pdf, "Courier");
if (!font)
{
pdfioFileClose(pdf);
return (false);
}
// Create an image object from the JPEG/PNG image file...
image = pdfioFileCreateImageObjFromFile(pdf, imagename, true);
if (!image)
{
pdfioFileClose(pdf);
return (false);
}
// Create a page dictionary with the font and image...
dict = pdfioDictCreate(pdf);
pdfioPageDictAddFont(dict, "F1", font);
pdfioPageDictAddImage(dict, "IM1", image);
// Create the page and its content stream...
page = pdfioFileCreatePage(pdf, dict);
// Position and scale the image on the page...
width = pdfioImageGetWidth(image);
height = pdfioImageGetHeight(image);
// Default media_box is "universal" 595.28x792 points (8.27x11in or
// 210x279mm). Use margins of 36 points (0.5in or 12.7mm) with another
// 36 points for the caption underneath...
swidth = 595.28 \- 72.0;
sheight = swidth * height / width;
if (sheight > (792.0 \- 36.0 \- 72.0))
{
sheight = 792.0 \- 36.0 \- 72.0;
swidth = sheight * width / height;
}
tx = 0.5 * (595.28 \- swidth);
ty = 0.5 * (792 \- 36 \- sheight);
pdfioContentDrawImage(page, "IM1", tx, ty + 36.0, swidth, sheight);
// Draw the caption in black...
pdfioContentSetFillColorDeviceGray(page, 0.0);
// Compute the starting point for the text \- Courier is monospaced
// with a nominal width of 0.6 times the text height...
tx = 0.5 * (595.28 \- 18.0 * 0.6 * strlen(caption));
// Position and draw the caption underneath...
pdfioContentTextBegin(page);
pdfioContentSetTextFont(page, "F1", 18.0);
pdfioContentTextMoveTo(page, tx, ty);
pdfioContentTextShow(page, /*unicode*/false, caption);
pdfioContentTextEnd(page);
// Close the page stream and the PDF file...
pdfioStreamClose(page);
pdfioFileClose(pdf);
return (true);
}
.fi
.SS Generate a Code 128 Barcode
.PP
One\-dimensional barcodes are often rendered using special fonts that map ASCII characters to sequences of bars that can be read. The examples directory contains such a font (code128.ttf) to create "Code 128" barcodes, with an accompanying bit of example code in code128.c\.
.PP
The first thing you need to do is prepare the barcode string to use with the font. Each barcode begins with a start pattern followed by the characters or digits you want to encode, a weighted sum digit, and a stop pattern. The make_code128 function creates this string:
.nf
static char * // O \- Output string
make_code128(char *dst, // I \- Destination buffer
const char *src, // I \- Source string
size_t dstsize) // I \- Size of destination buffer
{
char *dstptr, // Pointer into destination buffer
*dstend; // End of destination buffer
int sum; // Weighted sum
static const char *code128_chars = // Code 128 characters
" !\\"#$%&'()*+,\-./0123456789:;<=>?"
"@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\\\]^_"
"`abcdefghijklmnopqrstuvwxyz{|}~\\303"
"\\304\\305\\306\\307\\310\\311\\312";
static const char code128_start_code_b = '\\314';
// Start code B
static const char code128_stop = '\\316';
// Stop pattern
// Start a Code B barcode...
dstptr = dst;
dstend = dst + dstsize \- 3;
*dstptr++ = code128_start_code_b;
sum = code128_start_code_b \- 100;
while (*src && dstptr < dstend)
{
if (*src >= ' ' && *src < 0x7f)
{
sum += (dstptr \- dst) * (*src \- ' ');
*dstptr++ = *src;
}
src ++;
}
// Add the weighted sum modulo 103
*dstptr++ = code128_chars[sum % 103];
// Add the stop pattern and return...
*dstptr++ = code128_stop;
*dstptr = '\\0';
return (dst);
}
.fi
.PP
The main function does the rest of the work. The barcode font is imported using the pdfioFileCreateFontObjFromFile function. We pass false for the "unicode" argument since we just want the (default) ASCII encoding:
.nf
barcode_font = pdfioFileCreateFontObjFromFile(pdf, "code128.ttf",
/*unicode*/false);
.fi
.PP
Since barcodes usually have the number or text represented by the barcode printed underneath it, we also need a regular text font, for which we can choose one of the standard 14 PostScript base fonts using the pdfioFIleCreateFontObjFromBase function:
.nf
text_font = pdfioFileCreateFontObjFromBase(pdf, "Helvetica");
.fi
.PP
Once we have these fonts we can measure the barcode and regular text labels using the pdfioContentTextMeasure function to determine how large the PDF page needs to be to hold the barcode and text:
.nf
// Compute sizes of the text...
const char *barcode = argv[1];
char barcode_temp[256];
if (!(barcode[0] & 0x80))
barcode = make_code128(barcode_temp, barcode, sizeof(barcode_temp));
double barcode_height = 36.0;
double barcode_width =
pdfioContentTextMeasure(barcode_font, barcode, barcode_height);
const char *text = argv[2];
double text_height = 0.0;
double text_width = 0.0;
if (text && text_font)
{
text_height = 9.0;
text_width = pdfioContentTextMeasure(text_font, text,
text_height);
}
// Compute the size of the PDF page...
pdfio_rect_t media_box;
media_box.x1 = 0.0;
media_box.y1 = 0.0;
media_box.x2 = (barcode_width > text_width ?
barcode_width : text_width) + 18.0;
media_box.y2 = barcode_height + text_height + 18.0;
.fi
.PP
Finally, we just need to create a page of the specified size that references the two fonts:
.nf
// Start a page for the barcode...
page_dict = pdfioDictCreate(pdf);
pdfioDictSetRect(page_dict, "MediaBox", &media_box);
pdfioDictSetRect(page_dict, "CropBox", &media_box);
pdfioPageDictAddFont(page_dict, "B128", barcode_font);
if (text_font)
pdfioPageDictAddFont(page_dict, "TEXT", text_font);
page_st = pdfioFileCreatePage(pdf, page_dict);
.fi
.PP
With the barcode font called "B128" and the text font called "TEXT", we can use them to draw two strings:
.nf
// Draw the page...
pdfioContentSetFillColorGray(page_st, 0.0);
pdfioContentSetTextFont(page_st, "B128", barcode_height);
pdfioContentTextBegin(page_st);
pdfioContentTextMoveTo(page_st, 0.5 * (media_box.x2 \- barcode_width),
9.0 + text_height);
pdfioContentTextShow(page_st, /*unicode*/false, barcode);
pdfioContentTextEnd(page_st);
if (text && text_font)
{
pdfioContentSetTextFont(page_st, "TEXT", text_height);
pdfioContentTextBegin(page_st);
pdfioContentTextMoveTo(page_st, 0.5 * (media_box.x2 \- text_width), 9.0);
pdfioContentTextShow(page_st, /*unicode*/false, text);
pdfioContentTextEnd(page_st);
}
pdfioStreamClose(page_st);
.fi
.SS Convert Markdown to PDF
.PP
Markdown is a simple plain text format that supports things like headings, links, character styles, tables, and embedded images. The md2pdf.c example code uses the mmd library to convert markdown to a PDF file that can be distributed.
.PP
Note: The md2pdf example is by far the most complex example code included with PDFio and shows how to layout text, add headers and footers, add links, embed images, and format tables.
2021-05-30 03:21:45 +02:00
.SH ENUMERATIONS
2021-08-30 17:22:35 +02:00
.SS pdfio_cs_e
Standard color spaces
.TP 5
PDFIO_CS_ADOBE
.br
AdobeRGB 1998
.TP 5
PDFIO_CS_P3_D65
.br
Display P3
.TP 5
PDFIO_CS_SRGB
.br
sRGB
2021-10-26 04:00:25 +02:00
.SS pdfio_encryption_e
PDF encryption modes
.TP 5
PDFIO_ENCRYPTION_AES_128
.br
128-bit AES encryption (PDF 1.6)
.TP 5
PDFIO_ENCRYPTION_AES_256
.br
256-bit AES encryption (PDF 2.0)
2021-10-26 04:00:25 +02:00
.TP 5
PDFIO_ENCRYPTION_NONE
.br
No encryption
.TP 5
PDFIO_ENCRYPTION_RC4_128
.br
128-bit RC4 encryption (PDF 1.4)
.TP 5
PDFIO_ENCRYPTION_RC4_40
.br
40-bit RC4 encryption (PDF 1.3)
2021-05-30 03:21:45 +02:00
.SS pdfio_filter_e
Compression/decompression filters for streams
.TP 5
PDFIO_FILTER_ASCII85
.br
ASCII85Decode filter (reading only)
.TP 5
PDFIO_FILTER_ASCIIHEX
.br
ASCIIHexDecode filter (reading only)
.TP 5
PDFIO_FILTER_CCITTFAX
.br
CCITTFaxDecode filter
.TP 5
PDFIO_FILTER_CRYPT
.br
Encryption filter
.TP 5
PDFIO_FILTER_DCT
.br
DCTDecode (JPEG) filter
.TP 5
PDFIO_FILTER_FLATE
.br
FlateDecode filter
.TP 5
PDFIO_FILTER_JBIG2
.br
JBIG2Decode filter
.TP 5
PDFIO_FILTER_JPX
.br
JPXDecode filter (reading only)
.TP 5
PDFIO_FILTER_LZW
.br
LZWDecode filter (reading only)
.TP 5
PDFIO_FILTER_NONE
.br
No filter
.TP 5
PDFIO_FILTER_RUNLENGTH
.br
RunLengthDecode filter (reading only)
2021-07-18 16:01:43 +02:00
.SS pdfio_linecap_e
Line capping modes
.TP 5
PDFIO_LINECAP_BUTT
.br
Butt ends
.TP 5
PDFIO_LINECAP_ROUND
.br
Round ends
.TP 5
PDFIO_LINECAP_SQUARE
.br
Square ends
.SS pdfio_linejoin_e
Line joining modes
.TP 5
PDFIO_LINEJOIN_BEVEL
.br
Bevel joint
.TP 5
PDFIO_LINEJOIN_MITER
.br
Miter joint
.TP 5
PDFIO_LINEJOIN_ROUND
.br
Round joint
2021-10-26 04:00:25 +02:00
.SS pdfio_permission_e
PDF permission bits
.TP 5
PDFIO_PERMISSION_ALL
.br
.TP 5
PDFIO_PERMISSION_ANNOTATE
.br
PDF allows annotation
.TP 5
PDFIO_PERMISSION_ASSEMBLE
.br
PDF allows assembly (insert, delete, or rotate pages, add document outlines and thumbnails)
.TP 5
PDFIO_PERMISSION_COPY
.br
PDF allows copying
.TP 5
PDFIO_PERMISSION_FORMS
.br
PDF allows filling in forms
.TP 5
PDFIO_PERMISSION_MODIFY
.br
PDF allows modification
.TP 5
PDFIO_PERMISSION_NONE
.br
No permissions
.TP 5
PDFIO_PERMISSION_PRINT
.br
PDF allows printing
.TP 5
PDFIO_PERMISSION_PRINT_HIGH
.br
PDF allows high quality printing
.TP 5
PDFIO_PERMISSION_READING
.br
PDF allows screen reading/accessibility (deprecated in PDF 2.0)
.TP 5
~0
.br
All permissions
2021-07-18 16:01:43 +02:00
.SS pdfio_textrendering_e
Text rendering modes
.TP 5
PDFIO_TEXTRENDERING_FILL
.br
Fill text
.TP 5
PDFIO_TEXTRENDERING_FILL_AND_STROKE
.br
Fill then stroke text
.TP 5
PDFIO_TEXTRENDERING_FILL_AND_STROKE_PATH
.br
Fill then stroke text and add to path
.TP 5
PDFIO_TEXTRENDERING_FILL_PATH
.br
Fill text and add to path
.TP 5
PDFIO_TEXTRENDERING_INVISIBLE
.br
Don't fill or stroke (invisible)
.TP 5
PDFIO_TEXTRENDERING_STROKE
.br
Stroke text
.TP 5
PDFIO_TEXTRENDERING_STROKE_PATH
.br
Stroke text and add to path
.TP 5
PDFIO_TEXTRENDERING_TEXT_PATH
.br
Add text to path (invisible)
2021-05-30 03:21:45 +02:00
.SS pdfio_valtype_e
PDF value types
.TP 5
PDFIO_VALTYPE_ARRAY
.br
Array
.TP 5
PDFIO_VALTYPE_BINARY
.br
Binary data
.TP 5
PDFIO_VALTYPE_BOOLEAN
.br
Boolean
.TP 5
PDFIO_VALTYPE_DATE
.br
Date/time
.TP 5
PDFIO_VALTYPE_DICT
.br
Dictionary
.TP 5
PDFIO_VALTYPE_INDIRECT
.br
Indirect object (N G obj)
.TP 5
PDFIO_VALTYPE_NAME
.br
Name
.TP 5
PDFIO_VALTYPE_NONE
.br
No value, not set
.TP 5
PDFIO_VALTYPE_NULL
.br
Null object
.TP 5
PDFIO_VALTYPE_NUMBER
.br
Number (integer or real)
.TP 5
PDFIO_VALTYPE_STRING
.br
String
.SH FUNCTIONS
.SS pdfioArrayAppendArray
Add an array value to an array.
.PP
.nf
bool pdfioArrayAppendArray (
pdfio_array_t *a,
pdfio_array_t *value
);
.fi
.SS pdfioArrayAppendBinary
Add a binary string value to an array.
.PP
.nf
bool pdfioArrayAppendBinary (
pdfio_array_t *a,
const unsigned char *value,
2021-05-30 03:21:45 +02:00
size_t valuelen
);
.fi
.SS pdfioArrayAppendBoolean
Add a boolean value to an array.
.PP
.nf
bool pdfioArrayAppendBoolean (
pdfio_array_t *a,
bool value
);
.fi
.SS pdfioArrayAppendDate
Add a date value to an array.
.PP
.nf
bool pdfioArrayAppendDate (
pdfio_array_t *a,
time_t value
);
.fi
2021-05-30 03:21:45 +02:00
.SS pdfioArrayAppendDict
Add a dictionary to an array.
.PP
.nf
bool pdfioArrayAppendDict (
pdfio_array_t *a,
pdfio_dict_t *value
);
.fi
.SS pdfioArrayAppendName
Add a name to an array.
.PP
.nf
bool pdfioArrayAppendName (
pdfio_array_t *a,
const char *value
);
.fi
.SS pdfioArrayAppendNumber
Add a number to an array.
.PP
.nf
bool pdfioArrayAppendNumber (
pdfio_array_t *a,
double value
);
.fi
.SS pdfioArrayAppendObj
2021-05-30 03:21:45 +02:00
Add an indirect object reference to an array.
.PP
.nf
bool pdfioArrayAppendObj (
2021-05-30 03:21:45 +02:00
pdfio_array_t *a,
pdfio_obj_t *value
);
.fi
.SS pdfioArrayAppendString
Add a string to an array.
.PP
.nf
bool pdfioArrayAppendString (
pdfio_array_t *a,
const char *value
);
.fi
.SS pdfioArrayCopy
Copy an array.
.PP
.nf
pdfio_array_t * pdfioArrayCopy (
pdfio_file_t *pdf,
pdfio_array_t *a
);
.fi
.SS pdfioArrayCreate
Create an empty array.
.PP
.nf
pdfio_array_t * pdfioArrayCreate (
pdfio_file_t *pdf
);
.fi
.SS pdfioArrayCreateColorFromICCObj
Create an ICC-based color space array.
.PP
.nf
pdfio_array_t * pdfioArrayCreateColorFromICCObj (
pdfio_file_t *pdf,
pdfio_obj_t *icc_object
);
.fi
.SS pdfioArrayCreateColorFromMatrix
Create a calibrated color space array using a CIE XYZ transform matrix.
.PP
.nf
pdfio_array_t * pdfioArrayCreateColorFromMatrix (
pdfio_file_t *pdf,
size_t num_colors,
double gamma,
const double matrix[3][3],
const double white_point[3]
);
.fi
.SS pdfioArrayCreateColorFromPalette
Create an indexed color space array.
.PP
.nf
pdfio_array_t * pdfioArrayCreateColorFromPalette (
pdfio_file_t *pdf,
size_t num_colors,
const unsigned char *colors
);
.fi
.SS pdfioArrayCreateColorFromPrimaries
Create a calibrated color sapce array using CIE xy primary chromacities.
.PP
.nf
pdfio_array_t * pdfioArrayCreateColorFromPrimaries (
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
);
.fi
2021-08-30 17:22:35 +02:00
.SS pdfioArrayCreateColorFromStandard
Create a color array for a standard color space.
.PP
.nf
pdfio_array_t * pdfioArrayCreateColorFromStandard (
pdfio_file_t *pdf,
size_t num_colors,
pdfio_cs_t cs
);
.fi
.PP
This function creates a color array for a standard \fBPDFIO_CS_\fR enumerated color space.
The "num_colors" argument must be \fB1\fR for grayscale and \fB3\fR for RGB color.
2021-05-30 03:21:45 +02:00
.SS pdfioArrayGetArray
Get an array value from an array.
.PP
.nf
pdfio_array_t * pdfioArrayGetArray (
pdfio_array_t *a,
size_t n
);
.fi
.SS pdfioArrayGetBinary
Get a binary string value from an array.
.PP
.nf
unsigned char * pdfioArrayGetBinary (
pdfio_array_t *a,
size_t n,
size_t *length
);
.fi
.SS pdfioArrayGetBoolean
Get a boolean value from an array.
.PP
.nf
bool pdfioArrayGetBoolean (
pdfio_array_t *a,
size_t n
);
.fi
.SS pdfioArrayGetDate
Get a date value from an array.
.PP
.nf
time_t pdfioArrayGetDate (
pdfio_array_t *a,
size_t n
);
.fi
2021-05-30 03:21:45 +02:00
.SS pdfioArrayGetDict
Get a dictionary value from an array.
.PP
.nf
pdfio_dict_t * pdfioArrayGetDict (
pdfio_array_t *a,
size_t n
);
.fi
.SS pdfioArrayGetName
Get a name value from an array.
.PP
.nf
const char * pdfioArrayGetName (
pdfio_array_t *a,
size_t n
);
.fi
.SS pdfioArrayGetNumber
Get a number from an array.
.PP
.nf
double pdfioArrayGetNumber (
pdfio_array_t *a,
size_t n
);
.fi
.SS pdfioArrayGetObj
2021-05-30 03:21:45 +02:00
Get an indirect object reference from an array.
.PP
.nf
pdfio_obj_t * pdfioArrayGetObj (
2021-05-30 03:21:45 +02:00
pdfio_array_t *a,
size_t n
);
.fi
.SS pdfioArrayGetSize
Get the length of an array.
.PP
.nf
size_t pdfioArrayGetSize (
pdfio_array_t *a
);
.fi
.SS pdfioArrayGetString
Get a string value from an array.
.PP
.nf
const char * pdfioArrayGetString (
pdfio_array_t *a,
size_t n
);
.fi
.SS pdfioArrayGetType
Get a value type from an array.
.PP
.nf
pdfio_valtype_t pdfioArrayGetType (
pdfio_array_t *a,
size_t n
);
.fi
2024-10-25 23:50:51 +02:00
.SS pdfioArrayRemove
Remove an array entry.
.PP
.nf
bool pdfioArrayRemove (
pdfio_array_t *a,
size_t n
);
.fi
2021-05-30 03:21:45 +02:00
.SS pdfioContentClip
Clip output to the current path.
.PP
.nf
bool pdfioContentClip (
pdfio_stream_t *st,
bool even_odd
);
.fi
.SS pdfioContentDrawImage
Draw an image object.
.PP
.nf
bool pdfioContentDrawImage (
pdfio_stream_t *st,
const char *name,
double x,
double y,
double width,
double height
2021-05-30 03:21:45 +02:00
);
.fi
.PP
The object name must be part of the page dictionary resources, typically
using the \fIpdfioPageDictAddImage\fR function.
.SS pdfioContentFill
Fill the current path.
.PP
.nf
bool pdfioContentFill (
pdfio_stream_t *st,
bool even_odd
);
.fi
.SS pdfioContentFillAndStroke
Fill and stroke the current path.
.PP
.nf
bool pdfioContentFillAndStroke (
pdfio_stream_t *st,
bool even_odd
);
.fi
.SS pdfioContentMatrixConcat
Concatenate a matrix to the current graphics
state.
2021-05-30 03:21:45 +02:00
.PP
.nf
bool pdfioContentMatrixConcat (
pdfio_stream_t *st,
pdfio_matrix_t m
);
.fi
.SS pdfioContentMatrixRotate
Rotate the current transform matrix.
.PP
.nf
bool pdfioContentMatrixRotate (
pdfio_stream_t *st,
double degrees
);
.fi
.SS pdfioContentMatrixScale
Scale the current transform matrix.
.PP
.nf
bool pdfioContentMatrixScale (
pdfio_stream_t *st,
double sx,
double sy
);
.fi
.SS pdfioContentMatrixTranslate
Translate the current transform matrix.
.PP
.nf
bool pdfioContentMatrixTranslate (
pdfio_stream_t *st,
double tx,
double ty
);
.fi
.SS pdfioContentPathClose
Close the current path.
.PP
.nf
bool pdfioContentPathClose (
pdfio_stream_t *st
);
.fi
.SS pdfioContentPathCurve
Add a Bezier curve with two control points.
.PP
.nf
bool pdfioContentPathCurve (
pdfio_stream_t *st,
double x1,
double y1,
double x2,
double y2,
double x3,
double y3
);
.fi
.SS pdfioContentPathCurve13
Add a Bezier curve with an initial control point.
.PP
.nf
bool pdfioContentPathCurve13 (
pdfio_stream_t *st,
double x1,
double y1,
double x3,
double y3
);
.fi
.SS pdfioContentPathCurve23
Add a Bezier curve with a trailing control point.
.PP
.nf
bool pdfioContentPathCurve23 (
pdfio_stream_t *st,
double x2,
double y2,
double x3,
double y3
);
.fi
2022-07-03 16:01:20 +02:00
.SS pdfioContentPathEnd
Clear the current path.
.PP
.nf
bool pdfioContentPathEnd (
pdfio_stream_t *st
);
.fi
2021-05-30 03:21:45 +02:00
.SS pdfioContentPathLineTo
Add a straight line to the current path.
.PP
.nf
bool pdfioContentPathLineTo (
pdfio_stream_t *st,
double x,
double y
);
.fi
.SS pdfioContentPathMoveTo
Start a new subpath.
.PP
.nf
bool pdfioContentPathMoveTo (
pdfio_stream_t *st,
double x,
double y
);
.fi
.SS pdfioContentPathRect
Add a rectangle to the current path.
.PP
.nf
bool pdfioContentPathRect (
pdfio_stream_t *st,
double x,
double y,
double width,
double height
2021-05-30 03:21:45 +02:00
);
.fi
.SS pdfioContentRestore
Restore a previous graphics state.
.PP
.nf
bool pdfioContentRestore (
pdfio_stream_t *st
);
.fi
.SS pdfioContentSave
Save the current graphics state.
.PP
.nf
bool pdfioContentSave (
pdfio_stream_t *st
);
.fi
.SS pdfioContentSetDashPattern
Set the stroke pattern.
.PP
.nf
bool pdfioContentSetDashPattern (
pdfio_stream_t *st,
2021-10-19 05:08:13 +02:00
double phase,
double on,
double off
2021-05-30 03:21:45 +02:00
);
.fi
.PP
This function sets the stroke pattern when drawing lines. If "on" and "off"
are 0, a solid line is drawn.
2021-05-30 03:21:45 +02:00
.SS pdfioContentSetFillColorDeviceCMYK
Set device CMYK fill color.
.PP
.nf
bool pdfioContentSetFillColorDeviceCMYK (
pdfio_stream_t *st,
double c,
double m,
double y,
double k
);
.fi
.SS pdfioContentSetFillColorDeviceGray
Set the device gray fill color.
.PP
.nf
bool pdfioContentSetFillColorDeviceGray (
pdfio_stream_t *st,
double g
);
.fi
.SS pdfioContentSetFillColorDeviceRGB
Set the device RGB fill color.
.PP
.nf
bool pdfioContentSetFillColorDeviceRGB (
pdfio_stream_t *st,
double r,
double g,
double b
);
.fi
.SS pdfioContentSetFillColorGray
Set the calibrated gray fill color.
.PP
.nf
bool pdfioContentSetFillColorGray (
pdfio_stream_t *st,
double g
);
.fi
.SS pdfioContentSetFillColorRGB
Set the calibrated RGB fill color.
.PP
.nf
bool pdfioContentSetFillColorRGB (
pdfio_stream_t *st,
double r,
double g,
double b
);
.fi
.SS pdfioContentSetFillColorSpace
Set the fill colorspace.
.PP
.nf
bool pdfioContentSetFillColorSpace (
pdfio_stream_t *st,
const char *name
);
.fi
.SS pdfioContentSetFlatness
Set the flatness tolerance.
.PP
.nf
bool pdfioContentSetFlatness (
pdfio_stream_t *st,
double flatness
);
.fi
.SS pdfioContentSetLineCap
Set the line ends style.
.PP
.nf
bool pdfioContentSetLineCap (
pdfio_stream_t *st,
pdfio_linecap_t lc
);
.fi
.SS pdfioContentSetLineJoin
Set the line joining style.
.PP
.nf
bool pdfioContentSetLineJoin (
pdfio_stream_t *st,
pdfio_linejoin_t lj
);
.fi
.SS pdfioContentSetLineWidth
Set the line width.
.PP
.nf
bool pdfioContentSetLineWidth (
pdfio_stream_t *st,
double width
);
.fi
.SS pdfioContentSetMiterLimit
Set the miter limit.
.PP
.nf
bool pdfioContentSetMiterLimit (
pdfio_stream_t *st,
double limit
);
.fi
.SS pdfioContentSetStrokeColorDeviceCMYK
Set the device CMYK stroke color.
.PP
.nf
bool pdfioContentSetStrokeColorDeviceCMYK (
pdfio_stream_t *st,
double c,
double m,
double y,
double k
);
.fi
.SS pdfioContentSetStrokeColorDeviceGray
Set the device gray stroke color.
.PP
.nf
bool pdfioContentSetStrokeColorDeviceGray (
pdfio_stream_t *st,
double g
);
.fi
.SS pdfioContentSetStrokeColorDeviceRGB
Set the device RGB stroke color.
.PP
.nf
bool pdfioContentSetStrokeColorDeviceRGB (
pdfio_stream_t *st,
double r,
double g,
double b
);
.fi
.SS pdfioContentSetStrokeColorGray
Set the calibrated gray stroke color.
.PP
.nf
bool pdfioContentSetStrokeColorGray (
pdfio_stream_t *st,
double g
);
.fi
.SS pdfioContentSetStrokeColorRGB
Set the calibrated RGB stroke color.
.PP
.nf
bool pdfioContentSetStrokeColorRGB (
pdfio_stream_t *st,
double r,
double g,
double b
);
.fi
.SS pdfioContentSetStrokeColorSpace
Set the stroke color space.
.PP
.nf
bool pdfioContentSetStrokeColorSpace (
pdfio_stream_t *st,
const char *name
);
.fi
.SS pdfioContentSetTextCharacterSpacing
Set the spacing between characters.
.PP
.nf
bool pdfioContentSetTextCharacterSpacing (
pdfio_stream_t *st,
double spacing
);
.fi
.SS pdfioContentSetTextFont
Set the text font and size.
.PP
.nf
bool pdfioContentSetTextFont (
pdfio_stream_t *st,
const char *name,
double size
);
.fi
.SS pdfioContentSetTextLeading
Set text leading (line height) value.
.PP
.nf
bool pdfioContentSetTextLeading (
pdfio_stream_t *st,
double leading
);
.fi
.SS pdfioContentSetTextMatrix
Set the text transform matrix.
.PP
.nf
bool pdfioContentSetTextMatrix (
pdfio_stream_t *st,
pdfio_matrix_t m
);
.fi
.SS pdfioContentSetTextRenderingMode
Set the text rendering mode.
.PP
.nf
bool pdfioContentSetTextRenderingMode (
pdfio_stream_t *st,
pdfio_textrendering_t mode
);
.fi
.SS pdfioContentSetTextRise
Set the text baseline offset.
.PP
.nf
bool pdfioContentSetTextRise (
pdfio_stream_t *st,
double rise
);
.fi
.SS pdfioContentSetTextWordSpacing
Set the inter-word spacing.
.PP
.nf
bool pdfioContentSetTextWordSpacing (
pdfio_stream_t *st,
double spacing
);
.fi
.SS pdfioContentSetTextXScaling
Set the horizontal scaling value.
.PP
.nf
bool pdfioContentSetTextXScaling (
pdfio_stream_t *st,
double percent
);
.fi
.SS pdfioContentStroke
Stroke the current path.
.PP
.nf
bool pdfioContentStroke (
pdfio_stream_t *st
);
.fi
.SS pdfioContentTextBegin
Begin a text block.
.PP
.nf
bool pdfioContentTextBegin (
pdfio_stream_t *st
);
.fi
.SS pdfioContentTextEnd
End a text block.
.PP
.nf
bool pdfioContentTextEnd (
pdfio_stream_t *st
);
.fi
2023-12-05 03:21:18 +01:00
.SS pdfioContentTextMeasure
Measure a text string and return its width.
.PP
.nf
double pdfioContentTextMeasure (
pdfio_obj_t *font,
const char *s,
double size
);
.fi
.PP
This function measures the given text string "s" and returns its width based
on "size". The text string must always use the UTF-8 (Unicode) encoding but
any control characters (such as newlines) are ignored.
2021-05-30 03:21:45 +02:00
.SS pdfioContentTextMoveLine
Move to the next line and offset.
.PP
.nf
bool pdfioContentTextMoveLine (
pdfio_stream_t *st,
double tx,
double ty
);
.fi
.SS pdfioContentTextMoveTo
Offset within the current line.
.PP
.nf
bool pdfioContentTextMoveTo (
pdfio_stream_t *st,
double tx,
double ty
);
.fi
.SS pdfioContentTextNewLine
2021-05-30 03:21:45 +02:00
Move to the next line.
.PP
.nf
bool pdfioContentTextNewLine (
2021-05-30 03:21:45 +02:00
pdfio_stream_t *st
);
.fi
.SS pdfioContentTextNewLineShow
Move to the next line and show text.
.PP
.nf
bool pdfioContentTextNewLineShow (
pdfio_stream_t *st,
double ws,
double cs,
bool unicode,
const char *s
);
.fi
.PP
This function moves to the next line and then shows some text with optional
word and character spacing in a PDF content stream. The "unicode" argument
specifies that the current font maps to full Unicode. The "s" argument
specifies a UTF-8 encoded string.
.SS pdfioContentTextNewLineShowf
Show formatted text.
.PP
.nf
bool pdfioContentTextNewLineShowf (
pdfio_stream_t *st,
double ws,
double cs,
bool unicode,
const char *format,
...
);
.fi
.PP
This function moves to the next line and shows some formatted text with
optional word and character spacing in a PDF content stream. The "unicode"
argument specifies that the current font maps to full Unicode. The "format"
argument specifies a UTF-8 encoded \fBprintf\fR-style format string.
2021-05-30 03:21:45 +02:00
.SS pdfioContentTextShow
Show text.
.PP
.nf
bool pdfioContentTextShow (
pdfio_stream_t *st,
bool unicode,
const char *s
2021-05-30 03:21:45 +02:00
);
.fi
.PP
This function shows some text in a PDF content stream. The "unicode" argument
specifies that the current font maps to full Unicode. The "s" argument
specifies a UTF-8 encoded string.
2021-05-30 03:21:45 +02:00
.SS pdfioContentTextShowJustified
Show justified text.
.PP
.nf
bool pdfioContentTextShowJustified (
pdfio_stream_t *st,
bool unicode,
2021-05-30 03:21:45 +02:00
size_t num_fragments,
const double *offsets,
const char *const *fragments
);
.fi
.PP
This function shows some text in a PDF content stream. The "unicode" argument
specifies that the current font maps to full Unicode. The "fragments"
argument specifies an array of UTF-8 encoded strings.
.SS pdfioContentTextShowf
.PP
.nf
bool pdfioContentTextShowf (
pdfio_stream_t *st,
bool unicode,
const char *format,
...
);
.fi
2024-10-25 23:50:51 +02:00
.SS pdfioDictClear
Remove a key/value pair from a dictionary.
.PP
.nf
bool pdfioDictClear (
pdfio_dict_t *dict,
const char *key
);
.fi
2021-05-30 03:21:45 +02:00
.SS pdfioDictCopy
Copy a dictionary to a PDF file.
.PP
.nf
pdfio_dict_t * pdfioDictCopy (
pdfio_file_t *pdf,
pdfio_dict_t *dict
);
.fi
.SS pdfioDictCreate
Create a dictionary to hold key/value pairs.
.PP
.nf
pdfio_dict_t * pdfioDictCreate (
pdfio_file_t *pdf
);
.fi
.SS pdfioDictGetArray
Get a key array value from a dictionary.
.PP
.nf
pdfio_array_t * pdfioDictGetArray (
pdfio_dict_t *dict,
const char *key
);
.fi
.SS pdfioDictGetBinary
Get a key binary string value from a dictionary.
.PP
.nf
unsigned char * pdfioDictGetBinary (
pdfio_dict_t *dict,
const char *key,
size_t *length
);
.fi
.SS pdfioDictGetBoolean
Get a key boolean value from a dictionary.
.PP
.nf
bool pdfioDictGetBoolean (
pdfio_dict_t *dict,
const char *key
);
.fi
.SS pdfioDictGetDate
Get a date value from a dictionary.
.PP
.nf
time_t pdfioDictGetDate (
pdfio_dict_t *dict,
const char *key
);
.fi
2021-05-30 03:21:45 +02:00
.SS pdfioDictGetDict
Get a key dictionary value from a dictionary.
.PP
.nf
pdfio_dict_t * pdfioDictGetDict (
pdfio_dict_t *dict,
const char *key
);
.fi
2024-10-25 23:50:51 +02:00
.SS pdfioDictGetKey
Get the key for the specified pair.
.PP
.nf
const char * pdfioDictGetKey (
pdfio_dict_t *dict,
size_t n
);
.fi
2021-05-30 03:21:45 +02:00
.SS pdfioDictGetName
Get a key name value from a dictionary.
.PP
.nf
const char * pdfioDictGetName (
pdfio_dict_t *dict,
const char *key
);
.fi
2024-10-25 23:50:51 +02:00
.SS pdfioDictGetNumPairs
Get the number of key/value pairs in a dictionary.
.PP
.nf
size_t pdfioDictGetNumPairs (
pdfio_dict_t *dict
);
.fi
2021-05-30 03:21:45 +02:00
.SS pdfioDictGetNumber
Get a key number value from a dictionary.
.PP
.nf
double pdfioDictGetNumber (
pdfio_dict_t *dict,
const char *key
);
.fi
.SS pdfioDictGetObj
2021-05-30 03:21:45 +02:00
Get a key indirect object value from a dictionary.
.PP
.nf
pdfio_obj_t * pdfioDictGetObj (
2021-05-30 03:21:45 +02:00
pdfio_dict_t *dict,
const char *key
);
.fi
.SS pdfioDictGetRect
Get a key rectangle value from a dictionary.
.PP
.nf
pdfio_rect_t * pdfioDictGetRect (
pdfio_dict_t *dict,
const char *key,
pdfio_rect_t *rect
);
.fi
.SS pdfioDictGetString
Get a key string value from a dictionary.
.PP
.nf
const char * pdfioDictGetString (
pdfio_dict_t *dict,
const char *key
);
.fi
.SS pdfioDictGetType
Get a key value type from a dictionary.
.PP
.nf
pdfio_valtype_t pdfioDictGetType (
pdfio_dict_t *dict,
const char *key
);
.fi
.SS pdfioDictIterateKeys
Iterate the keys in a dictionary.
.PP
.nf
void pdfioDictIterateKeys (
pdfio_dict_t *dict,
pdfio_dict_cb_t cb,
void *cb_data
);
.fi
.PP
This function iterates the keys in a dictionary, calling the supplied
function "cb":
.PP
.nf
bool
my_dict_cb(pdfio_dict_t *dict, const char *key, void *cb_data)
{
... "key" contains the dictionary key ...
... return true to continue or false to stop ...
}
.fi
The iteration continues as long as the callback returns \fBtrue\fR or all keys
have been iterated.
2021-05-30 03:21:45 +02:00
.SS pdfioDictSetArray
Set a key array in a dictionary.
.PP
.nf
bool pdfioDictSetArray (
pdfio_dict_t *dict,
const char *key,
pdfio_array_t *value
);
.fi
.SS pdfioDictSetBinary
Set a key binary string in a dictionary.
.PP
.nf
bool pdfioDictSetBinary (
pdfio_dict_t *dict,
const char *key,
const unsigned char *value,
2021-05-30 03:21:45 +02:00
size_t valuelen
);
.fi
.SS pdfioDictSetBoolean
Set a key boolean in a dictionary.
.PP
.nf
bool pdfioDictSetBoolean (
pdfio_dict_t *dict,
const char *key,
bool value
);
.fi
.SS pdfioDictSetDate
Set a date value in a dictionary.
.PP
.nf
bool pdfioDictSetDate (
pdfio_dict_t *dict,
const char *key,
time_t value
);
.fi
2021-05-30 03:21:45 +02:00
.SS pdfioDictSetDict
Set a key dictionary in a dictionary.
.PP
.nf
bool pdfioDictSetDict (
pdfio_dict_t *dict,
const char *key,
pdfio_dict_t *value
);
.fi
.SS pdfioDictSetName
Set a key name in a dictionary.
.PP
.nf
bool pdfioDictSetName (
pdfio_dict_t *dict,
const char *key,
const char *value
);
.fi
.SS pdfioDictSetNull
Set a key null in a dictionary.
.PP
.nf
bool pdfioDictSetNull (
pdfio_dict_t *dict,
const char *key
);
.fi
.SS pdfioDictSetNumber
Set a key number in a dictionary.
.PP
.nf
bool pdfioDictSetNumber (
pdfio_dict_t *dict,
const char *key,
double value
);
.fi
.SS pdfioDictSetObj
2021-05-30 03:21:45 +02:00
Set a key indirect object reference in a dictionary.
.PP
.nf
bool pdfioDictSetObj (
2021-05-30 03:21:45 +02:00
pdfio_dict_t *dict,
const char *key,
pdfio_obj_t *value
);
.fi
.SS pdfioDictSetRect
Set a key rectangle in a dictionary.
.PP
.nf
bool pdfioDictSetRect (
pdfio_dict_t *dict,
const char *key,
pdfio_rect_t *value
);
.fi
.SS pdfioDictSetString
Set a key literal string in a dictionary.
.PP
.nf
bool pdfioDictSetString (
pdfio_dict_t *dict,
const char *key,
const char *value
);
.fi
.SS pdfioDictSetStringf
Set a key formatted string in a dictionary.
.PP
.nf
bool pdfioDictSetStringf (
pdfio_dict_t *dict,
const char *key,
const char *format,
...
);
.fi
.SS pdfioFileClose
Close a PDF file and free all memory used for it.
.PP
.nf
bool pdfioFileClose (
pdfio_file_t *pdf
);
.fi
.SS pdfioFileCreate
Create a PDF file.
.PP
.nf
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,
2024-06-24 17:51:50 +02:00
void *error_cbdata
2021-05-30 03:21:45 +02:00
);
.fi
2021-09-27 14:11:53 +02:00
.PP
This function creates a new PDF file. The "filename" argument specifies the
name of the PDF file to create.
.PP
The "version" argument specifies the PDF version number for the file or
\fBNULL\fR for the default ("2.0").
.PP
The "media_box" and "crop_box" arguments specify the default MediaBox and
CropBox for pages in the PDF file - if \fBNULL\fR then a default "Universal" size
of 8.27x11in (the intersection of US Letter and ISO A4) is used.
.PP
2024-06-24 17:51:50 +02:00
The "error_cb" and "error_cbdata" arguments specify an error handler callback
and its data pointer - if \fBNULL\fR the default error handler is used that
writes error messages to \fBstderr\fR.
.SS pdfioFileCreateArrayObj
Create a new object in a PDF file containing an array.
.PP
.nf
pdfio_obj_t * pdfioFileCreateArrayObj (
pdfio_file_t *pdf,
pdfio_array_t *array
);
.fi
.PP
This function creates a new object with an array value in a PDF file.
You must call \fIpdfioObjClose\fR to write the object to the file.
.SS pdfioFileCreateFontObjFromBase
Create one of the base 14 PDF fonts.
.PP
.nf
pdfio_obj_t * pdfioFileCreateFontObjFromBase (
pdfio_file_t *pdf,
const char *name
);
.fi
.PP
This function creates one of the base 14 PDF fonts. The "name" parameter
specifies the font nane:
.PP
.IP \(bu 5
2021-07-24 19:08:46 +02:00
"Courier"
.IP \(bu 5
2021-07-24 19:08:46 +02:00
"Courier-Bold"
.IP \(bu 5
2021-07-24 19:08:46 +02:00
"Courier-BoldItalic"
.IP \(bu 5
2021-07-24 19:08:46 +02:00
"Courier-Italic"
.IP \(bu 5
2021-07-24 19:08:46 +02:00
"Helvetica"
.IP \(bu 5
2021-07-24 19:08:46 +02:00
"Helvetica-Bold"
.IP \(bu 5
2021-07-24 19:08:46 +02:00
"Helvetica-BoldOblique"
.IP \(bu 5
2021-07-24 19:08:46 +02:00
"Helvetica-Oblique"
.IP \(bu 5
2021-07-24 19:08:46 +02:00
"Symbol"
.IP \(bu 5
2021-07-24 19:08:46 +02:00
"Times-Bold"
.IP \(bu 5
2021-07-24 19:08:46 +02:00
"Times-BoldItalic"
.IP \(bu 5
2021-07-24 19:08:46 +02:00
"Times-Italic"
.IP \(bu 5
2021-07-24 19:08:46 +02:00
"Times-Roman"
.IP \(bu 5
2021-07-24 19:08:46 +02:00
"ZapfDingbats"
.PP
Aside from "Symbol" and "Zapf-Dingbats", Base fonts use the Windows CP1252
(ISO-8859-1 with additional characters such as the Euro symbol) subset of
Unicode.
.SS pdfioFileCreateFontObjFromFile
2021-05-30 03:21:45 +02:00
Add a font object to a PDF file.
.PP
.nf
pdfio_obj_t * pdfioFileCreateFontObjFromFile (
2021-05-30 03:21:45 +02:00
pdfio_file_t *pdf,
const char *filename,
bool unicode
2021-05-30 03:21:45 +02:00
);
.fi
.PP
This function embeds a TrueType/OpenType font into a PDF file. The
"unicode" parameter controls whether the font is encoded for two-byte
characters (potentially full Unicode, but more typically a subset)
or to only support the Windows CP1252 (ISO-8859-1 with additional
characters such as the Euro symbol) subset of Unicode.
.SS pdfioFileCreateICCObjFromFile
2021-05-30 03:21:45 +02:00
Add an ICC profile object to a PDF file.
.PP
.nf
pdfio_obj_t * pdfioFileCreateICCObjFromFile (
2021-05-30 03:21:45 +02:00
pdfio_file_t *pdf,
const char *filename,
size_t num_colors
2021-05-30 03:21:45 +02:00
);
.fi
2021-07-18 16:01:43 +02:00
.SS pdfioFileCreateImageObjFromData
Add image object(s) to a PDF file from memory.
.PP
.nf
pdfio_obj_t * pdfioFileCreateImageObjFromData (
pdfio_file_t *pdf,
const unsigned char *data,
size_t width,
size_t height,
size_t num_colors,
pdfio_array_t *color_data,
bool alpha,
bool interpolate
);
.fi
.PP
This function creates image object(s) in a PDF file from a data buffer in
memory. The "data" parameter points to the image data as 8-bit color values.
The "width" and "height" parameters specify the image dimensions. The
"num_colors" parameter specifies the number of color components (\fB1\fR for
grayscale, \fB3\fR for RGB, and \fB4\fR for CMYK) and the "alpha" parameter specifies
whether each color tuple is followed by an alpha value. The "color_data"
parameter specifies an optional color space array for the image - if \fBNULL\fR,
the image is encoded in the corresponding device color space. The
"interpolate" parameter specifies whether to interpolate when scaling the
image on the page.
.PP
Note: When creating an image object with alpha, a second image object is
created to hold the "soft mask" data for the primary image.
.SS pdfioFileCreateImageObjFromFile
2021-07-18 16:01:43 +02:00
Add an image object to a PDF file from a file.
2021-05-30 03:21:45 +02:00
.PP
.nf
pdfio_obj_t * pdfioFileCreateImageObjFromFile (
2021-05-30 03:21:45 +02:00
pdfio_file_t *pdf,
const char *filename,
bool interpolate
);
.fi
.PP
This function creates an image object in a PDF file from a JPEG or PNG file.
2021-07-18 16:01:43 +02:00
The "filename" parameter specifies the name of the JPEG or PNG file, while
the "interpolate" parameter specifies whether to interpolate when scaling the
image on the page.
.PP
.IP 5
Note: Currently PNG support is limited to grayscale, RGB, or indexed files
.IP 5
without interlacing or alpha. Transparency (masking) based on color/index
.IP 5
is supported.
2024-10-25 23:50:51 +02:00
.SS pdfioFileCreateNameObj
Create a new object in a PDF file containing a name.
.PP
.nf
pdfio_obj_t * pdfioFileCreateNameObj (
pdfio_file_t *pdf,
const char *name
);
.fi
.PP
This function creates a new object with a name value in a PDF file.
You must call \fIpdfioObjClose\fR to write the object to the file.
.SS pdfioFileCreateNumberObj
Create a new object in a PDF file containing a number.
.PP
.nf
pdfio_obj_t * pdfioFileCreateNumberObj (
pdfio_file_t *pdf,
double number
);
.fi
.PP
This function creates a new object with a number value in a PDF file.
You must call \fIpdfioObjClose\fR to write the object to the file.
.SS pdfioFileCreateObj
2021-05-30 03:21:45 +02:00
Create a new object in a PDF file.
.PP
.nf
pdfio_obj_t * pdfioFileCreateObj (
2021-05-30 03:21:45 +02:00
pdfio_file_t *pdf,
pdfio_dict_t *dict
);
.fi
2021-09-27 14:11:53 +02:00
.SS pdfioFileCreateOutput
Create a PDF file through an output callback.
.PP
.nf
pdfio_file_t * pdfioFileCreateOutput (
pdfio_output_cb_t output_cb,
2024-06-24 17:51:50 +02:00
void *output_cbdata,
2021-09-27 14:11:53 +02:00
const char *version,
pdfio_rect_t *media_box,
pdfio_rect_t *crop_box,
pdfio_error_cb_t error_cb,
2024-06-24 17:51:50 +02:00
void *error_cbdata
2021-09-27 14:11:53 +02:00
);
.fi
.PP
This function creates a new PDF file that is streamed though an output
2024-06-24 17:51:50 +02:00
callback. The "output_cb" and "output_cbdata" arguments specify the output
callback and its data pointer which is called whenever data needs to be
2021-09-27 14:11:53 +02:00
written:
.PP
.nf
ssize_t
2024-06-24 17:51:50 +02:00
output_cb(void *output_cbdata, const void *buffer, size_t bytes)
2021-09-27 14:11:53 +02:00
{
// Write buffer to output and return the number of bytes written
2021-09-27 14:11:53 +02:00
}
.fi
2021-09-27 14:11:53 +02:00
The "version" argument specifies the PDF version number for the file or
\fBNULL\fR for the default ("2.0").
.PP
The "media_box" and "crop_box" arguments specify the default MediaBox and
CropBox for pages in the PDF file - if \fBNULL\fR then a default "Universal" size
of 8.27x11in (the intersection of US Letter and ISO A4) is used.
.PP
2024-06-24 17:51:50 +02:00
The "error_cb" and "error_cbdata" arguments specify an error handler callback
and its data pointer - if \fBNULL\fR the default error handler is used that
writes error messages to \fBstderr\fR.
2021-09-27 14:11:53 +02:00
.PP
.IP 5
\fINote\fR: Files created using this API are slightly larger than those
.IP 5
created using the \fIpdfioFileCreate\fR function since stream lengths are
.IP 5
stored as indirect object references.
2021-05-30 03:21:45 +02:00
.SS pdfioFileCreatePage
Create a page in a PDF file.
.PP
.nf
pdfio_stream_t * pdfioFileCreatePage (
pdfio_file_t *pdf,
pdfio_dict_t *dict
);
.fi
.SS pdfioFileCreateStringObj
Create a new object in a PDF file containing a string.
.PP
.nf
pdfio_obj_t * pdfioFileCreateStringObj (
pdfio_file_t *pdf,
const char *string
);
.fi
.PP
This function creates a new object with a string value in a PDF file.
You must call \fIpdfioObjClose\fR to write the object to the file.
.SS pdfioFileCreateTemporary
.PP
.nf
pdfio_file_t * pdfioFileCreateTemporary (
char *buffer,
size_t bufsize,
const char *version,
pdfio_rect_t *media_box,
pdfio_rect_t *crop_box,
pdfio_error_cb_t error_cb,
2024-06-24 17:51:50 +02:00
void *error_cbdata
);
.fi
.SS pdfioFileFindObj
2021-05-30 03:21:45 +02:00
Find an object using its object number.
.PP
.nf
pdfio_obj_t * pdfioFileFindObj (
2021-05-30 03:21:45 +02:00
pdfio_file_t *pdf,
size_t number
);
.fi
.PP
This differs from \fIpdfioFileGetObj\fR which takes an index into the
2021-05-30 03:21:45 +02:00
list of objects while this function takes the object number.
.SS pdfioFileGetAuthor
Get the author for a PDF file.
.PP
.nf
const char * pdfioFileGetAuthor (
pdfio_file_t *pdf
);
.fi
2024-06-24 17:51:50 +02:00
.SS pdfioFileGetCatalog
Get the document catalog dictionary.
.PP
.nf
pdfio_dict_t * pdfioFileGetCatalog (
pdfio_file_t *pdf
);
.fi
.PP
.SS pdfioFileGetCreationDate
Get the creation date for a PDF file.
.PP
.nf
time_t pdfioFileGetCreationDate (
pdfio_file_t *pdf
);
.fi
.SS pdfioFileGetCreator
Get the creator string for a PDF file.
.PP
.nf
const char * pdfioFileGetCreator (
pdfio_file_t *pdf
);
.fi
2021-05-30 03:21:45 +02:00
.SS pdfioFileGetID
Get the PDF file's ID strings.
.PP
.nf
pdfio_array_t * pdfioFileGetID (
pdfio_file_t *pdf
);
.fi
.SS pdfioFileGetKeywords
Get the keywords for a PDF file.
.PP
.nf
const char * pdfioFileGetKeywords (
pdfio_file_t *pdf
);
.fi
2021-05-30 03:21:45 +02:00
.SS pdfioFileGetName
Get a PDF's filename.
.PP
.nf
const char * pdfioFileGetName (
pdfio_file_t *pdf
);
.fi
.SS pdfioFileGetNumObjs
2021-05-30 03:21:45 +02:00
Get the number of objects in a PDF file.
.PP
.nf
size_t pdfioFileGetNumObjs (
2021-05-30 03:21:45 +02:00
pdfio_file_t *pdf
);
.fi
.SS pdfioFileGetNumPages
Get the number of pages in a PDF file.
.PP
.nf
size_t pdfioFileGetNumPages (
pdfio_file_t *pdf
);
.fi
.SS pdfioFileGetObj
2021-05-30 03:21:45 +02:00
Get an object from a PDF file.
.PP
.nf
pdfio_obj_t * pdfioFileGetObj (
2021-05-30 03:21:45 +02:00
pdfio_file_t *pdf,
size_t n
);
.fi
.SS pdfioFileGetPage
Get a page object from a PDF file.
.PP
.nf
pdfio_obj_t * pdfioFileGetPage (
pdfio_file_t *pdf,
size_t n
);
.fi
2021-10-26 04:00:25 +02:00
.SS pdfioFileGetPermissions
Get the access permissions of a PDF file.
.PP
.nf
pdfio_permission_t pdfioFileGetPermissions (
pdfio_file_t *pdf,
pdfio_encryption_t *encryption
);
.fi
.PP
This function returns the access permissions of a PDF file and (optionally)
the type of encryption that has been used.
.SS pdfioFileGetProducer
Get the producer string for a PDF file.
.PP
.nf
const char * pdfioFileGetProducer (
pdfio_file_t *pdf
);
.fi
.SS pdfioFileGetSubject
Get the subject for a PDF file.
.PP
.nf
const char * pdfioFileGetSubject (
pdfio_file_t *pdf
);
.fi
.SS pdfioFileGetTitle
Get the title for a PDF file.
.PP
.nf
const char * pdfioFileGetTitle (
pdfio_file_t *pdf
);
.fi
2021-05-30 03:21:45 +02:00
.SS pdfioFileGetVersion
Get the PDF version number for a PDF file.
.PP
.nf
const char * pdfioFileGetVersion (
pdfio_file_t *pdf
);
.fi
.SS pdfioFileOpen
Open a PDF file for reading.
.PP
.nf
pdfio_file_t * pdfioFileOpen (
const char *filename,
pdfio_password_cb_t password_cb,
2024-06-24 17:51:50 +02:00
void *password_cbdata,
2021-05-30 03:21:45 +02:00
pdfio_error_cb_t error_cb,
2024-06-24 17:51:50 +02:00
void *error_cbdata
2021-05-30 03:21:45 +02:00
);
.fi
2021-09-27 14:11:53 +02:00
.PP
This function opens an existing PDF file. The "filename" argument specifies
the name of the PDF file to create.
.PP
2024-06-24 17:51:50 +02:00
The "password_cb" and "password_cbdata" arguments specify a password callback
and its data pointer for PDF files that use one of the standard Adobe
"security" handlers. The callback returns a password string or \fBNULL\fR to
cancel the open. If \fBNULL\fR is specified for the callback function and the
PDF file requires a password, the open will always fail.
.PP
2024-06-24 17:51:50 +02:00
The "error_cb" and "error_cbdata" arguments specify an error handler callback
and its data pointer - if \fBNULL\fR the default error handler is used that
writes error messages to \fBstderr\fR.
.SS pdfioFileSetAuthor
Set the author for a PDF file.
.PP
.nf
void pdfioFileSetAuthor (
pdfio_file_t *pdf,
const char *value
);
.fi
.SS pdfioFileSetCreationDate
Set the creation date for a PDF file.
.PP
.nf
void pdfioFileSetCreationDate (
pdfio_file_t *pdf,
time_t value
);
.fi
.SS pdfioFileSetCreator
Set the creator string for a PDF file.
.PP
.nf
void pdfioFileSetCreator (
pdfio_file_t *pdf,
const char *value
);
.fi
.SS pdfioFileSetKeywords
Set the keywords string for a PDF file.
.PP
.nf
void pdfioFileSetKeywords (
pdfio_file_t *pdf,
const char *value
);
.fi
2021-10-26 04:00:25 +02:00
.SS pdfioFileSetPermissions
Set the PDF permissions, encryption mode, and passwords.
.PP
.nf
bool pdfioFileSetPermissions (
pdfio_file_t *pdf,
pdfio_permission_t permissions,
pdfio_encryption_t encryption,
const char *owner_password,
const char *user_password
);
.fi
.PP
This function sets the PDF usage permissions, encryption mode, and
passwords.
.PP
.IP 5
\fINote\fR: This function must be called before creating or copying any
.IP 5
objects. Due to fundamental limitations in the PDF format, PDF encryption
.IP 5
offers little protection from disclosure. Permissions are not enforced in
.IP 5
any meaningful way.
.SS pdfioFileSetSubject
Set the subject for a PDF file.
.PP
.nf
void pdfioFileSetSubject (
pdfio_file_t *pdf,
const char *value
);
.fi
.SS pdfioFileSetTitle
Set the title for a PDF file.
.PP
.nf
void pdfioFileSetTitle (
pdfio_file_t *pdf,
const char *value
);
.fi
.SS pdfioImageGetBytesPerLine
Get the number of bytes to read for each line.
.PP
.nf
size_t pdfioImageGetBytesPerLine (
pdfio_obj_t *obj
);
.fi
2021-05-30 03:21:45 +02:00
.SS pdfioImageGetHeight
Get the height of an image object.
.PP
.nf
double pdfioImageGetHeight (
pdfio_obj_t *obj
);
.fi
.SS pdfioImageGetWidth
Get the width of an image object.
.PP
.nf
double pdfioImageGetWidth (
pdfio_obj_t *obj
);
.fi
.SS pdfioObjClose
Close an object, writing any data as needed to the PDF
file.
2021-05-30 03:21:45 +02:00
.PP
.nf
bool pdfioObjClose (
pdfio_obj_t *obj
);
.fi
.SS pdfioObjCopy
Copy an object to another PDF file.
.PP
.nf
pdfio_obj_t * pdfioObjCopy (
pdfio_file_t *pdf,
pdfio_obj_t *srcobj
);
.fi
.SS pdfioObjCreateStream
Create an object (data) stream for writing.
.PP
.nf
pdfio_stream_t * pdfioObjCreateStream (
pdfio_obj_t *obj,
pdfio_filter_t filter
);
.fi
.SS pdfioObjGetArray
Get the array associated with an object.
.PP
.nf
pdfio_array_t * pdfioObjGetArray (
pdfio_obj_t *obj
);
.fi
.SS pdfioObjGetDict
Get the dictionary associated with an object.
.PP
.nf
pdfio_dict_t * pdfioObjGetDict (
pdfio_obj_t *obj
);
.fi
.SS pdfioObjGetGeneration
Get the object's generation number.
.PP
.nf
unsigned short pdfioObjGetGeneration (
pdfio_obj_t *obj
);
.fi
.SS pdfioObjGetLength
Get the length of the object's (data) stream.
.PP
.nf
size_t pdfioObjGetLength (
pdfio_obj_t *obj
);
.fi
2024-10-25 23:50:51 +02:00
.SS pdfioObjGetName
Get the name value associated with an object.
.PP
.nf
const char * pdfioObjGetName (
pdfio_obj_t *obj
);
.fi
2021-05-30 03:21:45 +02:00
.SS pdfioObjGetNumber
Get the object's number.
.PP
.nf
size_t pdfioObjGetNumber (
pdfio_obj_t *obj
);
.fi
.SS pdfioObjGetSubtype
Get an object's subtype.
.PP
.nf
const char * pdfioObjGetSubtype (
pdfio_obj_t *obj
);
.fi
.PP
This function returns an object's PDF subtype name, if any. Common subtype
names include:
.PP
.IP \(bu 5
"CIDFontType0": A CID Type0 font
.IP \(bu 5
"CIDFontType2": A CID TrueType font
.IP \(bu 5
"Image": An image or image mask
.IP \(bu 5
"Form": A fillable form
.IP \(bu 5
"OpenType": An OpenType font
.IP \(bu 5
"Type0": A composite font
.IP \(bu 5
"Type1": A PostScript Type1 font
.IP \(bu 5
"Type3": A PDF Type3 font
.IP \(bu 5
"TrueType": A TrueType font</li>
</ul>
2021-05-30 03:21:45 +02:00
.SS pdfioObjGetType
Get an object's type.
.PP
.nf
const char * pdfioObjGetType (
pdfio_obj_t *obj
);
.fi
.PP
This function returns an object's PDF type name, if any. Common type names
include:
.PP
.IP \(bu 5
"CMap": A character map for composite fonts
.IP \(bu 5
"Font": An embedded font (\fIpdfioObjGetSubtype\fR will tell you the
font format)
.IP \(bu 5
"FontDescriptor": A font descriptor
.IP \(bu 5
"Page": A (visible) page
.IP \(bu 5
"Pages": A page tree node
.IP \(bu 5
"Template": An invisible template page
.IP \(bu 5
"XObject": An image, image mask, or form (\fIpdfioObjGetSubtype\fR will
tell you which)</li>
</ul>
2021-05-30 03:21:45 +02:00
.SS pdfioObjOpenStream
Open an object's (data) stream for reading.
.PP
.nf
pdfio_stream_t * pdfioObjOpenStream (
pdfio_obj_t *obj,
bool decode
);
.fi
.SS pdfioPageCopy
Copy a page to a PDF file.
.PP
.nf
bool pdfioPageCopy (
pdfio_file_t *pdf,
pdfio_obj_t *srcpage
);
.fi
.SS pdfioPageDictAddColorSpace
Add a color space to the page dictionary.
2021-05-30 03:21:45 +02:00
.PP
.nf
bool pdfioPageDictAddColorSpace (
2021-05-30 03:21:45 +02:00
pdfio_dict_t *dict,
const char *name,
pdfio_array_t *data
2021-05-30 03:21:45 +02:00
);
.fi
.PP
This function adds a named color space to the page dictionary.
.PP
The names "DefaultCMYK", "DefaultGray", and "DefaultRGB" specify the default
device color space used for the page.
.PP
The "data" array contains a calibrated, indexed, or ICC-based color space
array that was created using the
\fIpdfioArrayCreateCalibratedColorFromMatrix\fR,
\fIpdfioArrayCreateCalibratedColorFromPrimaries\fR,
\fIpdfioArrayCreateICCBasedColor\fR, or
\fIpdfioArrayCreateIndexedColor\fR functions.
2021-05-30 03:21:45 +02:00
.SS pdfioPageDictAddFont
Add a font object to the page dictionary.
.PP
.nf
bool pdfioPageDictAddFont (
pdfio_dict_t *dict,
const char *name,
pdfio_obj_t *obj
);
.fi
.SS pdfioPageDictAddImage
Add an image object to the page dictionary.
.PP
.nf
bool pdfioPageDictAddImage (
pdfio_dict_t *dict,
const char *name,
pdfio_obj_t *obj
);
.fi
.SS pdfioPageGetNumStreams
Get the number of content streams for a page object.
.PP
.nf
size_t pdfioPageGetNumStreams (
pdfio_obj_t *page
);
.fi
.SS pdfioPageOpenStream
Open a content stream for a page.
.PP
.nf
pdfio_stream_t * pdfioPageOpenStream (
pdfio_obj_t *page,
size_t n,
bool decode
);
.fi
2021-05-30 03:21:45 +02:00
.SS pdfioStreamClose
Close a (data) stream in a PDF file.
.PP
.nf
bool pdfioStreamClose (
pdfio_stream_t *st
);
.fi
.SS pdfioStreamConsume
Consume bytes from the stream.
.PP
.nf
bool pdfioStreamConsume (
pdfio_stream_t *st,
size_t bytes
);
.fi
.SS pdfioStreamGetToken
Read a single PDF token from a stream.
.PP
.nf
bool pdfioStreamGetToken (
pdfio_stream_t *st,
char *buffer,
size_t bufsize
);
.fi
.PP
This function reads a single PDF token from a stream. Operator tokens,
boolean values, and numbers are returned as-is in the provided string buffer.
String values start with the opening parenthesis ('(') but have all escaping
resolved and the terminating parenthesis removed. Hexadecimal string values
start with the opening angle bracket ('<') and have all whitespace and the
terminating angle bracket removed.
2021-05-30 03:21:45 +02:00
.SS pdfioStreamPeek
Peek at data in a stream.
.PP
.nf
ssize_t pdfioStreamPeek (
pdfio_stream_t *st,
void *buffer,
size_t bytes
);
.fi
.SS pdfioStreamPrintf
Write a formatted string to a stream.
.PP
.nf
bool pdfioStreamPrintf (
pdfio_stream_t *st,
const char *format,
...
);
.fi
.SS pdfioStreamPutChar
Write a single character to a stream.
.PP
.nf
bool pdfioStreamPutChar (
pdfio_stream_t *st,
int ch
);
.fi
2021-05-30 03:21:45 +02:00
.SS pdfioStreamPuts
Write a literal string to a stream.
.PP
.nf
bool pdfioStreamPuts (
pdfio_stream_t *st,
const char *s
);
.fi
.SS pdfioStreamRead
Read data from a stream.
.PP
.nf
ssize_t pdfioStreamRead (
pdfio_stream_t *st,
void *buffer,
size_t bytes
);
.fi
.PP
This function reads data from a stream. When reading decoded image data
from a stream, you \fImust\fR read whole scanlines. The
\fIpdfioImageGetBytesPerLine\fR function can be used to determine the
proper read length.
2021-05-30 03:21:45 +02:00
.SS pdfioStreamWrite
Write data to a stream.
.PP
.nf
bool pdfioStreamWrite (
pdfio_stream_t *st,
const void *buffer,
size_t bytes
);
.fi
.SS pdfioStringCreate
Create a durable literal string.
.PP
.nf
char * pdfioStringCreate (
pdfio_file_t *pdf,
const char *s
);
.fi
.PP
This function creates a literal string associated with the PDF file
2021-06-07 23:06:13 +02:00
"pdf". The "s" string points to a nul-terminated C string.
2021-05-30 03:21:45 +02:00
.PP
\fBNULL\fR is returned on error, otherwise a \fBchar *\fR that is valid until
\fBpdfioFileClose\fR is called.
.SS pdfioStringCreatef
Create a durable formatted string.
.PP
.nf
char * pdfioStringCreatef (
pdfio_file_t *pdf,
const char *format,
...
);
.fi
.PP
This function creates a formatted string associated with the PDF file
2021-06-07 23:06:13 +02:00
"pdf". The "format" string contains \fBprintf\fR-style format characters.
2021-05-30 03:21:45 +02:00
.PP
\fBNULL\fR is returned on error, otherwise a \fBchar *\fR that is valid until
\fBpdfioFileClose\fR is called.
.SH STRUCTURES
.SS pdfio_rect_s
PDF rectangle
.PP
.nf
struct pdfio_rect_s
{
double x1;
double x2;
double y1;
double y2;
};
.fi
.SH TYPES
.SS pdfio_array_t
Array of PDF values
.PP
.nf
typedef struct _pdfio_array_s pdfio_array_t;
.fi
2021-08-30 17:22:35 +02:00
.SS pdfio_cs_t
Standard color spaces
.PP
.nf
typedef enum pdfio_cs_e pdfio_cs_t;
.fi
.SS pdfio_dict_cb_t
Dictionary iterator callback
.PP
.nf
typedef bool(*)(pdfio_dict_t *dict, const char *key, void *cb_data) pdfio_dict_cb_t;
.fi
2021-05-30 03:21:45 +02:00
.SS pdfio_dict_t
Key/value dictionary
.PP
.nf
typedef struct _pdfio_dict_s pdfio_dict_t;
.fi
2021-10-26 04:00:25 +02:00
.SS pdfio_encryption_t
PDF encryption modes
.PP
.nf
typedef enum pdfio_encryption_e pdfio_encryption_t;
.fi
2021-05-30 03:21:45 +02:00
.SS pdfio_error_cb_t
Error callback
.PP
.nf
typedef bool(*)(pdfio_file_t *pdf, const char *message, void *data) pdfio_error_cb_t;
.fi
.SS pdfio_file_t
PDF file
.PP
.nf
typedef struct _pdfio_file_s pdfio_file_t;
.fi
.SS pdfio_filter_t
Compression/decompression filters for streams
.PP
.nf
typedef enum pdfio_filter_e pdfio_filter_t;
.fi
2021-07-18 16:01:43 +02:00
.SS pdfio_linecap_t
Line capping modes
.PP
.nf
typedef enum pdfio_linecap_e pdfio_linecap_t;
.fi
.SS pdfio_linejoin_t
Line joining modes
.PP
.nf
typedef enum pdfio_linejoin_e pdfio_linejoin_t;
.fi
.SS pdfio_matrix_t[3][2]
Transform matrix
.PP
.nf
typedef double pdfio_matrix_t[3][2];
.fi
2021-05-30 03:21:45 +02:00
.SS pdfio_obj_t
Numbered object in PDF file
.PP
.nf
typedef struct _pdfio_obj_s pdfio_obj_t;
.fi
2021-09-27 14:11:53 +02:00
.SS pdfio_output_cb_t
Output callback for pdfioFileCreateOutput
.PP
.nf
typedef ssize_t(*)(void *ctx const void *data size_t datalen) pdfio_output_cb_t;
.fi
.SS pdfio_password_cb_t
Password callback for pdfioFileOpen
.PP
.nf
typedef const char *(*)(void *data const char *filename) pdfio_password_cb_t;
.fi
2021-10-26 04:00:25 +02:00
.SS pdfio_permission_t
PDF permission bitfield
.PP
.nf
typedef int pdfio_permission_t;
.fi
2021-05-30 03:21:45 +02:00
.SS pdfio_rect_t
PDF rectangle
.PP
.nf
typedef struct pdfio_rect_s pdfio_rect_t;
.fi
.SS pdfio_stream_t
Object data stream in PDF file
.PP
.nf
typedef struct _pdfio_stream_s pdfio_stream_t;
.fi
2021-07-18 16:01:43 +02:00
.SS pdfio_textrendering_t
Text rendering modes
.PP
.nf
typedef enum pdfio_textrendering_e pdfio_textrendering_t;
.fi
2021-05-30 03:21:45 +02:00
.SS pdfio_valtype_t
PDF value types
.PP
.nf
typedef enum pdfio_valtype_e pdfio_valtype_t;
.fi
.SH AUTHOR
.PP
Michael R Sweet
.SH COPYRIGHT
.PP
Copyright (c) 2021-2024 by Michael R Sweet