diff --git a/.gitignore b/.gitignore index 00b96fd..f495949 100644 --- a/.gitignore +++ b/.gitignore @@ -14,6 +14,7 @@ /examples/code128 /examples/image2pdf /examples/md2pdf +/examples/pdf2text /examples/pdfioinfo /Makefile /packages @@ -21,7 +22,6 @@ /pdfio.xcodeproj/xcshareddata /pdfio-*.tar.gz* /pdfio-*.zip* -/pdfiototext /testpdfio /testpdfio-*.pdf /testttf diff --git a/Makefile.in b/Makefile.in index c3693f1..6f49c84 100644 --- a/Makefile.in +++ b/Makefile.in @@ -103,13 +103,11 @@ LIBOBJS = \ ttf.o OBJS = \ $(LIBOBJS) \ - pdfiototext.o \ testpdfio.o \ testttf.o TARGETS = \ $(LIBPDFIO) \ $(LIBPDFIO_STATIC) \ - pdfiototext \ testpdfio \ testttf @@ -201,12 +199,6 @@ pdfio1.def: $(LIBOBJS) Makefile grep -v '^_ttf' | sed -e '1,$$s/^_//' | sort >>$@ -# pdfio text extraction (demo, doesn't handle a lot of things yet) -pdfiototext: pdfiototext.o libpdfio.a - echo Linking $@... - $(CC) $(LDFLAGS) -o $@ pdfiototext.o libpdfio.a $(LIBS) - - # pdfio test program testpdfio: testpdfio.o libpdfio.a echo Linking $@... diff --git a/examples/Makefile b/examples/Makefile index ada00b6..7a0d134 100644 --- a/examples/Makefile +++ b/examples/Makefile @@ -23,6 +23,7 @@ TARGETS = \ code128 \ image2pdf \ md2pdf \ + pdf2text \ pdfioinfo @@ -50,6 +51,11 @@ md2pdf: md2pdf.c mmd.c mmd.h $(CC) $(CFLAGS) -o $@ md2pdf.c mmd.c $(LIBS) +# pdfio text extraction (demo, doesn't handle a lot of things yet) +pdf2text: pdf2text.c + $(CC) $(CFLAGS) -o $@ pdf2text.c $(LIBS) + + # pdfioinfo pdfioinfo: pdfioinfo.c $(CC) $(CFLAGS) -o $@ pdfioinfo.c $(LIBS) diff --git a/pdfiototext.c b/examples/pdf2text.c similarity index 76% rename from pdfiototext.c rename to examples/pdf2text.c index d791739..4bad097 100644 --- a/pdfiototext.c +++ b/examples/pdf2text.c @@ -1,17 +1,17 @@ // // PDF to text program for PDFio. // -// Copyright © 2022 by Michael R Sweet. +// Copyright © 2022-2024 by Michael R Sweet. // // Licensed under Apache License v2.0. See the file "LICENSE" for more // information. // // Usage: // -// ./pdfiototext FILENAME.pdf > FILENAME.txt +// ./pdf2text FILENAME.pdf > FILENAME.txt // -#include "pdfio.h" +#include #include @@ -36,16 +36,14 @@ main(int argc, // I - Number of command-line arguments // Verify command-line arguments... if (argc != 2) { - puts("Usage: pdfiototext FILENAME.pdf > FILENAME.txt"); + puts("Usage: pdf2text FILENAME.pdf > FILENAME.txt"); return (1); } // Open the PDF file... - if ((file = pdfioFileOpen(argv[1], NULL, NULL, NULL, NULL)) == NULL) + if ((file = pdfioFileOpen(argv[1], /*password_cb*/NULL, /*password_data*/NULL, /*error_cb*/NULL, /*error_data*/NULL)) == NULL) return (1); -// printf("%s: %u pages\n", argv[1], (unsigned)pdfioFileGetNumPages(file)); - // Try grabbing content from all of the pages... for (i = 0, num_pages = pdfioFileGetNumPages(file); i < num_pages; i ++) { @@ -54,15 +52,11 @@ main(int argc, // I - Number of command-line arguments num_streams = pdfioPageGetNumStreams(obj); -// printf("%s: page%u=%p, num_streams=%u\n", argv[1], (unsigned)i, obj, (unsigned)num_streams); - for (j = 0; j < num_streams; j ++) { if ((st = pdfioPageOpenStream(obj, j, true)) == NULL) continue; -// printf("%s: page%u st%u=%p\n", argv[1], (unsigned)i, (unsigned)j, st); - first = true; while (pdfioStreamGetToken(st, buffer, sizeof(buffer))) { @@ -70,7 +64,7 @@ main(int argc, // I - Number of command-line arguments { if (first) first = false; - else + else if (buffer[1] != ' ') putchar(' '); fputs(buffer + 1, stdout);