mirror of
https://github.com/michaelrsweet/pdfio.git
synced 2024-12-27 05:48:20 +01:00
Initial working pdfioFileOpen, test program.
This commit is contained in:
parent
d13364a4fd
commit
f5f0e190b5
@ -122,7 +122,7 @@ _pdfioFileGets(pdfio_file_t *pdf, // I - PDF file
|
|||||||
while (!eol)
|
while (!eol)
|
||||||
{
|
{
|
||||||
// If there are characters ready in the buffer, use them...
|
// If there are characters ready in the buffer, use them...
|
||||||
while (pdf->bufptr < pdf->bufend && bufptr < bufend)
|
while (!eol && pdf->bufptr < pdf->bufend && bufptr < bufend)
|
||||||
{
|
{
|
||||||
char ch = *(pdf->bufptr++); // Next character in buffer
|
char ch = *(pdf->bufptr++); // Next character in buffer
|
||||||
|
|
||||||
|
@ -352,7 +352,7 @@ pdfioFileOpen(
|
|||||||
if (!_pdfioFileGets(pdf, line, sizeof(line)))
|
if (!_pdfioFileGets(pdf, line, sizeof(line)))
|
||||||
goto error;
|
goto error;
|
||||||
|
|
||||||
if ((strncmp(line, "%PDF-1.", 6) && strncmp(line, "%PDF-2.", 6)) || !isdigit(line[6] & 255))
|
if ((strncmp(line, "%PDF-1.", 7) && strncmp(line, "%PDF-2.", 7)) || !isdigit(line[7] & 255))
|
||||||
{
|
{
|
||||||
// Bad header
|
// Bad header
|
||||||
_pdfioFileError(pdf, "Bad header '%s'.", line);
|
_pdfioFileError(pdf, "Bad header '%s'.", line);
|
||||||
@ -360,12 +360,15 @@ pdfioFileOpen(
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Copy the version number...
|
// Copy the version number...
|
||||||
pdf->version = strdup(line + 4);
|
pdf->version = strdup(line + 5);
|
||||||
|
|
||||||
// Grab the last 32 characters of the file to find the start of the xref table...
|
// Grab the last 32 characters of the file to find the start of the xref table...
|
||||||
_pdfioFileSeek(pdf, 32, SEEK_END);
|
_pdfioFileSeek(pdf, -32, SEEK_END);
|
||||||
if (_pdfioFileRead(pdf, line, 32) < 32)
|
if (_pdfioFileRead(pdf, line, 32) < 32)
|
||||||
|
{
|
||||||
|
_pdfioFileError(pdf, "Unable to read startxref data.");
|
||||||
goto error;
|
goto error;
|
||||||
|
}
|
||||||
line[32] = '\0';
|
line[32] = '\0';
|
||||||
|
|
||||||
if ((ptr = strstr(line, "startxref")) == NULL)
|
if ((ptr = strstr(line, "startxref")) == NULL)
|
||||||
|
16
testpdfio.c
16
testpdfio.c
@ -22,8 +22,20 @@ int // O - Exit status
|
|||||||
main(int argc, // I - Number of command-line arguments
|
main(int argc, // I - Number of command-line arguments
|
||||||
char *argv[]) // I - Command-line arguments
|
char *argv[]) // I - Command-line arguments
|
||||||
{
|
{
|
||||||
(void)argc;
|
if (argc > 1)
|
||||||
(void)argv;
|
{
|
||||||
|
int i; // Looping var
|
||||||
|
pdfio_file_t *pdf; // PDF file
|
||||||
|
|
||||||
|
for (i = 1; i < argc; i ++)
|
||||||
|
{
|
||||||
|
if ((pdf = pdfioFileOpen(argv[i], NULL, NULL)) != NULL)
|
||||||
|
{
|
||||||
|
printf("%s: PDF %s, %d objects.\n", argv[i], pdfioFileGetVersion(pdf), (int)pdfioFileGetNumObjects(pdf));
|
||||||
|
pdfioFileClose(pdf);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return (0);
|
return (0);
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user