mirror of
https://github.com/michaelrsweet/pdfio.git
synced 2024-12-25 12:58:21 +01:00
Move pdfiototext to examples.
This commit is contained in:
parent
aa91b141a8
commit
ed1421287f
2
.gitignore
vendored
2
.gitignore
vendored
@ -14,6 +14,7 @@
|
|||||||
/examples/code128
|
/examples/code128
|
||||||
/examples/image2pdf
|
/examples/image2pdf
|
||||||
/examples/md2pdf
|
/examples/md2pdf
|
||||||
|
/examples/pdf2text
|
||||||
/examples/pdfioinfo
|
/examples/pdfioinfo
|
||||||
/Makefile
|
/Makefile
|
||||||
/packages
|
/packages
|
||||||
@ -21,7 +22,6 @@
|
|||||||
/pdfio.xcodeproj/xcshareddata
|
/pdfio.xcodeproj/xcshareddata
|
||||||
/pdfio-*.tar.gz*
|
/pdfio-*.tar.gz*
|
||||||
/pdfio-*.zip*
|
/pdfio-*.zip*
|
||||||
/pdfiototext
|
|
||||||
/testpdfio
|
/testpdfio
|
||||||
/testpdfio-*.pdf
|
/testpdfio-*.pdf
|
||||||
/testttf
|
/testttf
|
||||||
|
@ -103,13 +103,11 @@ LIBOBJS = \
|
|||||||
ttf.o
|
ttf.o
|
||||||
OBJS = \
|
OBJS = \
|
||||||
$(LIBOBJS) \
|
$(LIBOBJS) \
|
||||||
pdfiototext.o \
|
|
||||||
testpdfio.o \
|
testpdfio.o \
|
||||||
testttf.o
|
testttf.o
|
||||||
TARGETS = \
|
TARGETS = \
|
||||||
$(LIBPDFIO) \
|
$(LIBPDFIO) \
|
||||||
$(LIBPDFIO_STATIC) \
|
$(LIBPDFIO_STATIC) \
|
||||||
pdfiototext \
|
|
||||||
testpdfio \
|
testpdfio \
|
||||||
testttf
|
testttf
|
||||||
|
|
||||||
@ -201,12 +199,6 @@ pdfio1.def: $(LIBOBJS) Makefile
|
|||||||
grep -v '^_ttf' | sed -e '1,$$s/^_//' | sort >>$@
|
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
|
# pdfio test program
|
||||||
testpdfio: testpdfio.o libpdfio.a
|
testpdfio: testpdfio.o libpdfio.a
|
||||||
echo Linking $@...
|
echo Linking $@...
|
||||||
|
@ -23,6 +23,7 @@ TARGETS = \
|
|||||||
code128 \
|
code128 \
|
||||||
image2pdf \
|
image2pdf \
|
||||||
md2pdf \
|
md2pdf \
|
||||||
|
pdf2text \
|
||||||
pdfioinfo
|
pdfioinfo
|
||||||
|
|
||||||
|
|
||||||
@ -50,6 +51,11 @@ md2pdf: md2pdf.c mmd.c mmd.h
|
|||||||
$(CC) $(CFLAGS) -o $@ md2pdf.c mmd.c $(LIBS)
|
$(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: pdfioinfo.c
|
pdfioinfo: pdfioinfo.c
|
||||||
$(CC) $(CFLAGS) -o $@ pdfioinfo.c $(LIBS)
|
$(CC) $(CFLAGS) -o $@ pdfioinfo.c $(LIBS)
|
||||||
|
@ -1,17 +1,17 @@
|
|||||||
//
|
//
|
||||||
// PDF to text program for PDFio.
|
// 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
|
// Licensed under Apache License v2.0. See the file "LICENSE" for more
|
||||||
// information.
|
// information.
|
||||||
//
|
//
|
||||||
// Usage:
|
// Usage:
|
||||||
//
|
//
|
||||||
// ./pdfiototext FILENAME.pdf > FILENAME.txt
|
// ./pdf2text FILENAME.pdf > FILENAME.txt
|
||||||
//
|
//
|
||||||
|
|
||||||
#include "pdfio.h"
|
#include <pdfio.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
||||||
|
|
||||||
@ -36,16 +36,14 @@ main(int argc, // I - Number of command-line arguments
|
|||||||
// Verify command-line arguments...
|
// Verify command-line arguments...
|
||||||
if (argc != 2)
|
if (argc != 2)
|
||||||
{
|
{
|
||||||
puts("Usage: pdfiototext FILENAME.pdf > FILENAME.txt");
|
puts("Usage: pdf2text FILENAME.pdf > FILENAME.txt");
|
||||||
return (1);
|
return (1);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Open the PDF file...
|
// 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);
|
return (1);
|
||||||
|
|
||||||
// printf("%s: %u pages\n", argv[1], (unsigned)pdfioFileGetNumPages(file));
|
|
||||||
|
|
||||||
// Try grabbing content from all of the pages...
|
// Try grabbing content from all of the pages...
|
||||||
for (i = 0, num_pages = pdfioFileGetNumPages(file); i < num_pages; i ++)
|
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);
|
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 ++)
|
for (j = 0; j < num_streams; j ++)
|
||||||
{
|
{
|
||||||
if ((st = pdfioPageOpenStream(obj, j, true)) == NULL)
|
if ((st = pdfioPageOpenStream(obj, j, true)) == NULL)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
// printf("%s: page%u st%u=%p\n", argv[1], (unsigned)i, (unsigned)j, st);
|
|
||||||
|
|
||||||
first = true;
|
first = true;
|
||||||
while (pdfioStreamGetToken(st, buffer, sizeof(buffer)))
|
while (pdfioStreamGetToken(st, buffer, sizeof(buffer)))
|
||||||
{
|
{
|
||||||
@ -70,7 +64,7 @@ main(int argc, // I - Number of command-line arguments
|
|||||||
{
|
{
|
||||||
if (first)
|
if (first)
|
||||||
first = false;
|
first = false;
|
||||||
else
|
else if (buffer[1] != ' ')
|
||||||
putchar(' ');
|
putchar(' ');
|
||||||
|
|
||||||
fputs(buffer + 1, stdout);
|
fputs(buffer + 1, stdout);
|
Loading…
Reference in New Issue
Block a user