1 //========================================================================
5 // Copyright 1996 Derek B. Noonburg
7 //========================================================================
10 #pragma implementation
23 #include "OutputDev.h"
28 //------------------------------------------------------------------------
30 //------------------------------------------------------------------------
32 PDFDoc::PDFDoc(GString *fileName1) {
49 if (!(file = fopen(fileName->getCString(), "rb", "ctx=stm"))) {
50 error(-1, "Couldn't open file '%s'", fileName->getCString());
54 if (!(file = fopen(fileName->getCString(), "rb"))) {
55 fileName2 = fileName->copy();
56 fileName2->lowerCase();
57 if (!(file = fopen(fileName2->getCString(), "rb"))) {
58 fileName2->upperCase();
59 if (!(file = fopen(fileName2->getCString(), "rb"))) {
60 error(-1, "Couldn't open file '%s'", fileName->getCString());
71 str = new FileStream(file, 0, -1, &obj);
80 error(-1, "Couldn't read xref table");
85 catalog = new Catalog(xref->getCatalog(&catObj));
87 if (!catalog->isOk()) {
88 error(-1, "Couldn't read page catalog");
110 void PDFDoc::displayPage(OutputDev *out, int page, int zoom, int rotate,
113 double x1, y1, x2, y2;
118 printf("***** page %d *****\n", page);
119 catalog->getPage(page)->display(out, zoom, rotate);
124 for (i = 0; i < links->getNumLinks(); ++i) {
125 link = links->getLink(i);
126 link->getBorder(&x1, &y1, &x2, &y2, &w);
128 out->drawLinkBorder(x1, y1, x2, y2, w);
134 void PDFDoc::displayPages(OutputDev *out, int firstPage, int lastPage,
135 int zoom, int rotate) {
139 for (page = firstPage; page <= lastPage; ++page) {
141 printf("***** page %d *****\n", page);
142 p = catalog->getPage(page);
143 p->display(out, zoom, rotate);
147 GBool PDFDoc::saveAs(GString *name) {
152 if (!(f = fopen(name->getCString(), "wb"))) {
153 error(-1, "Couldn't open file '%s'", name->getCString());
157 while ((n = fread(buf, 1, sizeof(buf), file)) > 0)
158 fwrite(buf, 1, n, f);
163 void PDFDoc::getLinks(int page) {
166 links = new Links(catalog->getPage(page)->getAnnots(&obj),
167 catalog->getBaseURI());