mirror of
https://github.com/michaelrsweet/pdfio.git
synced 2025-01-28 23:52:55 +01:00
Delay loading of the Info object and clean up the pdfioinfo example (Issue #87)
This commit is contained in:
parent
fbd61d1fe9
commit
3bc041e6d3
@ -6,6 +6,7 @@ v1.4.1 - YYYY-MM-DD
|
|||||||
-------------------
|
-------------------
|
||||||
|
|
||||||
- Fixed the link libraries for the example source code (Issue #86)
|
- Fixed the link libraries for the example source code (Issue #86)
|
||||||
|
- Fixed handling of the Info object (Issue #87)
|
||||||
|
|
||||||
|
|
||||||
v1.4.0 - 2024-12-26
|
v1.4.0 - 2024-12-26
|
||||||
|
28
doc/pdfio.3
28
doc/pdfio.3
@ -1,4 +1,4 @@
|
|||||||
.TH pdfio 3 "pdf read/write library" "2024-12-26" "pdf read/write library"
|
.TH pdfio 3 "pdf read/write library" "2025-01-17" "pdf read/write library"
|
||||||
.SH NAME
|
.SH NAME
|
||||||
pdfio \- pdf read/write library
|
pdfio \- pdf read/write library
|
||||||
.SH Introduction
|
.SH Introduction
|
||||||
@ -1045,9 +1045,11 @@ The pdfioinfo.c example program opens a PDF file and prints the title, author, c
|
|||||||
{
|
{
|
||||||
const char *filename; // PDF filename
|
const char *filename; // PDF filename
|
||||||
pdfio_file_t *pdf; // PDF file
|
pdfio_file_t *pdf; // PDF file
|
||||||
|
const char *author; // Author name
|
||||||
time_t creation_date; // Creation date
|
time_t creation_date; // Creation date
|
||||||
struct tm *creation_tm; // Creation date/time information
|
struct tm *creation_tm; // Creation date/time information
|
||||||
char creation_text[256]; // Creation date/time as a string
|
char creation_text[256]; // Creation date/time as a string
|
||||||
|
const char *title; // Title
|
||||||
|
|
||||||
|
|
||||||
// Get the filename from the command\-line...
|
// Get the filename from the command\-line...
|
||||||
@ -1065,15 +1067,25 @@ The pdfioinfo.c example program opens a PDF file and prints the title, author, c
|
|||||||
if (pdf == NULL)
|
if (pdf == NULL)
|
||||||
return (1);
|
return (1);
|
||||||
|
|
||||||
|
// Get the title and author...
|
||||||
|
author = pdfioFileGetAuthor(pdf);
|
||||||
|
title = pdfioFileGetTitle(pdf);
|
||||||
|
|
||||||
// Get the creation date and convert to a string...
|
// Get the creation date and convert to a string...
|
||||||
creation_date = pdfioFileGetCreationDate(pdf);
|
if ((creation_date = pdfioFileGetCreationDate(pdf)) > 0)
|
||||||
creation_tm = localtime(&creation_date);
|
{
|
||||||
strftime(creation_text, sizeof(creation_text), "%c", creation_tm);
|
creation_tm = localtime(&creation_date);
|
||||||
|
strftime(creation_text, sizeof(creation_text), "%c", creation_tm);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
snprintf(creation_text, sizeof(creation_text), "\-\- not set \-\-");
|
||||||
|
}
|
||||||
|
|
||||||
// Print file information to stdout...
|
// Print file information to stdout...
|
||||||
printf("%s:\\n", filename);
|
printf("%s:\\n", filename);
|
||||||
printf(" Title: %s\\n", pdfioFileGetTitle(pdf));
|
printf(" Title: %s\\n", title ? title : "\-\- not set \-\-");
|
||||||
printf(" Author: %s\\n", pdfioFileGetAuthor(pdf));
|
printf(" Author: %s\\n", author ? author : "\-\- not set \-\-");
|
||||||
printf(" Created On: %s\\n", creation_text);
|
printf(" Created On: %s\\n", creation_text);
|
||||||
printf(" Number Pages: %u\\n", (unsigned)pdfioFileGetNumPages(pdf));
|
printf(" Number Pages: %u\\n", (unsigned)pdfioFileGetNumPages(pdf));
|
||||||
|
|
||||||
@ -2062,7 +2074,7 @@ The render_line function adds content from the linefrag_t array to a PDF page. I
|
|||||||
}
|
}
|
||||||
.fi
|
.fi
|
||||||
.PP
|
.PP
|
||||||
We then loops through the fragments for the current line, drawing checkboxes, images, and text as needed. When a hyperlink is present, we add the link to the links array in the docdata_t structure, mapping "@" and "@@" to an internal link corresponding to the linked text:
|
We then loops through the fragments for the current line, drawing checkboxes, images, and text as needed. Whan a hyperlink is present, we add the link to the links array in the docdata_t structure, mapping "@" and "@@" to an internal link corresponding to the linked text:
|
||||||
.nf
|
.nf
|
||||||
|
|
||||||
if (frag\->url && dd\->num_links < DOCLINK_MAX)
|
if (frag\->url && dd\->num_links < DOCLINK_MAX)
|
||||||
@ -2070,7 +2082,7 @@ We then loops through the fragments for the current line, drawing checkboxes, im
|
|||||||
doclink_t *l = dd\->links + dd\->num_links;
|
doclink_t *l = dd\->links + dd\->num_links;
|
||||||
// Pointer to this link record
|
// Pointer to this link record
|
||||||
|
|
||||||
if (!strcmp(frag\->url, "@"))
|
if (!strcmp(frag\->url, "@"))
|
||||||
{
|
{
|
||||||
// Use mapped text as link target...
|
// Use mapped text as link target...
|
||||||
char targetlink[129]; // Targeted link
|
char targetlink[129]; // Targeted link
|
||||||
|
@ -1161,9 +1161,11 @@ main(<span class="reserved">int</span> argc, <span clas
|
|||||||
{
|
{
|
||||||
<span class="reserved">const</span> <span class="reserved">char</span> *filename; <span class="comment">// PDF filename</span>
|
<span class="reserved">const</span> <span class="reserved">char</span> *filename; <span class="comment">// PDF filename</span>
|
||||||
pdfio_file_t *pdf; <span class="comment">// PDF file</span>
|
pdfio_file_t *pdf; <span class="comment">// PDF file</span>
|
||||||
|
<span class="reserved">const</span> <span class="reserved">char</span> *author; <span class="comment">// Author name</span>
|
||||||
time_t creation_date; <span class="comment">// Creation date</span>
|
time_t creation_date; <span class="comment">// Creation date</span>
|
||||||
<span class="reserved">struct</span> tm *creation_tm; <span class="comment">// Creation date/time information</span>
|
<span class="reserved">struct</span> tm *creation_tm; <span class="comment">// Creation date/time information</span>
|
||||||
<span class="reserved">char</span> creation_text[<span class="number">256</span>]; <span class="comment">// Creation date/time as a string</span>
|
<span class="reserved">char</span> creation_text[<span class="number">256</span>]; <span class="comment">// Creation date/time as a string</span>
|
||||||
|
<span class="reserved">const</span> <span class="reserved">char</span> *title; <span class="comment">// Title</span>
|
||||||
|
|
||||||
|
|
||||||
<span class="comment">// Get the filename from the command-line...</span>
|
<span class="comment">// Get the filename from the command-line...</span>
|
||||||
@ -1181,15 +1183,25 @@ main(<span class="reserved">int</span> argc, <span clas
|
|||||||
<span class="reserved">if</span> (pdf == NULL)
|
<span class="reserved">if</span> (pdf == NULL)
|
||||||
<span class="reserved">return</span> (<span class="number">1</span>);
|
<span class="reserved">return</span> (<span class="number">1</span>);
|
||||||
|
|
||||||
|
<span class="comment">// Get the title and author...</span>
|
||||||
|
author = pdfioFileGetAuthor(pdf);
|
||||||
|
title = pdfioFileGetTitle(pdf);
|
||||||
|
|
||||||
<span class="comment">// Get the creation date and convert to a string...</span>
|
<span class="comment">// Get the creation date and convert to a string...</span>
|
||||||
creation_date = pdfioFileGetCreationDate(pdf);
|
<span class="reserved">if</span> ((creation_date = pdfioFileGetCreationDate(pdf)) > <span class="number">0</span>)
|
||||||
creation_tm = localtime(&creation_date);
|
{
|
||||||
strftime(creation_text, <span class="reserved">sizeof</span>(creation_text), <span class="string">"%c"</span>, creation_tm);
|
creation_tm = localtime(&creation_date);
|
||||||
|
strftime(creation_text, <span class="reserved">sizeof</span>(creation_text), <span class="string">"%c"</span>, creation_tm);
|
||||||
|
}
|
||||||
|
<span class="reserved">else</span>
|
||||||
|
{
|
||||||
|
snprintf(creation_text, <span class="reserved">sizeof</span>(creation_text), <span class="string">"-- not set --"</span>);
|
||||||
|
}
|
||||||
|
|
||||||
<span class="comment">// Print file information to stdout...</span>
|
<span class="comment">// Print file information to stdout...</span>
|
||||||
printf(<span class="string">"%s:\n"</span>, filename);
|
printf(<span class="string">"%s:\n"</span>, filename);
|
||||||
printf(<span class="string">" Title: %s\n"</span>, pdfioFileGetTitle(pdf));
|
printf(<span class="string">" Title: %s\n"</span>, title ? title : <span class="string">"-- not set --"</span>);
|
||||||
printf(<span class="string">" Author: %s\n"</span>, pdfioFileGetAuthor(pdf));
|
printf(<span class="string">" Author: %s\n"</span>, author ? author : <span class="string">"-- not set --"</span>);
|
||||||
printf(<span class="string">" Created On: %s\n"</span>, creation_text);
|
printf(<span class="string">" Created On: %s\n"</span>, creation_text);
|
||||||
printf(<span class="string">" Number Pages: %u\n"</span>, (<span class="reserved">unsigned</span>)pdfioFileGetNumPages(pdf));
|
printf(<span class="string">" Number Pages: %u\n"</span>, (<span class="reserved">unsigned</span>)pdfioFileGetNumPages(pdf));
|
||||||
|
|
||||||
@ -2022,13 +2034,13 @@ dd->y -= margin_top + lineheight;
|
|||||||
dd->y -= lineheight;
|
dd->y -= lineheight;
|
||||||
}
|
}
|
||||||
</code></pre>
|
</code></pre>
|
||||||
<p>We then loops through the fragments for the current line, drawing checkboxes, images, and text as needed. When a hyperlink is present, we add the link to the <code>links</code> array in the <code>docdata_t</code> structure, mapping "@" and "@@" to an internal link corresponding to the linked text:</p>
|
<p>We then loops through the fragments for the current line, drawing checkboxes, images, and text as needed. WhÑn a hyperlink is present, we add the link to the <code>links</code> array in the <code>docdata_t</code> structure, mapping "@" and "@@" to an internal link corresponding to the linked text:</p>
|
||||||
<pre><code class="language-c"><span class="reserved">if</span> (frag->url && dd->num_links < DOCLINK_MAX)
|
<pre><code class="language-c"><span class="reserved">if</span> (frag->url && dd->num_links < DOCLINK_MAX)
|
||||||
{
|
{
|
||||||
doclink_t *l = dd->links + dd->num_links;
|
doclink_t *l = dd->links + dd->num_links;
|
||||||
<span class="comment">// Pointer to this link record</span>
|
<span class="comment">// Pointer to this link record</span>
|
||||||
|
|
||||||
ï<span class="reserved">if</span> (!strcmp(frag->url, <span class="string">"@"</span>))
|
<span class="reserved">if</span> (!strcmp(frag->url, <span class="string">"@"</span>))
|
||||||
{
|
{
|
||||||
<span class="comment">// Use mapped text as link target...</span>
|
<span class="comment">// Use mapped text as link target...</span>
|
||||||
<span class="reserved">char</span> targetlink[<span class="number">129</span>]; <span class="comment">// Targeted link</span>
|
<span class="reserved">char</span> targetlink[<span class="number">129</span>]; <span class="comment">// Targeted link</span>
|
||||||
|
22
doc/pdfio.md
22
doc/pdfio.md
@ -886,9 +886,11 @@ main(int argc, // I - Number of command-line arguments
|
|||||||
{
|
{
|
||||||
const char *filename; // PDF filename
|
const char *filename; // PDF filename
|
||||||
pdfio_file_t *pdf; // PDF file
|
pdfio_file_t *pdf; // PDF file
|
||||||
|
const char *author; // Author name
|
||||||
time_t creation_date; // Creation date
|
time_t creation_date; // Creation date
|
||||||
struct tm *creation_tm; // Creation date/time information
|
struct tm *creation_tm; // Creation date/time information
|
||||||
char creation_text[256]; // Creation date/time as a string
|
char creation_text[256]; // Creation date/time as a string
|
||||||
|
const char *title; // Title
|
||||||
|
|
||||||
|
|
||||||
// Get the filename from the command-line...
|
// Get the filename from the command-line...
|
||||||
@ -906,15 +908,25 @@ main(int argc, // I - Number of command-line arguments
|
|||||||
if (pdf == NULL)
|
if (pdf == NULL)
|
||||||
return (1);
|
return (1);
|
||||||
|
|
||||||
|
// Get the title and author...
|
||||||
|
author = pdfioFileGetAuthor(pdf);
|
||||||
|
title = pdfioFileGetTitle(pdf);
|
||||||
|
|
||||||
// Get the creation date and convert to a string...
|
// Get the creation date and convert to a string...
|
||||||
creation_date = pdfioFileGetCreationDate(pdf);
|
if ((creation_date = pdfioFileGetCreationDate(pdf)) > 0)
|
||||||
creation_tm = localtime(&creation_date);
|
{
|
||||||
strftime(creation_text, sizeof(creation_text), "%c", creation_tm);
|
creation_tm = localtime(&creation_date);
|
||||||
|
strftime(creation_text, sizeof(creation_text), "%c", creation_tm);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
snprintf(creation_text, sizeof(creation_text), "-- not set --");
|
||||||
|
}
|
||||||
|
|
||||||
// Print file information to stdout...
|
// Print file information to stdout...
|
||||||
printf("%s:\n", filename);
|
printf("%s:\n", filename);
|
||||||
printf(" Title: %s\n", pdfioFileGetTitle(pdf));
|
printf(" Title: %s\n", title ? title : "-- not set --");
|
||||||
printf(" Author: %s\n", pdfioFileGetAuthor(pdf));
|
printf(" Author: %s\n", author ? author : "-- not set --");
|
||||||
printf(" Created On: %s\n", creation_text);
|
printf(" Created On: %s\n", creation_text);
|
||||||
printf(" Number Pages: %u\n", (unsigned)pdfioFileGetNumPages(pdf));
|
printf(" Number Pages: %u\n", (unsigned)pdfioFileGetNumPages(pdf));
|
||||||
|
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
//
|
//
|
||||||
// PDF metadata example for PDFio.
|
// PDF metadata example for PDFio.
|
||||||
//
|
//
|
||||||
// Copyright © 2023-2024 by Michael R Sweet.
|
// Copyright © 2023-2025 by Michael R Sweet.
|
||||||
//
|
//
|
||||||
// Licensed under Apache License v2.0. See the file "LICENSE" for more
|
// Licensed under Apache License v2.0. See the file "LICENSE" for more
|
||||||
// information.
|
// information.
|
||||||
@ -25,9 +25,11 @@ main(int argc, // I - Number of command-line arguments
|
|||||||
{
|
{
|
||||||
const char *filename; // PDF filename
|
const char *filename; // PDF filename
|
||||||
pdfio_file_t *pdf; // PDF file
|
pdfio_file_t *pdf; // PDF file
|
||||||
|
const char *author; // Author name
|
||||||
time_t creation_date; // Creation date
|
time_t creation_date; // Creation date
|
||||||
struct tm *creation_tm; // Creation date/time information
|
struct tm *creation_tm; // Creation date/time information
|
||||||
char creation_text[256]; // Creation date/time as a string
|
char creation_text[256]; // Creation date/time as a string
|
||||||
|
const char *title; // Title
|
||||||
|
|
||||||
|
|
||||||
// Get the filename from the command-line...
|
// Get the filename from the command-line...
|
||||||
@ -46,15 +48,25 @@ main(int argc, // I - Number of command-line arguments
|
|||||||
if (pdf == NULL)
|
if (pdf == NULL)
|
||||||
return (1);
|
return (1);
|
||||||
|
|
||||||
|
// Get the title and author...
|
||||||
|
author = pdfioFileGetAuthor(pdf);
|
||||||
|
title = pdfioFileGetTitle(pdf);
|
||||||
|
|
||||||
// Get the creation date and convert to a string...
|
// Get the creation date and convert to a string...
|
||||||
creation_date = pdfioFileGetCreationDate(pdf);
|
if ((creation_date = pdfioFileGetCreationDate(pdf)) > 0)
|
||||||
creation_tm = localtime(&creation_date);
|
{
|
||||||
strftime(creation_text, sizeof(creation_text), "%c", creation_tm);
|
creation_tm = localtime(&creation_date);
|
||||||
|
strftime(creation_text, sizeof(creation_text), "%c", creation_tm);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
snprintf(creation_text, sizeof(creation_text), "-- not set --");
|
||||||
|
}
|
||||||
|
|
||||||
// Print file information to stdout...
|
// Print file information to stdout...
|
||||||
printf("%s:\n", filename);
|
printf("%s:\n", filename);
|
||||||
printf(" Title: %s\n", pdfioFileGetTitle(pdf));
|
printf(" Title: %s\n", title ? title : "-- not set --");
|
||||||
printf(" Author: %s\n", pdfioFileGetAuthor(pdf));
|
printf(" Author: %s\n", author ? author : "-- not set --");
|
||||||
printf(" Created On: %s\n", creation_text);
|
printf(" Created On: %s\n", creation_text);
|
||||||
printf(" Number Pages: %u\n", (unsigned)pdfioFileGetNumPages(pdf));
|
printf(" Number Pages: %u\n", (unsigned)pdfioFileGetNumPages(pdf));
|
||||||
|
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
//
|
//
|
||||||
// PDF file functions for PDFio.
|
// PDF file functions for PDFio.
|
||||||
//
|
//
|
||||||
// Copyright © 2021-2024 by Michael R Sweet.
|
// Copyright © 2021-2025 by Michael R Sweet.
|
||||||
//
|
//
|
||||||
// Licensed under Apache License v2.0. See the file "LICENSE" for more
|
// Licensed under Apache License v2.0. See the file "LICENSE" for more
|
||||||
// information.
|
// information.
|
||||||
@ -1938,7 +1938,6 @@ load_xref(
|
|||||||
// Save the trailer dictionary and grab the root (catalog) and info
|
// Save the trailer dictionary and grab the root (catalog) and info
|
||||||
// objects...
|
// objects...
|
||||||
pdf->trailer_dict = trailer.value.dict;
|
pdf->trailer_dict = trailer.value.dict;
|
||||||
pdf->info_obj = pdfioDictGetObj(pdf->trailer_dict, "Info");
|
|
||||||
pdf->encrypt_obj = pdfioDictGetObj(pdf->trailer_dict, "Encrypt");
|
pdf->encrypt_obj = pdfioDictGetObj(pdf->trailer_dict, "Encrypt");
|
||||||
pdf->id_array = pdfioDictGetArray(pdf->trailer_dict, "ID");
|
pdf->id_array = pdfioDictGetArray(pdf->trailer_dict, "ID");
|
||||||
|
|
||||||
@ -2086,7 +2085,6 @@ load_xref(
|
|||||||
// Save the trailer dictionary and grab the root (catalog) and info
|
// Save the trailer dictionary and grab the root (catalog) and info
|
||||||
// objects...
|
// objects...
|
||||||
pdf->trailer_dict = trailer.value.dict;
|
pdf->trailer_dict = trailer.value.dict;
|
||||||
pdf->info_obj = pdfioDictGetObj(pdf->trailer_dict, "Info");
|
|
||||||
pdf->encrypt_obj = pdfioDictGetObj(pdf->trailer_dict, "Encrypt");
|
pdf->encrypt_obj = pdfioDictGetObj(pdf->trailer_dict, "Encrypt");
|
||||||
pdf->id_array = pdfioDictGetArray(pdf->trailer_dict, "ID");
|
pdf->id_array = pdfioDictGetArray(pdf->trailer_dict, "ID");
|
||||||
|
|
||||||
@ -2123,6 +2121,8 @@ load_xref(
|
|||||||
|
|
||||||
// Once we have all of the xref tables loaded, get the important objects and
|
// Once we have all of the xref tables loaded, get the important objects and
|
||||||
// build the pages array...
|
// build the pages array...
|
||||||
|
pdf->info_obj = pdfioDictGetObj(pdf->trailer_dict, "Info");
|
||||||
|
|
||||||
if ((pdf->root_obj = pdfioDictGetObj(pdf->trailer_dict, "Root")) == NULL)
|
if ((pdf->root_obj = pdfioDictGetObj(pdf->trailer_dict, "Root")) == NULL)
|
||||||
{
|
{
|
||||||
_pdfioFileError(pdf, "Missing Root object.");
|
_pdfioFileError(pdf, "Missing Root object.");
|
||||||
|
Loading…
x
Reference in New Issue
Block a user