Compare commits

..

No commits in common. "2ea99597cc2c79521af2399f63e91ef0604ec52f" and "9c04d1dc209cb081799f4c787ebe712b2d93d460" have entirely different histories.

13 changed files with 29 additions and 679 deletions

View File

@ -2,16 +2,6 @@ Changes in PDFio
================
v1.4.0 - YYYY-MM-DD
-------------------
- Added new `pdfioDictGetKey` and `pdfioDictGetNumPairs` APIs (Issue #63)
- Added new `pdfioArrayRemove` and `pdfioDictClear` APIs (Issue #74)
- Added new `pdfioFileCreateNameObj` and `pdfioObjGetName` APIs for creating and
getting name object values (Issue #76)
- Updated documentation (Issue #78)
v1.3.2 - 2024-08-15
-------------------

24
configure vendored
View File

@ -1,6 +1,6 @@
#! /bin/sh
# Guess values for system-dependent variables and create Makefiles.
# Generated by GNU Autoconf 2.71 for pdfio 1.4.0.
# Generated by GNU Autoconf 2.71 for pdfio 1.3.2.
#
# Report bugs to <https://github.com/michaelrsweet/pdfio/issues>.
#
@ -610,8 +610,8 @@ MAKEFLAGS=
# Identity of this package.
PACKAGE_NAME='pdfio'
PACKAGE_TARNAME='pdfio'
PACKAGE_VERSION='1.4.0'
PACKAGE_STRING='pdfio 1.4.0'
PACKAGE_VERSION='1.3.2'
PACKAGE_STRING='pdfio 1.3.2'
PACKAGE_BUGREPORT='https://github.com/michaelrsweet/pdfio/issues'
PACKAGE_URL='https://www.msweet.org/pdfio'
@ -1293,7 +1293,7 @@ if test "$ac_init_help" = "long"; then
# Omit some internal or obsolete options to make the list less imposing.
# This message is too long to be a string in the A/UX 3.1 sh.
cat <<_ACEOF
\`configure' configures pdfio 1.4.0 to adapt to many kinds of systems.
\`configure' configures pdfio 1.3.2 to adapt to many kinds of systems.
Usage: $0 [OPTION]... [VAR=VALUE]...
@ -1359,7 +1359,7 @@ fi
if test -n "$ac_init_help"; then
case $ac_init_help in
short | recursive ) echo "Configuration of pdfio 1.4.0:";;
short | recursive ) echo "Configuration of pdfio 1.3.2:";;
esac
cat <<\_ACEOF
@ -1456,7 +1456,7 @@ fi
test -n "$ac_init_help" && exit $ac_status
if $ac_init_version; then
cat <<\_ACEOF
pdfio configure 1.4.0
pdfio configure 1.3.2
generated by GNU Autoconf 2.71
Copyright (C) 2021 Free Software Foundation, Inc.
@ -1612,7 +1612,7 @@ cat >config.log <<_ACEOF
This file contains any messages produced by compilers while
running configure, to aid debugging if configure makes a mistake.
It was created by pdfio $as_me 1.4.0, which was
It was created by pdfio $as_me 1.3.2, which was
generated by GNU Autoconf 2.71. Invocation command line was
$ $0$ac_configure_args_raw
@ -2368,9 +2368,9 @@ ac_compiler_gnu=$ac_cv_c_compiler_gnu
PDFIO_VERSION="1.4.0"
PDFIO_VERSION_MAJOR="`echo 1.4.0 | awk -F. '{print $1}'`"
PDFIO_VERSION_MINOR="`echo 1.4.0 | awk -F. '{printf("%d\n",$2);}'`"
PDFIO_VERSION="1.3.2"
PDFIO_VERSION_MAJOR="`echo 1.3.2 | awk -F. '{print $1}'`"
PDFIO_VERSION_MINOR="`echo 1.3.2 | awk -F. '{printf("%d\n",$2);}'`"
@ -4935,7 +4935,7 @@ cat >>$CONFIG_STATUS <<\_ACEOF || ac_write_fail=1
# report actual input values of CONFIG_FILES etc. instead of their
# values after options handling.
ac_log="
This file was extended by pdfio $as_me 1.4.0, which was
This file was extended by pdfio $as_me 1.3.2, which was
generated by GNU Autoconf 2.71. Invocation command line was
CONFIG_FILES = $CONFIG_FILES
@ -4991,7 +4991,7 @@ ac_cs_config_escaped=`printf "%s\n" "$ac_cs_config" | sed "s/^ //; s/'/'\\\\\\\\
cat >>$CONFIG_STATUS <<_ACEOF || ac_write_fail=1
ac_cs_config='$ac_cs_config_escaped'
ac_cs_version="\\
pdfio config.status 1.4.0
pdfio config.status 1.3.2
configured by $0, generated by GNU Autoconf 2.71,
with options \\"\$ac_cs_config\\"

View File

@ -21,7 +21,7 @@ AC_PREREQ([2.70])
dnl Package name and version...
AC_INIT([pdfio], [1.4.0], [https://github.com/michaelrsweet/pdfio/issues], [pdfio], [https://www.msweet.org/pdfio])
AC_INIT([pdfio], [1.3.2], [https://github.com/michaelrsweet/pdfio/issues], [pdfio], [https://www.msweet.org/pdfio])
PDFIO_VERSION="AC_PACKAGE_VERSION"
PDFIO_VERSION_MAJOR="`echo AC_PACKAGE_VERSION | awk -F. '{print $1}'`"

View File

@ -1,4 +1,4 @@
.TH pdfio 3 "pdf read/write library" "2024-10-25" "pdf read/write library"
.TH pdfio 3 "pdf read/write library" "2024-10-09" "pdf read/write library"
.SH NAME
pdfio \- pdf read/write library
.SH Introduction
@ -138,121 +138,6 @@ PDFio also provides PDF content helper functions for producing PDF content that
#include <pdfio\-content.h>
.fi
.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
.fi
.PP
> 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
.IP \(bu 5
.PP
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
.PP
> 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
.nf
.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
.fi
.PP
> endobj
.nf
.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
.fi
.PP
> startxref % startxref keyword 459 % Byte offset of cross\-reference table %%EOF % End\-of\-file marker
.nf
.fi
.SH API Overview
.PP
PDFio exposes several types:
@ -1602,15 +1487,6 @@ pdfio_valtype_t pdfioArrayGetType (
size_t n
);
.fi
.SS pdfioArrayRemove
Remove an array entry.
.PP
.nf
bool pdfioArrayRemove (
pdfio_array_t *a,
size_t n
);
.fi
.SS pdfioContentClip
Clip output to the current path.
.PP
@ -2191,15 +2067,6 @@ bool pdfioContentTextShowf (
...
);
.fi
.SS pdfioDictClear
Remove a key/value pair from a dictionary.
.PP
.nf
bool pdfioDictClear (
pdfio_dict_t *dict,
const char *key
);
.fi
.SS pdfioDictCopy
Copy a dictionary to a PDF file.
.PP
@ -2263,15 +2130,6 @@ pdfio_dict_t * pdfioDictGetDict (
const char *key
);
.fi
.SS pdfioDictGetKey
Get the key for the specified pair.
.PP
.nf
const char * pdfioDictGetKey (
pdfio_dict_t *dict,
size_t n
);
.fi
.SS pdfioDictGetName
Get a key name value from a dictionary.
.PP
@ -2281,14 +2139,6 @@ const char * pdfioDictGetName (
const char *key
);
.fi
.SS pdfioDictGetNumPairs
Get the number of key/value pairs in a dictionary.
.PP
.nf
size_t pdfioDictGetNumPairs (
pdfio_dict_t *dict
);
.fi
.SS pdfioDictGetNumber
Get a key number value from a dictionary.
.PP
@ -2650,18 +2500,6 @@ Note: Currently PNG support is limited to grayscale, RGB, or indexed files
without interlacing or alpha. Transparency (masking) based on color/index
.IP 5
is supported.
.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
@ -3098,14 +2936,6 @@ size_t pdfioObjGetLength (
pdfio_obj_t *obj
);
.fi
.SS pdfioObjGetName
Get the name value associated with an object.
.PP
.nf
const char * pdfioObjGetName (
pdfio_obj_t *obj
);
.fi
.SS pdfioObjGetNumber
Get the object's number.
.PP

View File

@ -1,13 +1,13 @@
<!DOCTYPE html>
<html lang="en-US">
<head>
<title>PDFio Programming Manual v1.4.0</title>
<title>PDFio Programming Manual v1.3.2</title>
<meta http-equiv="Content-Type" content="text/html;charset=utf-8">
<meta name="generator" content="codedoc v3.7">
<meta name="author" content="Michael R Sweet">
<meta name="language" content="en-US">
<meta name="copyright" content="Copyright © 2021-2024 by Michael R Sweet">
<meta name="version" content="1.4.0">
<meta name="version" content="1.3.2">
<style type="text/css"><!--
body {
background: white;
@ -251,7 +251,7 @@ span.string {
<body>
<div class="header">
<p><img class="title" src="pdfio-512.png"></p>
<h1 class="title">PDFio Programming Manual v1.4.0</h1>
<h1 class="title">PDFio Programming Manual v1.3.2</h1>
<p>Michael R Sweet</p>
<p>Copyright © 2021-2024 by Michael R Sweet</p>
</div>
@ -265,7 +265,6 @@ span.string {
<li><a href="#xcode-project">Xcode Project</a></li>
<li><a href="#detecting-pdfio">Detecting PDFio</a></li>
<li><a href="#header-files">Header Files</a></li>
<li><a href="#understanding-pdf-files">Understanding PDF Files</a></li>
</ul></li>
<li><a href="#api-overview">API Overview</a><ul class="subcontents">
<li><a href="#reading-pdf-files">Reading PDF Files</a></li>
@ -306,7 +305,6 @@ span.string {
<li><a href="#pdfioArrayGetSize">pdfioArrayGetSize</a></li>
<li><a href="#pdfioArrayGetString">pdfioArrayGetString</a></li>
<li><a href="#pdfioArrayGetType">pdfioArrayGetType</a></li>
<li><a href="#pdfioArrayRemove">pdfioArrayRemove</a></li>
<li><a href="#pdfioContentClip">pdfioContentClip</a></li>
<li><a href="#pdfioContentDrawImage">pdfioContentDrawImage</a></li>
<li><a href="#pdfioContentFill">pdfioContentFill</a></li>
@ -363,7 +361,6 @@ span.string {
<li><a href="#pdfioContentTextShow">pdfioContentTextShow</a></li>
<li><a href="#pdfioContentTextShowJustified">pdfioContentTextShowJustified</a></li>
<li><a href="#pdfioContentTextShowf">pdfioContentTextShowf</a></li>
<li><a href="#pdfioDictClear">pdfioDictClear</a></li>
<li><a href="#pdfioDictCopy">pdfioDictCopy</a></li>
<li><a href="#pdfioDictCreate">pdfioDictCreate</a></li>
<li><a href="#pdfioDictGetArray">pdfioDictGetArray</a></li>
@ -371,9 +368,7 @@ span.string {
<li><a href="#pdfioDictGetBoolean">pdfioDictGetBoolean</a></li>
<li><a href="#pdfioDictGetDate">pdfioDictGetDate</a></li>
<li><a href="#pdfioDictGetDict">pdfioDictGetDict</a></li>
<li><a href="#pdfioDictGetKey">pdfioDictGetKey</a></li>
<li><a href="#pdfioDictGetName">pdfioDictGetName</a></li>
<li><a href="#pdfioDictGetNumPairs">pdfioDictGetNumPairs</a></li>
<li><a href="#pdfioDictGetNumber">pdfioDictGetNumber</a></li>
<li><a href="#pdfioDictGetObj">pdfioDictGetObj</a></li>
<li><a href="#pdfioDictGetRect">pdfioDictGetRect</a></li>
@ -400,7 +395,6 @@ span.string {
<li><a href="#pdfioFileCreateICCObjFromFile">pdfioFileCreateICCObjFromFile</a></li>
<li><a href="#pdfioFileCreateImageObjFromData">pdfioFileCreateImageObjFromData</a></li>
<li><a href="#pdfioFileCreateImageObjFromFile">pdfioFileCreateImageObjFromFile</a></li>
<li><a href="#pdfioFileCreateNameObj">pdfioFileCreateNameObj</a></li>
<li><a href="#pdfioFileCreateNumberObj">pdfioFileCreateNumberObj</a></li>
<li><a href="#pdfioFileCreateObj">pdfioFileCreateObj</a></li>
<li><a href="#pdfioFileCreateOutput">pdfioFileCreateOutput</a></li>
@ -442,7 +436,6 @@ span.string {
<li><a href="#pdfioObjGetDict">pdfioObjGetDict</a></li>
<li><a href="#pdfioObjGetGeneration">pdfioObjGetGeneration</a></li>
<li><a href="#pdfioObjGetLength">pdfioObjGetLength</a></li>
<li><a href="#pdfioObjGetName">pdfioObjGetName</a></li>
<li><a href="#pdfioObjGetNumber">pdfioObjGetNumber</a></li>
<li><a href="#pdfioObjGetSubtype">pdfioObjGetSubtype</a></li>
<li><a href="#pdfioObjGetType">pdfioObjGetType</a></li>
@ -579,104 +572,6 @@ LIBS += `pkg-config --libs pdfio`
<p>PDFio also provides <a href="#pdf-content-helper-functions">PDF content helper functions</a> for producing PDF content that are defined in a separate header file:</p>
<pre><code class="language-c"><span class="directive">#include &lt;pdfio-content.h&gt;</span>
</code></pre>
<h3 class="title" id="understanding-pdf-files">Understanding PDF Files</h3>
<p>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 &quot;Hello, World!&quot; on one page:</p>
<pre><code>%PDF-1.0 % Header starts here
%âãÏÓ
1 0 obj % Body starts here
&lt;&lt;
/Kids [2 0 R]
/Count 1
/Type /Pages
</code></pre>
<blockquote>
<p>&gt; endobj 2 0 obj <a href="<
/Rotate 0
/Parent 1 0 R
/Resources 3 0 R
/MediaBox [0 0 612 792]
/Contents [4 0 R]/Type /Page
">&lt;
/Rotate 0
/Parent 1 0 R
/Resources 3 0 R
/MediaBox [0 0 612 792]
/Contents [4 0 R]/Type /Page
</a> endobj 3 0 obj <a href="<
/Font
<<
/F0
<<
/BaseFont /Times-Italic
/Subtype /Type1
/Type /Font
">&lt;
/Font
&lt;&lt;
/F0
&lt;&lt;
/BaseFont /Times-Italic
/Subtype /Type1
/Type /Font
</a> &gt; &gt; endobj 4 0 obj <a href="<
/Length 65
">&lt;
/Length 65
</a> stream</p>
</blockquote>
<ol>
<li><p>0. 0. 1. 50. 700. cm BT /F0 36. Tf (Hello, World!) Tj ET endstream endobj 5 0 obj &lt;&lt; /Pages 1 0 R /Type /Catalog</p>
</li>
</ol>
<blockquote>
<p>&gt; 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 &lt;&lt; /Root 5 0 R /Size 6 &gt; startxref 459 %%EOF</p>
<pre><code></code></pre>
</blockquote>
<h4 id="header">Header</h4>
<p>The header is the first line of a PDF file that specifies the version of the PDF format that has been used, for example <code>%PDF-1.0</code>.</p>
<p>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:</p>
<pre><code>%âãÏÓ
</code></pre>
<p>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:</p>
<pre><code>%PDF-1.0
%âãÏÓ
</code></pre>
<h4 id="body">Body</h4>
<p>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:</p>
<pre><code>1 0 obj
&lt;&lt;
/Kids [2 0 R]
/Count 1
/Type /Pages
</code></pre>
<blockquote>
<p>&gt; endobj</p>
<pre><code></code></pre>
</blockquote>
<p>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 <code>1 0 obj</code> and trailing <code>endobj</code> lines. In this case, the content is the dictionary <code>&lt;&lt;/Kids [2 0 R] /Count 1 /Type /Pages&gt;&gt;</code>.</p>
<h4 id="cross-reference-table">Cross-Reference Table</h4>
<p>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.</p>
<p>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:</p>
<pre><code>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
</code></pre>
<h4 id="trailer">Trailer</h4>
<p>The first line of the trailer is just the <code>trailer</code> keyword. This is followed by the trailer dictionary which contains at least the <code>/Size</code> entry specifying the number of entries in the cross-reference table and the <code>/Root</code> entry which references the object for the document catalog which is the root element of the graph of objects in the body.</p>
<p>There follows a line with just the <code>startxref</code> 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 <code>%%EOF</code> which signals the end of the PDF file.</p>
<pre><code>trailer % Trailer keyword
&lt;&lt; % The trailer dictinonary
/Root 5 0 R
/Size 6
</code></pre>
<blockquote>
<p>&gt; startxref % startxref keyword 459 % Byte offset of cross-reference table %%EOF % End-of-file marker</p>
<pre><code></code></pre>
</blockquote>
<h2 class="title" id="api-overview">API Overview</h2>
<p>PDFio exposes several types:</p>
<ul>
@ -1607,19 +1502,6 @@ size_t pdfioArrayGetSize(<a href="#pdfio_array_t">pdfio_array_t</a> *a);</p>
</tbody></table>
<h4 class="returnvalue">Return Value</h4>
<p class="description">Value type</p>
<h3 class="function"><a id="pdfioArrayRemove">pdfioArrayRemove</a></h3>
<p class="description">Remove an array entry.</p>
<p class="code">
<span class="reserved">bool</span> pdfioArrayRemove(<a href="#pdfio_array_t">pdfio_array_t</a> *a, size_t n);</p>
<h4 class="parameters">Parameters</h4>
<table class="list"><tbody>
<tr><th>a</th>
<td class="description">Array</td></tr>
<tr><th>n</th>
<td class="description">Index</td></tr>
</tbody></table>
<h4 class="returnvalue">Return Value</h4>
<p class="description"><code>true</code> on success, <code>false</code> otherwise</p>
<h3 class="function"><a id="pdfioContentClip">pdfioContentClip</a></h3>
<p class="description">Clip output to the current path.</p>
<p class="code">
@ -2474,19 +2356,6 @@ argument specifies an array of UTF-8 encoded strings.</p>
<p class="discussion">This function shows some formatted text in a PDF content stream. The
&quot;unicode&quot; argument specifies that the current font maps to full Unicode.
The &quot;format&quot; argument specifies a UTF-8 encoded <code>printf</code>-style format string.</p>
<h3 class="function"><a id="pdfioDictClear">pdfioDictClear</a></h3>
<p class="description">Remove a key/value pair from a dictionary.</p>
<p class="code">
<span class="reserved">bool</span> pdfioDictClear(<a href="#pdfio_dict_t">pdfio_dict_t</a> *dict, <span class="reserved">const</span> <span class="reserved">char</span> *key);</p>
<h4 class="parameters">Parameters</h4>
<table class="list"><tbody>
<tr><th>dict</th>
<td class="description">Dictionary</td></tr>
<tr><th>key</th>
<td class="description">Key</td></tr>
</tbody></table>
<h4 class="returnvalue">Return Value</h4>
<p class="description"><code>true</code> if cleared, <code>false</code> otherwise</p>
<h3 class="function"><a id="pdfioDictCopy">pdfioDictCopy</a></h3>
<p class="description">Copy a dictionary to a PDF file.</p>
<p class="code">
@ -2578,19 +2447,6 @@ time_t pdfioDictGetDate(<a href="#pdfio_dict_t">pdfio_dict_t</a> *dict, <span cl
</tbody></table>
<h4 class="returnvalue">Return Value</h4>
<p class="description">Value</p>
<h3 class="function"><a id="pdfioDictGetKey">pdfioDictGetKey</a></h3>
<p class="description">Get the key for the specified pair.</p>
<p class="code">
<span class="reserved">const</span> <span class="reserved">char</span> *pdfioDictGetKey(<a href="#pdfio_dict_t">pdfio_dict_t</a> *dict, size_t n);</p>
<h4 class="parameters">Parameters</h4>
<table class="list"><tbody>
<tr><th>dict</th>
<td class="description">Dictionary</td></tr>
<tr><th>n</th>
<td class="description">Pair index (<code>0</code>-based)</td></tr>
</tbody></table>
<h4 class="returnvalue">Return Value</h4>
<p class="description">Key for specified pair</p>
<h3 class="function"><a id="pdfioDictGetName">pdfioDictGetName</a></h3>
<p class="description">Get a key name value from a dictionary.</p>
<p class="code">
@ -2604,17 +2460,6 @@ time_t pdfioDictGetDate(<a href="#pdfio_dict_t">pdfio_dict_t</a> *dict, <span cl
</tbody></table>
<h4 class="returnvalue">Return Value</h4>
<p class="description">Value</p>
<h3 class="function"><a id="pdfioDictGetNumPairs">pdfioDictGetNumPairs</a></h3>
<p class="description">Get the number of key/value pairs in a dictionary.</p>
<p class="code">
size_t pdfioDictGetNumPairs(<a href="#pdfio_dict_t">pdfio_dict_t</a> *dict);</p>
<h4 class="parameters">Parameters</h4>
<table class="list"><tbody>
<tr><th>dict</th>
<td class="description">Dictionary</td></tr>
</tbody></table>
<h4 class="returnvalue">Return Value</h4>
<p class="description">Number of pairs</p>
<h3 class="function"><a id="pdfioDictGetNumber">pdfioDictGetNumber</a></h3>
<p class="description">Get a key number value from a dictionary.</p>
<p class="code">
@ -3102,22 +2947,6 @@ image on the page.<br>
Note: Currently PNG support is limited to grayscale, RGB, or indexed files
without interlacing or alpha. Transparency (masking) based on color/index
is supported.</blockquote>
<h3 class="function"><a id="pdfioFileCreateNameObj">pdfioFileCreateNameObj</a></h3>
<p class="description">Create a new object in a PDF file containing a name.</p>
<p class="code">
<a href="#pdfio_obj_t">pdfio_obj_t</a> *pdfioFileCreateNameObj(<a href="#pdfio_file_t">pdfio_file_t</a> *pdf, <span class="reserved">const</span> <span class="reserved">char</span> *name);</p>
<h4 class="parameters">Parameters</h4>
<table class="list"><tbody>
<tr><th>pdf</th>
<td class="description">PDF file</td></tr>
<tr><th>name</th>
<td class="description">Name value</td></tr>
</tbody></table>
<h4 class="returnvalue">Return Value</h4>
<p class="description">New object</p>
<h4 class="discussion">Discussion</h4>
<p class="discussion">This function creates a new object with a name value in a PDF file.
You must call <a href="#pdfioObjClose"><code>pdfioObjClose</code></a> to write the object to the file.</p>
<h3 class="function"><a id="pdfioFileCreateNumberObj">pdfioFileCreateNumberObj</a></h3>
<p class="description">Create a new object in a PDF file containing a number.</p>
<p class="code">
@ -3699,17 +3528,6 @@ size_t pdfioObjGetLength(<a href="#pdfio_obj_t">pdfio_obj_t</a> *obj);</p>
</tbody></table>
<h4 class="returnvalue">Return Value</h4>
<p class="description">Length in bytes or <code>0</code> for none</p>
<h3 class="function"><a id="pdfioObjGetName">pdfioObjGetName</a></h3>
<p class="description">Get the name value associated with an object.</p>
<p class="code">
<span class="reserved">const</span> <span class="reserved">char</span> *pdfioObjGetName(<a href="#pdfio_obj_t">pdfio_obj_t</a> *obj);</p>
<h4 class="parameters">Parameters</h4>
<table class="list"><tbody>
<tr><th>obj</th>
<td class="description">Object</td></tr>
</tbody></table>
<h4 class="returnvalue">Return Value</h4>
<p class="description">Dictionary or <code>NULL</code> on error</p>
<h3 class="function"><a id="pdfioObjGetNumber">pdfioObjGetNumber</a></h3>
<p class="description">Get the object's number.</p>
<p class="code">

View File

@ -120,182 +120,6 @@ that are defined in a separate header file:
```
Understanding PDF Files
-----------------------
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:
```
%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
```
### Header
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`.
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:
```
%âãÏÓ
```
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:
```
%PDF-1.0
%âãÏÓ
```
### Body
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:
```
1 0 obj
<<
/Kids [2 0 R]
/Count 1
/Type /Pages
>>
endobj
```
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>>`.
### Cross-Reference Table
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.
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:
```
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
```
### Trailer
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.
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.
```
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
```
API Overview
============
@ -308,7 +132,6 @@ PDFio exposes several types:
- `pdfio_stream_t`: An object stream
Reading PDF Files
-----------------

View File

@ -1,7 +1,7 @@
//
// PDF array functions for PDFio.
//
// Copyright © 2021-2024 by Michael R Sweet.
// Copyright © 2021 by Michael R Sweet.
//
// Licensed under Apache License v2.0. See the file "LICENSE" for more
// information.
@ -637,28 +637,6 @@ _pdfioArrayRead(pdfio_file_t *pdf, // I - PDF file
}
//
// 'pdfioArrayRemove()' - Remove an array entry.
//
bool // O - `true` on success, `false` otherwise
pdfioArrayRemove(pdfio_array_t *a, // I - Array
size_t n) // I - Index
{
if (!a || n >= a->num_values)
return (false);
if (a->values[n].type == PDFIO_VALTYPE_BINARY)
free(a->values[n].value.binary.data);
a->num_values --;
if (n < a->num_values)
memmove(a->values + n, a->values + n + 1, (a->num_values - n) * sizeof(_pdfio_value_t));
return (true);
}
//
// '_pdfioArrayWrite()' - Write an array to a PDF file.
//

View File

@ -1,7 +1,7 @@
//
// PDF dictionary functions for PDFio.
//
// Copyright © 2021-2024 by Michael R Sweet.
// Copyright © 2021-2023 by Michael R Sweet.
//
// Licensed under Apache License v2.0. See the file "LICENSE" for more
// information.
@ -18,22 +18,19 @@ static int compare_pairs(_pdfio_pair_t *a, _pdfio_pair_t *b);
//
// 'pdfioDictClear()' - Remove a key/value pair from a dictionary.
// '_pdfioDictClear()' - Remove a key/value pair from a dictionary.
//
bool // O - `true` if cleared, `false` otherwise
pdfioDictClear(pdfio_dict_t *dict, // I - Dictionary
const char *key) // I - Key
void
_pdfioDictClear(pdfio_dict_t *dict, // I - Dictionary
const char *key) // I - Key
{
size_t idx; // Index into pairs
_pdfio_pair_t *pair, // Current pair
pkey; // Search key
PDFIO_DEBUG("pdfioDictClear(dict=%p, key=\"%s\")\n", dict, key);
if (!dict || !key)
return (false);
PDFIO_DEBUG("_pdfioDictClear(dict=%p, key=\"%s\")\n", dict, key);
// See if the key is already set...
if (dict->num_pairs > 0)
@ -51,12 +48,8 @@ pdfioDictClear(pdfio_dict_t *dict, // I - Dictionary
if (idx < dict->num_pairs)
memmove(pair, pair + 1, (dict->num_pairs - idx) * sizeof(_pdfio_pair_t));
return (true);
}
}
return (false);
}
@ -342,18 +335,6 @@ pdfioDictGetDict(pdfio_dict_t *dict, // I - Dictionary
}
//
// 'pdfioDictGetKey()' - Get the key for the specified pair.
//
const char * // O - Key for specified pair
pdfioDictGetKey(pdfio_dict_t *dict, // I - Dictionary
size_t n) // I - Pair index (`0`-based)
{
return ((dict && n < dict->num_pairs) ? dict->pairs[n].key : NULL);
}
//
// 'pdfioDictGetName()' - Get a key name value from a dictionary.
//
@ -372,17 +353,6 @@ pdfioDictGetName(pdfio_dict_t *dict, // I - Dictionary
}
//
// 'pdfioDictGetNumPairs()' - Get the number of key/value pairs in a dictionary.
//
size_t // O - Number of pairs
pdfioDictGetNumPairs(pdfio_dict_t *dict)// I - Dictionary
{
return (dict ? dict->num_pairs : 0);
}
//
// 'pdfioDictGetNumber()' - Get a key number value from a dictionary.
//

View File

@ -244,35 +244,6 @@ pdfioFileCreateArrayObj(
}
//
// 'pdfioFileCreateNameObj()' - Create a new object in a PDF file containing a name.
//
// This function creates a new object with a name value in a PDF file.
// You must call @link pdfioObjClose@ to write the object to the file.
//
pdfio_obj_t * // O - New object
pdfioFileCreateNameObj(
pdfio_file_t *pdf, // I - PDF file
const char *name) // I - Name value
{
_pdfio_value_t value; // Object value
// Range check input...
if (!pdf || !name)
return (NULL);
value.type = PDFIO_VALTYPE_NAME;
value.value.name = pdfioStringCreate(pdf, name);
if (!value.value.name)
return (NULL);
return (_pdfioFileCreateObj(pdf, NULL, &value));
}
//
// 'pdfioFileCreateNumberObj()' - Create a new object in a PDF file containing a number.
//

View File

@ -99,7 +99,7 @@ pdfioObjCopy(pdfio_file_t *pdf, // I - PDF file
return (NULL);
if (dstobj->value.type == PDFIO_VALTYPE_DICT)
pdfioDictClear(dstobj->value.value.dict, "Length");
_pdfioDictClear(dstobj->value.value.dict, "Length");
if (srcobj->stream_offset)
{
@ -333,26 +333,6 @@ pdfioObjGetLength(pdfio_obj_t *obj) // I - Object
}
//
// 'pdfioObjGetName()' - Get the name value associated with an object.
//
const char * // O - Dictionary or `NULL` on error
pdfioObjGetName(pdfio_obj_t *obj) // I - Object
{
if (!obj)
return (NULL);
if (obj->value.type == PDFIO_VALTYPE_NONE)
_pdfioObjLoad(obj);
if (obj->value.type == PDFIO_VALTYPE_NAME)
return (obj->value.value.name);
else
return (NULL);
}
//
// 'pdfioObjGetNumber()' - Get the object's number.
//

View File

@ -353,6 +353,7 @@ extern void _pdfioCryptoSHA256Init(_pdfio_sha256_t *ctx) _PDFIO_INTERNAL;
extern void _pdfioCryptoSHA256Finish(_pdfio_sha256_t *ctx, uint8_t *Message_Digest) _PDFIO_INTERNAL;
extern bool _pdfioCryptoUnlock(pdfio_file_t *pdf, pdfio_password_cb_t password_cb, void *password_data) _PDFIO_INTERNAL;
extern void _pdfioDictClear(pdfio_dict_t *dict, const char *key) _PDFIO_INTERNAL;
extern bool _pdfioDictDecrypt(pdfio_file_t *pdf, pdfio_obj_t *obj, pdfio_dict_t *dict, size_t depth) _PDFIO_INTERNAL;
extern void _pdfioDictDebug(pdfio_dict_t *dict, FILE *fp) _PDFIO_INTERNAL;
extern void _pdfioDictDelete(pdfio_dict_t *dict) _PDFIO_INTERNAL;

View File

@ -23,7 +23,7 @@ extern "C" {
// Version number...
//
# define PDFIO_VERSION "1.4.0"
# define PDFIO_VERSION "1.3.2"
//
@ -151,9 +151,7 @@ extern pdfio_obj_t *pdfioArrayGetObj(pdfio_array_t *a, size_t n) _PDFIO_PUBLIC;
extern size_t pdfioArrayGetSize(pdfio_array_t *a) _PDFIO_PUBLIC;
extern const char *pdfioArrayGetString(pdfio_array_t *a, size_t n) _PDFIO_PUBLIC;
extern pdfio_valtype_t pdfioArrayGetType(pdfio_array_t *a, size_t n) _PDFIO_PUBLIC;
extern bool pdfioArrayRemove(pdfio_array_t *a, size_t n) _PDFIO_PUBLIC;
extern bool pdfioDictClear(pdfio_dict_t *dict, const char *key) _PDFIO_PUBLIC;
extern pdfio_dict_t *pdfioDictCopy(pdfio_file_t *pdf, pdfio_dict_t *dict) _PDFIO_PUBLIC;
extern pdfio_dict_t *pdfioDictCreate(pdfio_file_t *pdf) _PDFIO_PUBLIC;
extern pdfio_array_t *pdfioDictGetArray(pdfio_dict_t *dict, const char *key) _PDFIO_PUBLIC;
@ -161,9 +159,7 @@ extern unsigned char *pdfioDictGetBinary(pdfio_dict_t *dict, const char *key, si
extern bool pdfioDictGetBoolean(pdfio_dict_t *dict, const char *key) _PDFIO_PUBLIC;
extern time_t pdfioDictGetDate(pdfio_dict_t *dict, const char *key) _PDFIO_PUBLIC;
extern pdfio_dict_t *pdfioDictGetDict(pdfio_dict_t *dict, const char *key) _PDFIO_PUBLIC;
extern const char *pdfioDictGetKey(pdfio_dict_t *dict, size_t n) _PDFIO_PUBLIC;
extern const char *pdfioDictGetName(pdfio_dict_t *dict, const char *key) _PDFIO_PUBLIC;
extern size_t pdfioDictGetNumPairs(pdfio_dict_t *dict) _PDFIO_PUBLIC;
extern double pdfioDictGetNumber(pdfio_dict_t *dict, const char *key) _PDFIO_PUBLIC;
extern pdfio_obj_t *pdfioDictGetObj(pdfio_dict_t *dict, const char *key) _PDFIO_PUBLIC;
extern pdfio_rect_t *pdfioDictGetRect(pdfio_dict_t *dict, const char *key, pdfio_rect_t *rect) _PDFIO_PUBLIC;
@ -186,7 +182,6 @@ extern bool pdfioDictSetStringf(pdfio_dict_t *dict, const char *key, const char
extern bool pdfioFileClose(pdfio_file_t *pdf) _PDFIO_PUBLIC;
extern 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) _PDFIO_PUBLIC;
extern pdfio_obj_t *pdfioFileCreateArrayObj(pdfio_file_t *pdf, pdfio_array_t *array) _PDFIO_PUBLIC;
extern pdfio_obj_t *pdfioFileCreateNameObj(pdfio_file_t *pdf, const char *name) _PDFIO_PUBLIC;
extern pdfio_obj_t *pdfioFileCreateNumberObj(pdfio_file_t *pdf, double number) _PDFIO_PUBLIC;
extern pdfio_obj_t *pdfioFileCreateObj(pdfio_file_t *pdf, pdfio_dict_t *dict) _PDFIO_PUBLIC;
extern pdfio_file_t *pdfioFileCreateOutput(pdfio_output_cb_t output_cb, void *output_ctx, const char *version, pdfio_rect_t *media_box, pdfio_rect_t *crop_box, pdfio_error_cb_t error_cb, void *error_data) _PDFIO_PUBLIC;
@ -227,7 +222,6 @@ extern pdfio_array_t *pdfioObjGetArray(pdfio_obj_t *obj) _PDFIO_PUBLIC;
extern pdfio_dict_t *pdfioObjGetDict(pdfio_obj_t *obj) _PDFIO_PUBLIC;
extern unsigned short pdfioObjGetGeneration(pdfio_obj_t *obj) _PDFIO_PUBLIC;
extern size_t pdfioObjGetLength(pdfio_obj_t *obj) _PDFIO_PUBLIC;
extern const char *pdfioObjGetName(pdfio_obj_t *obj) _PDFIO_PUBLIC;
extern size_t pdfioObjGetNumber(pdfio_obj_t *obj) _PDFIO_PUBLIC;
extern const char *pdfioObjGetSubtype(pdfio_obj_t *obj) _PDFIO_PUBLIC;
extern const char *pdfioObjGetType(pdfio_obj_t *obj) _PDFIO_PUBLIC;

View File

@ -1,5 +1,5 @@
LIBRARY pdfio1
VERSION 1.4
VERSION 1.3
EXPORTS
_pdfioArrayDebug
_pdfioArrayDecrypt
@ -23,6 +23,7 @@ _pdfioCryptoSHA256Append
_pdfioCryptoSHA256Finish
_pdfioCryptoSHA256Init
_pdfioCryptoUnlock
_pdfioDictClear
_pdfioDictDebug
_pdfioDictDecrypt
_pdfioDictDelete
@ -95,7 +96,6 @@ pdfioArrayGetObj
pdfioArrayGetSize
pdfioArrayGetString
pdfioArrayGetType
pdfioArrayRemove
pdfioContentClip
pdfioContentDrawImage
pdfioContentFill
@ -153,7 +153,6 @@ pdfioContentTextNextLine
pdfioContentTextShow
pdfioContentTextShowJustified
pdfioContentTextShowf
pdfioDictClear
pdfioDictCopy
pdfioDictCreate
pdfioDictGetArray
@ -161,9 +160,7 @@ pdfioDictGetBinary
pdfioDictGetBoolean
pdfioDictGetDate
pdfioDictGetDict
pdfioDictGetKey
pdfioDictGetName
pdfioDictGetNumPairs
pdfioDictGetNumber
pdfioDictGetObj
pdfioDictGetRect
@ -190,7 +187,6 @@ pdfioFileCreateFontObjFromFile
pdfioFileCreateICCObjFromFile
pdfioFileCreateImageObjFromData
pdfioFileCreateImageObjFromFile
pdfioFileCreateNameObj
pdfioFileCreateNumberObj
pdfioFileCreateObj
pdfioFileCreateOutput
@ -232,7 +228,6 @@ pdfioObjGetArray
pdfioObjGetDict
pdfioObjGetGeneration
pdfioObjGetLength
pdfioObjGetName
pdfioObjGetNumber
pdfioObjGetSubtype
pdfioObjGetType