summaryrefslogtreecommitdiff
path: root/apps/pdfdraw.c
diff options
context:
space:
mode:
authorTor Andersson <tor@ghostscript.com>2010-03-09 01:18:29 +0100
committerTor Andersson <tor@ghostscript.com>2010-03-09 01:18:29 +0100
commit9737242baff66bed4937f9efede3befbaee8e792 (patch)
treecbe8f8f92536ed51562c72e78e968a6066400d67 /apps/pdfdraw.c
parentc96f530870d86d552007ca2e124fc3aa1f0824ac (diff)
downloadmupdf-9737242baff66bed4937f9efede3befbaee8e792.tar.xz
Add text extraction device.
Diffstat (limited to 'apps/pdfdraw.c')
-rw-r--r--apps/pdfdraw.c37
1 files changed, 33 insertions, 4 deletions
diff --git a/apps/pdfdraw.c b/apps/pdfdraw.c
index 44957dc2..2855227a 100644
--- a/apps/pdfdraw.c
+++ b/apps/pdfdraw.c
@@ -231,7 +231,7 @@ static void drawpnm(int pagenum, struct benchmark *loadtimes, struct benchmark *
// drawpage->contents->rp = drawpage->contents->bp;
// pdf_runcontentstream(dev, ctm, 0, xref, drawpage->resources, drawpage->contents);
- dev = fz_newdrawdevice(pdf_devicergb, pix);
+ dev = fz_newdrawdevice(pix);
drawpage->contents->rp = drawpage->contents->bp;
error = pdf_runcontentstream(dev, ctm, 0, xref, drawpage->resources, drawpage->contents);
if (error)
@@ -303,6 +303,37 @@ static void drawpnm(int pagenum, struct benchmark *loadtimes, struct benchmark *
fprintf(stdout, "\n");
}
+static void drawtxt(int pagenum)
+{
+ fz_error error;
+ fz_matrix ctm;
+ fz_obj *pageobj;
+ fz_textline *text;
+ fz_device *dev;
+
+ pageobj = pdf_getpageobject(xref, pagenum);
+ error = pdf_loadpage(&drawpage, xref, pageobj);
+ if (error)
+ die(error);
+
+ ctm = fz_identity();
+
+ text = fz_newtextline();
+ dev = fz_newtextdevice(text);
+
+ drawpage->contents->rp = drawpage->contents->bp;
+ error = pdf_runcontentstream(dev, ctm, 0, xref, drawpage->resources, drawpage->contents);
+ if (error)
+ die(error);
+
+ printf("[Page %d]\n", pagenum);
+ fz_debugtextline(text);
+ printf("\n");
+
+ fz_freetextdevice(dev);
+ fz_freetextline(text);
+}
+
static void drawpages(char *pagelist)
{
int page, spage, epage;
@@ -352,7 +383,7 @@ static void drawpages(char *pagelist)
switch (drawmode)
{
case DRAWPNM: drawpnm(page, &loadtimes, &drawtimes); break;
-// case DRAWTXT: drawtxt(page); break;
+ case DRAWTXT: drawtxt(page); break;
// case DRAWXML: drawxml(page); break;
}
}
@@ -417,8 +448,6 @@ int main(int argc, char **argv)
closexref();
-//XXX fz_newrenderer(&drawgc, pdf_devicergb, 0, 1024 * 512);
-
openxref(argv[fz_optind], password, 0);
state = NO_PAGES_DRAWN;
}