mirror of
https://github.com/michaelrsweet/pdfio.git
synced 2025-04-08 09:56:45 +02:00
Update pdfioinfo example to support Acrobat Form dictionaries as well as indirect references (Issue #114)
This commit is contained in:
parent
0bd9edc845
commit
130cef8702
@ -6,6 +6,7 @@ v1.5.2 - YYYY-MM-DD
|
|||||||
-------------------
|
-------------------
|
||||||
|
|
||||||
- Updated maximum allowed PDF string size to 64k (Issue #117)
|
- Updated maximum allowed PDF string size to 64k (Issue #117)
|
||||||
|
- Fixed form detection in `pdfioinfo` example code (Issue #114)
|
||||||
- Fixed parsing of certain date/time values (Issue #115)
|
- Fixed parsing of certain date/time values (Issue #115)
|
||||||
- Fixed support for empty name values (Issue #116)
|
- Fixed support for empty name values (Issue #116)
|
||||||
|
|
||||||
|
119
doc/pdfio.3
119
doc/pdfio.3
@ -1,4 +1,4 @@
|
|||||||
.TH pdfio 3 "pdf read/write library" "2025-03-06" "pdf read/write library"
|
.TH pdfio 3 "pdf read/write library" "2025-04-04" "pdf read/write library"
|
||||||
.SH NAME
|
.SH NAME
|
||||||
pdfio \- pdf read/write library
|
pdfio \- pdf read/write library
|
||||||
.SH Introduction
|
.SH Introduction
|
||||||
@ -1047,11 +1047,26 @@ 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
|
pdfio_dict_t *catalog; // Catalog dictionary
|
||||||
time_t creation_date; // Creation date
|
const char *author, // Author name
|
||||||
struct tm *creation_tm; // Creation date/time information
|
*creator, // Creator name
|
||||||
char creation_text[256]; // Creation date/time as a string
|
*producer, // Producer name
|
||||||
const char *title; // Title
|
*title; // Title
|
||||||
|
time_t creation_date, // Creation date
|
||||||
|
modification_date; // Modification date
|
||||||
|
struct tm *creation_tm, // Creation date/time information
|
||||||
|
*modification_tm; // Modification date/time information
|
||||||
|
char creation_text[256], // Creation date/time as a string
|
||||||
|
modification_text[256], // Modification date/time human fmt string
|
||||||
|
range_text[255]; // Page range text
|
||||||
|
size_t num_pages; // PDF number of pages
|
||||||
|
bool has_acroform; // Does the file have an AcroForm?
|
||||||
|
pdfio_obj_t *page; // Object
|
||||||
|
pdfio_dict_t *page_dict; // Object dictionary
|
||||||
|
size_t cur, // Current page index
|
||||||
|
prev; // Previous page index
|
||||||
|
pdfio_rect_t cur_box, // Current MediaBox
|
||||||
|
prev_box; // Previous MediaBox
|
||||||
|
|
||||||
|
|
||||||
// Get the filename from the command\-line...
|
// Get the filename from the command\-line...
|
||||||
@ -1064,14 +1079,20 @@ The pdfioinfo.c example program opens a PDF file and prints the title, author, c
|
|||||||
filename = argv[1];
|
filename = argv[1];
|
||||||
|
|
||||||
// Open the PDF file with the default callbacks...
|
// Open the PDF file with the default callbacks...
|
||||||
pdf = pdfioFileOpen(filename, /*password_cb*/NULL, /*password_cbdata*/NULL,
|
pdf = pdfioFileOpen(filename, /*password_cb*/NULL,
|
||||||
/*error_cb*/NULL, /*error_cbdata*/NULL);
|
/*password_cbdata*/NULL, /*error_cb*/NULL,
|
||||||
|
/*error_cbdata*/NULL);
|
||||||
if (pdf == NULL)
|
if (pdf == NULL)
|
||||||
return (1);
|
return (1);
|
||||||
|
|
||||||
// Get the title and author...
|
// Get the title, author, etc...
|
||||||
author = pdfioFileGetAuthor(pdf);
|
catalog = pdfioFileGetCatalog(pdf);
|
||||||
title = pdfioFileGetTitle(pdf);
|
author = pdfioFileGetAuthor(pdf);
|
||||||
|
creator = pdfioFileGetCreator(pdf);
|
||||||
|
has_acroform = pdfioDictGetType(catalog, "AcroForm") != PDFIO_VALTYPE_NONE;
|
||||||
|
num_pages = pdfioFileGetNumPages(pdf);
|
||||||
|
producer = pdfioFileGetProducer(pdf);
|
||||||
|
title = pdfioFileGetTitle(pdf);
|
||||||
|
|
||||||
// Get the creation date and convert to a string...
|
// Get the creation date and convert to a string...
|
||||||
if ((creation_date = pdfioFileGetCreationDate(pdf)) > 0)
|
if ((creation_date = pdfioFileGetCreationDate(pdf)) > 0)
|
||||||
@ -1084,12 +1105,76 @@ The pdfioinfo.c example program opens a PDF file and prints the title, author, c
|
|||||||
snprintf(creation_text, sizeof(creation_text), "\-\- not set \-\-");
|
snprintf(creation_text, sizeof(creation_text), "\-\- not set \-\-");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Get the modification date and convert to a string...
|
||||||
|
if ((modification_date = pdfioFileGetModificationDate(pdf)) > 0)
|
||||||
|
{
|
||||||
|
modification_tm = localtime(&modification_date);
|
||||||
|
strftime(modification_text, sizeof(modification_text), "%c", modification_tm);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
snprintf(modification_text, sizeof(modification_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", title ? title : "\-\- not set \-\-");
|
printf(" Title: %s\\n", title ? title : "\-\- not set \-\-");
|
||||||
printf(" Author: %s\\n", author ? author : "\-\- not set \-\-");
|
printf(" Author: %s\\n", author ? author : "\-\- not set \-\-");
|
||||||
printf(" Created On: %s\\n", creation_text);
|
printf(" Creator: %s\\n", creator ? creator : "\-\- not set \-\-");
|
||||||
printf(" Number Pages: %u\\n", (unsigned)pdfioFileGetNumPages(pdf));
|
printf(" Producer: %s\\n", producer ? producer : "\-\- not set \-\-");
|
||||||
|
printf(" Created On: %s\\n", creation_text);
|
||||||
|
printf(" Modified On: %s\\n", modification_text);
|
||||||
|
printf(" Version: %s\\n", pdfioFileGetVersion(pdf));
|
||||||
|
printf(" AcroForm: %s\\n", has_acroform ? "Yes" : "No");
|
||||||
|
printf(" Number of Pages: %u\\n", (unsigned)num_pages);
|
||||||
|
|
||||||
|
// Report the MediaBox for all of the pages
|
||||||
|
prev_box.x1 = prev_box.x2 = prev_box.y1 = prev_box.y2 = 0.0;
|
||||||
|
|
||||||
|
for (cur = 0, prev = 0; cur < num_pages; cur ++)
|
||||||
|
{
|
||||||
|
// Find the MediaBox for this page in the page tree...
|
||||||
|
for (page = pdfioFileGetPage(pdf, cur);
|
||||||
|
page != NULL;
|
||||||
|
page = pdfioDictGetObj(page_dict, "Parent"))
|
||||||
|
{
|
||||||
|
cur_box.x1 = cur_box.x2 = cur_box.y1 = cur_box.y2 = 0.0;
|
||||||
|
page_dict = pdfioObjGetDict(page);
|
||||||
|
|
||||||
|
if (pdfioDictGetRect(page_dict, "MediaBox", &cur_box))
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
// If this MediaBox is different from the previous one, show the range of
|
||||||
|
// pages that have that size...
|
||||||
|
if (cur == 0 ||
|
||||||
|
fabs(cur_box.x1 \- prev_box.x1) > 0.01 ||
|
||||||
|
fabs(cur_box.y1 \- prev_box.y1) > 0.01 ||
|
||||||
|
fabs(cur_box.x2 \- prev_box.x2) > 0.01 ||
|
||||||
|
fabs(cur_box.y2 \- prev_box.y2) > 0.01)
|
||||||
|
{
|
||||||
|
if (cur > prev)
|
||||||
|
{
|
||||||
|
snprintf(range_text, sizeof(range_text), "Pages %u\-%u",
|
||||||
|
(unsigned)(prev + 1), (unsigned)cur);
|
||||||
|
printf("%16s: [%g %g %g %g]\\n", range_text,
|
||||||
|
prev_box.x1, prev_box.y1, prev_box.x2, prev_box.y2);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Start a new series of pages with the new size...
|
||||||
|
prev = cur;
|
||||||
|
prev_box = cur_box;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Show the last range as needed...
|
||||||
|
if (cur > prev)
|
||||||
|
{
|
||||||
|
snprintf(range_text, sizeof(range_text), "Pages %u\-%u",
|
||||||
|
(unsigned)(prev + 1), (unsigned)cur);
|
||||||
|
printf("%16s: [%g %g %g %g]\\n", range_text,
|
||||||
|
prev_box.x1, prev_box.y1, prev_box.x2, prev_box.y2);
|
||||||
|
}
|
||||||
|
|
||||||
// Close the PDF file...
|
// Close the PDF file...
|
||||||
pdfioFileClose(pdf);
|
pdfioFileClose(pdf);
|
||||||
@ -4590,6 +4675,10 @@ bool pdfioStreamPrintf (
|
|||||||
...
|
...
|
||||||
);
|
);
|
||||||
.fi
|
.fi
|
||||||
|
.PP
|
||||||
|
This function writes a formatted string to a stream. In addition to the
|
||||||
|
standard \fBprintf\fR format characters, you can use "%N" to format a PDF name
|
||||||
|
value ("/Name") and "%S" to format a PDF string ("(String)") value.
|
||||||
.SS pdfioStreamPutChar
|
.SS pdfioStreamPutChar
|
||||||
Write a single character to a stream.
|
Write a single character to a stream.
|
||||||
.PP
|
.PP
|
||||||
|
123
doc/pdfio.html
123
doc/pdfio.html
@ -1,13 +1,13 @@
|
|||||||
<!DOCTYPE html>
|
<!DOCTYPE html>
|
||||||
<html lang="en-US">
|
<html lang="en-US">
|
||||||
<head>
|
<head>
|
||||||
<title>PDFio Programming Manual v1.5.0</title>
|
<title>PDFio Programming Manual v1.5.2</title>
|
||||||
<meta http-equiv="Content-Type" content="text/html;charset=utf-8">
|
<meta http-equiv="Content-Type" content="text/html;charset=utf-8">
|
||||||
<meta name="generator" content="codedoc v3.8">
|
<meta name="generator" content="codedoc v3.8">
|
||||||
<meta name="author" content="Michael R Sweet">
|
<meta name="author" content="Michael R Sweet">
|
||||||
<meta name="language" content="en-US">
|
<meta name="language" content="en-US">
|
||||||
<meta name="copyright" content="Copyright © 2021-2025 by Michael R Sweet">
|
<meta name="copyright" content="Copyright © 2021-2025 by Michael R Sweet">
|
||||||
<meta name="version" content="1.5.0">
|
<meta name="version" content="1.5.2">
|
||||||
<style type="text/css"><!--
|
<style type="text/css"><!--
|
||||||
body {
|
body {
|
||||||
background: white;
|
background: white;
|
||||||
@ -251,7 +251,7 @@ span.string {
|
|||||||
<body>
|
<body>
|
||||||
<div class="header">
|
<div class="header">
|
||||||
<p><img class="title" src="pdfio-512.png"></p>
|
<p><img class="title" src="pdfio-512.png"></p>
|
||||||
<h1 class="title">PDFio Programming Manual v1.5.0</h1>
|
<h1 class="title">PDFio Programming Manual v1.5.2</h1>
|
||||||
<p>Michael R Sweet</p>
|
<p>Michael R Sweet</p>
|
||||||
<p>Copyright © 2021-2025 by Michael R Sweet</p>
|
<p>Copyright © 2021-2025 by Michael R Sweet</p>
|
||||||
</div>
|
</div>
|
||||||
@ -1165,11 +1165,26 @@ 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>
|
pdfio_dict_t *catalog; <span class="comment">// Catalog dictionary</span>
|
||||||
time_t creation_date; <span class="comment">// Creation date</span>
|
<span class="reserved">const</span> <span class="reserved">char</span> *author, <span class="comment">// Author name</span>
|
||||||
<span class="reserved">struct</span> tm *creation_tm; <span class="comment">// Creation date/time information</span>
|
*creator, <span class="comment">// Creator name</span>
|
||||||
<span class="reserved">char</span> creation_text[<span class="number">256</span>]; <span class="comment">// Creation date/time as a string</span>
|
*producer, <span class="comment">// Producer name</span>
|
||||||
<span class="reserved">const</span> <span class="reserved">char</span> *title; <span class="comment">// Title</span>
|
*title; <span class="comment">// Title</span>
|
||||||
|
time_t creation_date, <span class="comment">// Creation date</span>
|
||||||
|
modification_date; <span class="comment">// Modification date</span>
|
||||||
|
<span class="reserved">struct</span> tm *creation_tm, <span class="comment">// Creation date/time information</span>
|
||||||
|
*modification_tm; <span class="comment">// Modification 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>
|
||||||
|
modification_text[<span class="number">256</span>], <span class="comment">// Modification date/time human fmt string</span>
|
||||||
|
range_text[<span class="number">255</span>]; <span class="comment">// Page range text</span>
|
||||||
|
size_t num_pages; <span class="comment">// PDF number of pages</span>
|
||||||
|
<span class="reserved">bool</span> has_acroform; <span class="comment">// Does the file have an AcroForm?</span>
|
||||||
|
pdfio_obj_t *page; <span class="comment">// Object</span>
|
||||||
|
pdfio_dict_t *page_dict; <span class="comment">// Object dictionary</span>
|
||||||
|
size_t cur, <span class="comment">// Current page index</span>
|
||||||
|
prev; <span class="comment">// Previous page index</span>
|
||||||
|
pdfio_rect_t cur_box, <span class="comment">// Current MediaBox</span>
|
||||||
|
prev_box; <span class="comment">// Previous MediaBox</span>
|
||||||
|
|
||||||
|
|
||||||
<span class="comment">// Get the filename from the command-line...</span>
|
<span class="comment">// Get the filename from the command-line...</span>
|
||||||
@ -1182,14 +1197,20 @@ main(<span class="reserved">int</span> argc, <span clas
|
|||||||
filename = argv[<span class="number">1</span>];
|
filename = argv[<span class="number">1</span>];
|
||||||
|
|
||||||
<span class="comment">// Open the PDF file with the default callbacks...</span>
|
<span class="comment">// Open the PDF file with the default callbacks...</span>
|
||||||
pdf = pdfioFileOpen(filename, <span class="comment">/*password_cb*/</span>NULL, <span class="comment">/*password_cbdata*/</span>NULL,
|
pdf = pdfioFileOpen(filename, <span class="comment">/*password_cb*/</span>NULL,
|
||||||
<span class="comment">/*error_cb*/</span>NULL, <span class="comment">/*error_cbdata*/</span>NULL);
|
<span class="comment">/*password_cbdata*/</span>NULL, <span class="comment">/*error_cb*/</span>NULL,
|
||||||
|
<span class="comment">/*error_cbdata*/</span>NULL);
|
||||||
<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>
|
<span class="comment">// Get the title, author, etc...</span>
|
||||||
author = pdfioFileGetAuthor(pdf);
|
catalog = pdfioFileGetCatalog(pdf);
|
||||||
title = pdfioFileGetTitle(pdf);
|
author = pdfioFileGetAuthor(pdf);
|
||||||
|
creator = pdfioFileGetCreator(pdf);
|
||||||
|
has_acroform = pdfioDictGetType(catalog, <span class="string">"AcroForm"</span>) != PDFIO_VALTYPE_NONE;
|
||||||
|
num_pages = pdfioFileGetNumPages(pdf);
|
||||||
|
producer = pdfioFileGetProducer(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>
|
||||||
<span class="reserved">if</span> ((creation_date = pdfioFileGetCreationDate(pdf)) > <span class="number">0</span>)
|
<span class="reserved">if</span> ((creation_date = pdfioFileGetCreationDate(pdf)) > <span class="number">0</span>)
|
||||||
@ -1202,12 +1223,76 @@ main(<span class="reserved">int</span> argc, <span clas
|
|||||||
snprintf(creation_text, <span class="reserved">sizeof</span>(creation_text), <span class="string">"-- not set --"</span>);
|
snprintf(creation_text, <span class="reserved">sizeof</span>(creation_text), <span class="string">"-- not set --"</span>);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
<span class="comment">// Get the modification date and convert to a string...</span>
|
||||||
|
<span class="reserved">if</span> ((modification_date = pdfioFileGetModificationDate(pdf)) > <span class="number">0</span>)
|
||||||
|
{
|
||||||
|
modification_tm = localtime(&modification_date);
|
||||||
|
strftime(modification_text, <span class="reserved">sizeof</span>(modification_text), <span class="string">"%c"</span>, modification_tm);
|
||||||
|
}
|
||||||
|
<span class="reserved">else</span>
|
||||||
|
{
|
||||||
|
snprintf(modification_text, <span class="reserved">sizeof</span>(modification_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>, title ? title : <span class="string">"-- not set --"</span>);
|
printf(<span class="string">" Title: %s\n"</span>, title ? title : <span class="string">"-- not set --"</span>);
|
||||||
printf(<span class="string">" Author: %s\n"</span>, author ? author : <span class="string">"-- not set --"</span>);
|
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">" Creator: %s\n"</span>, creator ? creator : <span class="string">"-- not set --"</span>);
|
||||||
printf(<span class="string">" Number Pages: %u\n"</span>, (<span class="reserved">unsigned</span>)pdfioFileGetNumPages(pdf));
|
printf(<span class="string">" Producer: %s\n"</span>, producer ? producer : <span class="string">"-- not set --"</span>);
|
||||||
|
printf(<span class="string">" Created On: %s\n"</span>, creation_text);
|
||||||
|
printf(<span class="string">" Modified On: %s\n"</span>, modification_text);
|
||||||
|
printf(<span class="string">" Version: %s\n"</span>, pdfioFileGetVersion(pdf));
|
||||||
|
printf(<span class="string">" AcroForm: %s\n"</span>, has_acroform ? <span class="string">"Yes"</span> : <span class="string">"No"</span>);
|
||||||
|
printf(<span class="string">" Number of Pages: %u\n"</span>, (<span class="reserved">unsigned</span>)num_pages);
|
||||||
|
|
||||||
|
<span class="comment">// Report the MediaBox for all of the pages</span>
|
||||||
|
prev_box.x1 = prev_box.x2 = prev_box.y1 = prev_box.y2 = <span class="number">0.0</span>;
|
||||||
|
|
||||||
|
<span class="reserved">for</span> (cur = <span class="number">0</span>, prev = <span class="number">0</span>; cur < num_pages; cur ++)
|
||||||
|
{
|
||||||
|
<span class="comment">// Find the MediaBox for this page in the page tree...</span>
|
||||||
|
<span class="reserved">for</span> (page = pdfioFileGetPage(pdf, cur);
|
||||||
|
page != NULL;
|
||||||
|
page = pdfioDictGetObj(page_dict, <span class="string">"Parent"</span>))
|
||||||
|
{
|
||||||
|
cur_box.x1 = cur_box.x2 = cur_box.y1 = cur_box.y2 = <span class="number">0.0</span>;
|
||||||
|
page_dict = pdfioObjGetDict(page);
|
||||||
|
|
||||||
|
<span class="reserved">if</span> (pdfioDictGetRect(page_dict, <span class="string">"MediaBox"</span>, &cur_box))
|
||||||
|
<span class="reserved">break</span>;
|
||||||
|
}
|
||||||
|
|
||||||
|
<span class="comment">// If this MediaBox is different from the previous one, show the range of</span>
|
||||||
|
<span class="comment">// pages that have that size...</span>
|
||||||
|
<span class="reserved">if</span> (cur == <span class="number">0</span> ||
|
||||||
|
fabs(cur_box.x1 - prev_box.x1) > <span class="number">0.01</span> ||
|
||||||
|
fabs(cur_box.y1 - prev_box.y1) > <span class="number">0.01</span> ||
|
||||||
|
fabs(cur_box.x2 - prev_box.x2) > <span class="number">0.01</span> ||
|
||||||
|
fabs(cur_box.y2 - prev_box.y2) > <span class="number">0.01</span>)
|
||||||
|
{
|
||||||
|
<span class="reserved">if</span> (cur > prev)
|
||||||
|
{
|
||||||
|
snprintf(range_text, <span class="reserved">sizeof</span>(range_text), <span class="string">"Pages %u-%u"</span>,
|
||||||
|
(<span class="reserved">unsigned</span>)(prev + <span class="number">1</span>), (<span class="reserved">unsigned</span>)cur);
|
||||||
|
printf(<span class="string">"%16s: [%g %g %g %g]\n"</span>, range_text,
|
||||||
|
prev_box.x1, prev_box.y1, prev_box.x2, prev_box.y2);
|
||||||
|
}
|
||||||
|
|
||||||
|
<span class="comment">// Start a new series of pages with the new size...</span>
|
||||||
|
prev = cur;
|
||||||
|
prev_box = cur_box;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
<span class="comment">// Show the last range as needed...</span>
|
||||||
|
<span class="reserved">if</span> (cur > prev)
|
||||||
|
{
|
||||||
|
snprintf(range_text, <span class="reserved">sizeof</span>(range_text), <span class="string">"Pages %u-%u"</span>,
|
||||||
|
(<span class="reserved">unsigned</span>)(prev + <span class="number">1</span>), (<span class="reserved">unsigned</span>)cur);
|
||||||
|
printf(<span class="string">"%16s: [%g %g %g %g]\n"</span>, range_text,
|
||||||
|
prev_box.x1, prev_box.y1, prev_box.x2, prev_box.y2);
|
||||||
|
}
|
||||||
|
|
||||||
<span class="comment">// Close the PDF file...</span>
|
<span class="comment">// Close the PDF file...</span>
|
||||||
pdfioFileClose(pdf);
|
pdfioFileClose(pdf);
|
||||||
@ -5081,6 +5166,10 @@ ssize_t pdfioStreamPeek(<a href="#pdfio_stream_t">pdfio_stream_t</a> *st, <span
|
|||||||
</tbody></table>
|
</tbody></table>
|
||||||
<h4 class="returnvalue">Return Value</h4>
|
<h4 class="returnvalue">Return Value</h4>
|
||||||
<p class="description"><code>true</code> on success, <code>false</code> on failure</p>
|
<p class="description"><code>true</code> on success, <code>false</code> on failure</p>
|
||||||
|
<h4 class="discussion">Discussion</h4>
|
||||||
|
<p class="discussion">This function writes a formatted string to a stream. In addition to the
|
||||||
|
standard <code>printf</code> format characters, you can use "%N" to format a PDF name
|
||||||
|
value ("/Name") and "%S" to format a PDF string ("(String)") value.</p>
|
||||||
<h3 class="function"><a id="pdfioStreamPutChar">pdfioStreamPutChar</a></h3>
|
<h3 class="function"><a id="pdfioStreamPutChar">pdfioStreamPutChar</a></h3>
|
||||||
<p class="description">Write a single character to a stream.</p>
|
<p class="description">Write a single character to a stream.</p>
|
||||||
<p class="code">
|
<p class="code">
|
||||||
|
113
doc/pdfio.md
113
doc/pdfio.md
@ -889,11 +889,26 @@ 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
|
pdfio_dict_t *catalog; // Catalog dictionary
|
||||||
time_t creation_date; // Creation date
|
const char *author, // Author name
|
||||||
struct tm *creation_tm; // Creation date/time information
|
*creator, // Creator name
|
||||||
char creation_text[256]; // Creation date/time as a string
|
*producer, // Producer name
|
||||||
const char *title; // Title
|
*title; // Title
|
||||||
|
time_t creation_date, // Creation date
|
||||||
|
modification_date; // Modification date
|
||||||
|
struct tm *creation_tm, // Creation date/time information
|
||||||
|
*modification_tm; // Modification date/time information
|
||||||
|
char creation_text[256], // Creation date/time as a string
|
||||||
|
modification_text[256], // Modification date/time human fmt string
|
||||||
|
range_text[255]; // Page range text
|
||||||
|
size_t num_pages; // PDF number of pages
|
||||||
|
bool has_acroform; // Does the file have an AcroForm?
|
||||||
|
pdfio_obj_t *page; // Object
|
||||||
|
pdfio_dict_t *page_dict; // Object dictionary
|
||||||
|
size_t cur, // Current page index
|
||||||
|
prev; // Previous page index
|
||||||
|
pdfio_rect_t cur_box, // Current MediaBox
|
||||||
|
prev_box; // Previous MediaBox
|
||||||
|
|
||||||
|
|
||||||
// Get the filename from the command-line...
|
// Get the filename from the command-line...
|
||||||
@ -906,14 +921,20 @@ main(int argc, // I - Number of command-line arguments
|
|||||||
filename = argv[1];
|
filename = argv[1];
|
||||||
|
|
||||||
// Open the PDF file with the default callbacks...
|
// Open the PDF file with the default callbacks...
|
||||||
pdf = pdfioFileOpen(filename, /*password_cb*/NULL, /*password_cbdata*/NULL,
|
pdf = pdfioFileOpen(filename, /*password_cb*/NULL,
|
||||||
/*error_cb*/NULL, /*error_cbdata*/NULL);
|
/*password_cbdata*/NULL, /*error_cb*/NULL,
|
||||||
|
/*error_cbdata*/NULL);
|
||||||
if (pdf == NULL)
|
if (pdf == NULL)
|
||||||
return (1);
|
return (1);
|
||||||
|
|
||||||
// Get the title and author...
|
// Get the title, author, etc...
|
||||||
author = pdfioFileGetAuthor(pdf);
|
catalog = pdfioFileGetCatalog(pdf);
|
||||||
title = pdfioFileGetTitle(pdf);
|
author = pdfioFileGetAuthor(pdf);
|
||||||
|
creator = pdfioFileGetCreator(pdf);
|
||||||
|
has_acroform = pdfioDictGetType(catalog, "AcroForm") != PDFIO_VALTYPE_NONE;
|
||||||
|
num_pages = pdfioFileGetNumPages(pdf);
|
||||||
|
producer = pdfioFileGetProducer(pdf);
|
||||||
|
title = pdfioFileGetTitle(pdf);
|
||||||
|
|
||||||
// Get the creation date and convert to a string...
|
// Get the creation date and convert to a string...
|
||||||
if ((creation_date = pdfioFileGetCreationDate(pdf)) > 0)
|
if ((creation_date = pdfioFileGetCreationDate(pdf)) > 0)
|
||||||
@ -926,12 +947,76 @@ main(int argc, // I - Number of command-line arguments
|
|||||||
snprintf(creation_text, sizeof(creation_text), "-- not set --");
|
snprintf(creation_text, sizeof(creation_text), "-- not set --");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Get the modification date and convert to a string...
|
||||||
|
if ((modification_date = pdfioFileGetModificationDate(pdf)) > 0)
|
||||||
|
{
|
||||||
|
modification_tm = localtime(&modification_date);
|
||||||
|
strftime(modification_text, sizeof(modification_text), "%c", modification_tm);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
snprintf(modification_text, sizeof(modification_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", title ? title : "-- not set --");
|
printf(" Title: %s\n", title ? title : "-- not set --");
|
||||||
printf(" Author: %s\n", author ? author : "-- not set --");
|
printf(" Author: %s\n", author ? author : "-- not set --");
|
||||||
printf(" Created On: %s\n", creation_text);
|
printf(" Creator: %s\n", creator ? creator : "-- not set --");
|
||||||
printf(" Number Pages: %u\n", (unsigned)pdfioFileGetNumPages(pdf));
|
printf(" Producer: %s\n", producer ? producer : "-- not set --");
|
||||||
|
printf(" Created On: %s\n", creation_text);
|
||||||
|
printf(" Modified On: %s\n", modification_text);
|
||||||
|
printf(" Version: %s\n", pdfioFileGetVersion(pdf));
|
||||||
|
printf(" AcroForm: %s\n", has_acroform ? "Yes" : "No");
|
||||||
|
printf(" Number of Pages: %u\n", (unsigned)num_pages);
|
||||||
|
|
||||||
|
// Report the MediaBox for all of the pages
|
||||||
|
prev_box.x1 = prev_box.x2 = prev_box.y1 = prev_box.y2 = 0.0;
|
||||||
|
|
||||||
|
for (cur = 0, prev = 0; cur < num_pages; cur ++)
|
||||||
|
{
|
||||||
|
// Find the MediaBox for this page in the page tree...
|
||||||
|
for (page = pdfioFileGetPage(pdf, cur);
|
||||||
|
page != NULL;
|
||||||
|
page = pdfioDictGetObj(page_dict, "Parent"))
|
||||||
|
{
|
||||||
|
cur_box.x1 = cur_box.x2 = cur_box.y1 = cur_box.y2 = 0.0;
|
||||||
|
page_dict = pdfioObjGetDict(page);
|
||||||
|
|
||||||
|
if (pdfioDictGetRect(page_dict, "MediaBox", &cur_box))
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
// If this MediaBox is different from the previous one, show the range of
|
||||||
|
// pages that have that size...
|
||||||
|
if (cur == 0 ||
|
||||||
|
fabs(cur_box.x1 - prev_box.x1) > 0.01 ||
|
||||||
|
fabs(cur_box.y1 - prev_box.y1) > 0.01 ||
|
||||||
|
fabs(cur_box.x2 - prev_box.x2) > 0.01 ||
|
||||||
|
fabs(cur_box.y2 - prev_box.y2) > 0.01)
|
||||||
|
{
|
||||||
|
if (cur > prev)
|
||||||
|
{
|
||||||
|
snprintf(range_text, sizeof(range_text), "Pages %u-%u",
|
||||||
|
(unsigned)(prev + 1), (unsigned)cur);
|
||||||
|
printf("%16s: [%g %g %g %g]\n", range_text,
|
||||||
|
prev_box.x1, prev_box.y1, prev_box.x2, prev_box.y2);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Start a new series of pages with the new size...
|
||||||
|
prev = cur;
|
||||||
|
prev_box = cur_box;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Show the last range as needed...
|
||||||
|
if (cur > prev)
|
||||||
|
{
|
||||||
|
snprintf(range_text, sizeof(range_text), "Pages %u-%u",
|
||||||
|
(unsigned)(prev + 1), (unsigned)cur);
|
||||||
|
printf("%16s: [%g %g %g %g]\n", range_text,
|
||||||
|
prev_box.x1, prev_box.y1, prev_box.x2, prev_box.y2);
|
||||||
|
}
|
||||||
|
|
||||||
// Close the PDF file...
|
// Close the PDF file...
|
||||||
pdfioFileClose(pdf);
|
pdfioFileClose(pdf);
|
||||||
|
@ -68,7 +68,7 @@ main(int argc, // I - Number of command-line arguments
|
|||||||
catalog = pdfioFileGetCatalog(pdf);
|
catalog = pdfioFileGetCatalog(pdf);
|
||||||
author = pdfioFileGetAuthor(pdf);
|
author = pdfioFileGetAuthor(pdf);
|
||||||
creator = pdfioFileGetCreator(pdf);
|
creator = pdfioFileGetCreator(pdf);
|
||||||
has_acroform = pdfioDictGetObj(catalog, "AcroForm") != NULL ? true : false;
|
has_acroform = pdfioDictGetType(catalog, "AcroForm") != PDFIO_VALTYPE_NONE;
|
||||||
num_pages = pdfioFileGetNumPages(pdf);
|
num_pages = pdfioFileGetNumPages(pdf);
|
||||||
producer = pdfioFileGetProducer(pdf);
|
producer = pdfioFileGetProducer(pdf);
|
||||||
title = pdfioFileGetTitle(pdf);
|
title = pdfioFileGetTitle(pdf);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user