2024-12-19 16:43:21 -05:00
|
|
|
|
//
|
|
|
|
|
// PDF metadata example for PDFio.
|
|
|
|
|
//
|
2025-01-17 16:50:30 -05:00
|
|
|
|
// Copyright © 2023-2025 by Michael R Sweet.
|
2024-12-19 16:43:21 -05:00
|
|
|
|
//
|
|
|
|
|
// Licensed under Apache License v2.0. See the file "LICENSE" for more
|
|
|
|
|
// information.
|
|
|
|
|
//
|
|
|
|
|
// Usage:
|
|
|
|
|
//
|
|
|
|
|
// ./pdfioinfo FILENAME.pdf
|
|
|
|
|
//
|
|
|
|
|
|
|
|
|
|
#include <pdfio.h>
|
|
|
|
|
#include <time.h>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//
|
|
|
|
|
// 'main()' - Open a PDF file and show its metadata.
|
|
|
|
|
//
|
|
|
|
|
|
|
|
|
|
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
|
2025-01-17 16:50:30 -05:00
|
|
|
|
const char *author; // Author name
|
2024-12-19 16:43:21 -05:00
|
|
|
|
time_t creation_date; // Creation date
|
|
|
|
|
struct tm *creation_tm; // Creation date/time information
|
|
|
|
|
char creation_text[256]; // Creation date/time as a string
|
2025-01-17 16:50:30 -05:00
|
|
|
|
const char *title; // Title
|
2024-12-19 16:43:21 -05:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 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);
|
|
|
|
|
|
2025-01-17 16:50:30 -05:00
|
|
|
|
// Get the title and author...
|
|
|
|
|
author = pdfioFileGetAuthor(pdf);
|
|
|
|
|
title = pdfioFileGetTitle(pdf);
|
|
|
|
|
|
2024-12-19 16:43:21 -05:00
|
|
|
|
// Get the creation date and convert to a string...
|
2025-01-17 16:50:30 -05:00
|
|
|
|
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 --");
|
|
|
|
|
}
|
2024-12-19 16:43:21 -05:00
|
|
|
|
|
|
|
|
|
// Print file information to stdout...
|
|
|
|
|
printf("%s:\n", filename);
|
2025-01-17 16:50:30 -05:00
|
|
|
|
printf(" Title: %s\n", title ? title : "-- not set --");
|
|
|
|
|
printf(" Author: %s\n", author ? author : "-- not set --");
|
2024-12-19 16:43:21 -05:00
|
|
|
|
printf(" Created On: %s\n", creation_text);
|
|
|
|
|
printf(" Number Pages: %u\n", (unsigned)pdfioFileGetNumPages(pdf));
|
|
|
|
|
|
|
|
|
|
// Close the PDF file...
|
|
|
|
|
pdfioFileClose(pdf);
|
|
|
|
|
|
|
|
|
|
return (0);
|
|
|
|
|
}
|