diff --git a/CHANGES.md b/CHANGES.md index 48fdc8f..7829fa4 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -6,6 +6,7 @@ v1.4.1 - YYYY-MM-DD ------------------- - 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 diff --git a/doc/pdfio.3 b/doc/pdfio.3 index 8029add..41eeedb 100644 --- a/doc/pdfio.3 +++ b/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 pdfio \- pdf read/write library .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 pdfio_file_t *pdf; // PDF file + const char *author; // Author name time_t creation_date; // Creation date struct tm *creation_tm; // Creation date/time information char creation_text[256]; // Creation date/time as a string + const char *title; // Title // 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) return (1); + // Get the title and author... + author = pdfioFileGetAuthor(pdf); + title = pdfioFileGetTitle(pdf); + // 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); + if ((creation_date = pdfioFileGetCreationDate(pdf)) > 0) + { + 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... printf("%s:\\n", filename); - printf(" Title: %s\\n", pdfioFileGetTitle(pdf)); - printf(" Author: %s\\n", pdfioFileGetAuthor(pdf)); + printf(" Title: %s\\n", title ? title : "\-\- not set \-\-"); + printf(" Author: %s\\n", author ? author : "\-\- not set \-\-"); printf(" Created On: %s\\n", creation_text); 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 .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 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; // Pointer to this link record - if (!strcmp(frag\->url, "@")) + if (!strcmp(frag\->url, "@")) { // Use mapped text as link target... char targetlink[129]; // Targeted link diff --git a/doc/pdfio.html b/doc/pdfio.html index 8709c10..834afce 100644 --- a/doc/pdfio.html +++ b/doc/pdfio.html @@ -1161,9 +1161,11 @@ main(int argc, const char *filename; // PDF filename pdfio_file_t *pdf; // PDF file + const char *author; // Author name time_t creation_date; // Creation date struct tm *creation_tm; // Creation date/time information char creation_text[256]; // Creation date/time as a string + const char *title; // Title // Get the filename from the command-line... @@ -1181,15 +1183,25 @@ main(int argc, if (pdf == NULL) return (1); + // Get the title and author... + author = pdfioFileGetAuthor(pdf); + title = pdfioFileGetTitle(pdf); + // 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); + if ((creation_date = pdfioFileGetCreationDate(pdf)) > 0) + { + 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... printf("%s:\n", filename); - printf(" Title: %s\n", pdfioFileGetTitle(pdf)); - printf(" Author: %s\n", pdfioFileGetAuthor(pdf)); + printf(" Title: %s\n", title ? title : "-- not set --"); + printf(" Author: %s\n", author ? author : "-- not set --"); printf(" Created On: %s\n", creation_text); printf(" Number Pages: %u\n", (unsigned)pdfioFileGetNumPages(pdf)); @@ -2022,13 +2034,13 @@ dd->y -= margin_top + lineheight; dd->y -= lineheight; } -

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. WhÑn 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:

if (frag->url && dd->num_links < DOCLINK_MAX)
 {
   doclink_t *l = dd->links + dd->num_links;
                                   // Pointer to this link record
 
- ïif (!strcmp(frag->url, "@"))
+  if (!strcmp(frag->url, "@"))
   {
     // Use mapped text as link target...
     char  targetlink[129];        // Targeted link
diff --git a/doc/pdfio.md b/doc/pdfio.md
index 773fda6..8e91805 100644
--- a/doc/pdfio.md
+++ b/doc/pdfio.md
@@ -886,9 +886,11 @@ main(int  argc,                         // I - Number of command-line arguments
 {
   const char    *filename;              // PDF filename
   pdfio_file_t  *pdf;                   // PDF file
+  const char    *author;                // Author name
   time_t        creation_date;          // Creation date
   struct tm     *creation_tm;           // Creation date/time information
   char          creation_text[256];     // Creation date/time as a string
+  const char    *title;                 // Title
 
 
   // Get the filename from the command-line...
@@ -906,15 +908,25 @@ main(int  argc,                         // I - Number of command-line arguments
   if (pdf == NULL)
     return (1);
 
+  // Get the title and author...
+  author = pdfioFileGetAuthor(pdf);
+  title  = pdfioFileGetTitle(pdf);
+
   // 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);
+  if ((creation_date = pdfioFileGetCreationDate(pdf)) > 0)
+  {
+    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...
   printf("%s:\n", filename);
-  printf("         Title: %s\n", pdfioFileGetTitle(pdf));
-  printf("        Author: %s\n", pdfioFileGetAuthor(pdf));
+  printf("         Title: %s\n", title ? title : "-- not set --");
+  printf("        Author: %s\n", author ? author : "-- not set --");
   printf("    Created On: %s\n", creation_text);
   printf("  Number Pages: %u\n", (unsigned)pdfioFileGetNumPages(pdf));
 
diff --git a/examples/pdfioinfo.c b/examples/pdfioinfo.c
index 27a8bb9..f690eff 100644
--- a/examples/pdfioinfo.c
+++ b/examples/pdfioinfo.c
@@ -1,7 +1,7 @@
 //
 // 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
 // information.
@@ -25,9 +25,11 @@ main(int  argc,				// I - Number of command-line arguments
 {
   const char	*filename;		// PDF filename
   pdfio_file_t	*pdf;			// PDF file
+  const char	*author;		// Author name
   time_t	creation_date;		// Creation date
   struct tm	*creation_tm;		// Creation date/time information
   char		creation_text[256];	// Creation date/time as a string
+  const char	*title;			// Title
 
 
   // Get the filename from the command-line...
@@ -46,15 +48,25 @@ main(int  argc,				// I - Number of command-line arguments
   if (pdf == NULL)
     return (1);
 
+  // Get the title and author...
+  author = pdfioFileGetAuthor(pdf);
+  title  = pdfioFileGetTitle(pdf);
+
   // 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);
+  if ((creation_date = pdfioFileGetCreationDate(pdf)) > 0)
+  {
+    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...
   printf("%s:\n", filename);
-  printf("         Title: %s\n", pdfioFileGetTitle(pdf));
-  printf("        Author: %s\n", pdfioFileGetAuthor(pdf));
+  printf("         Title: %s\n", title ? title : "-- not set --");
+  printf("        Author: %s\n", author ? author : "-- not set --");
   printf("    Created On: %s\n", creation_text);
   printf("  Number Pages: %u\n", (unsigned)pdfioFileGetNumPages(pdf));
 
diff --git a/pdfio-file.c b/pdfio-file.c
index b12b714..efd9c7d 100644
--- a/pdfio-file.c
+++ b/pdfio-file.c
@@ -1,7 +1,7 @@
 //
 // 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
 // information.
@@ -1938,7 +1938,6 @@ load_xref(
 	// Save the trailer dictionary and grab the root (catalog) and info
 	// objects...
 	pdf->trailer_dict = trailer.value.dict;
-	pdf->info_obj     = pdfioDictGetObj(pdf->trailer_dict, "Info");
 	pdf->encrypt_obj  = pdfioDictGetObj(pdf->trailer_dict, "Encrypt");
 	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
 	// objects...
 	pdf->trailer_dict = trailer.value.dict;
-	pdf->info_obj     = pdfioDictGetObj(pdf->trailer_dict, "Info");
 	pdf->encrypt_obj  = pdfioDictGetObj(pdf->trailer_dict, "Encrypt");
 	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
   // build the pages array...
+  pdf->info_obj = pdfioDictGetObj(pdf->trailer_dict, "Info");
+
   if ((pdf->root_obj = pdfioDictGetObj(pdf->trailer_dict, "Root")) == NULL)
   {
     _pdfioFileError(pdf, "Missing Root object.");