diff --git a/pdfio-common.c b/pdfio-common.c index 68a3755..f69049b 100644 --- a/pdfio-common.c +++ b/pdfio-common.c @@ -122,7 +122,7 @@ _pdfioFileGets(pdfio_file_t *pdf, // I - PDF file while (!eol) { // 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 diff --git a/pdfio-file.c b/pdfio-file.c index e7311bb..8f8c5d1 100644 --- a/pdfio-file.c +++ b/pdfio-file.c @@ -352,7 +352,7 @@ pdfioFileOpen( if (!_pdfioFileGets(pdf, line, sizeof(line))) 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 _pdfioFileError(pdf, "Bad header '%s'.", line); @@ -360,12 +360,15 @@ pdfioFileOpen( } // 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... - _pdfioFileSeek(pdf, 32, SEEK_END); + _pdfioFileSeek(pdf, -32, SEEK_END); if (_pdfioFileRead(pdf, line, 32) < 32) + { + _pdfioFileError(pdf, "Unable to read startxref data."); goto error; + } line[32] = '\0'; if ((ptr = strstr(line, "startxref")) == NULL) diff --git a/testpdfio.c b/testpdfio.c index 780039d..8398550 100644 --- a/testpdfio.c +++ b/testpdfio.c @@ -22,8 +22,20 @@ int // O - Exit status main(int argc, // I - Number of command-line arguments char *argv[]) // I - Command-line arguments { - (void)argc; - (void)argv; + if (argc > 1) + { + 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); }