Back to index

tetex-bin  3.0
Public Member Functions | Private Member Functions | Private Attributes
PDFDoc Class Reference

#include <PDFDoc.h>

Collaboration diagram for PDFDoc:
Collaboration graph
[legend]

List of all members.

Public Member Functions

 PDFDoc (GString *fileNameA, GString *ownerPassword=NULL, GString *userPassword=NULL)
 PDFDoc (BaseStream *strA, GString *ownerPassword=NULL, GString *userPassword=NULL)
 ~PDFDoc ()
GBool isOk ()
int getErrorCode ()
GStringgetFileName ()
XRefgetXRef ()
CataloggetCatalog ()
BaseStreamgetBaseStream ()
double getPageWidth (int page)
double getPageHeight (int page)
int getPageRotate (int page)
int getNumPages ()
GStringreadMetadata ()
ObjectgetStructTreeRoot ()
void displayPage (OutputDev *out, int page, double hDPI, double vDPI, int rotate, GBool crop, GBool doLinks, GBool(*abortCheckCbk)(void *data)=NULL, void *abortCheckCbkData=NULL)
void displayPages (OutputDev *out, int firstPage, int lastPage, double hDPI, double vDPI, int rotate, GBool crop, GBool doLinks, GBool(*abortCheckCbk)(void *data)=NULL, void *abortCheckCbkData=NULL)
void displayPageSlice (OutputDev *out, int page, double hDPI, double vDPI, int rotate, GBool crop, int sliceX, int sliceY, int sliceW, int sliceH, GBool(*abortCheckCbk)(void *data)=NULL, void *abortCheckCbkData=NULL)
int findPage (int num, int gen)
LinkActionfindLink (double x, double y)
GBool onLink (double x, double y)
LinkDestfindDest (GString *name)
OutlinegetOutline ()
GBool isEncrypted ()
GBool okToPrint (GBool ignoreOwnerPW=gFalse)
GBool okToChange (GBool ignoreOwnerPW=gFalse)
GBool okToCopy (GBool ignoreOwnerPW=gFalse)
GBool okToAddNotes (GBool ignoreOwnerPW=gFalse)
GBool isLinearized ()
ObjectgetDocInfo (Object *obj)
ObjectgetDocInfoNF (Object *obj)
double getPDFVersion ()
GBool saveAs (GString *name)

Private Member Functions

GBool setup (GString *ownerPassword, GString *userPassword)
void checkHeader ()
void getLinks (Page *page)

Private Attributes

GStringfileName
FILEfile
BaseStreamstr
double pdfVersion
XRefxref
Catalogcatalog
Linkslinks
Outlineoutline
GBool ok
int errCode

Detailed Description

Definition at line 36 of file PDFDoc.h.


Constructor & Destructor Documentation

PDFDoc::PDFDoc ( GString fileNameA,
GString ownerPassword = NULL,
GString userPassword = NULL 
)

Definition at line 46 of file PDFDoc.cc.

                                     {
  Object obj;
  GString *fileName1, *fileName2;

  ok = gFalse;
  errCode = errNone;

  file = NULL;
  str = NULL;
  xref = NULL;
  catalog = NULL;
  links = NULL;
#ifndef DISABLE_OUTLINE
  outline = NULL;
#endif

  fileName = fileNameA;
  fileName1 = fileName;


  // try to open file
  fileName2 = NULL;
#ifdef VMS
  if (!(file = fopen(fileName1->getCString(), "rb", "ctx=stm"))) {
    error(-1, "Couldn't open file '%s'", fileName1->getCString());
    errCode = errOpenFile;
    return;
  }
#else
  if (!(file = fopen(fileName1->getCString(), "rb"))) {
    fileName2 = fileName->copy();
    fileName2->lowerCase();
    if (!(file = fopen(fileName2->getCString(), "rb"))) {
      fileName2->upperCase();
      if (!(file = fopen(fileName2->getCString(), "rb"))) {
       error(-1, "Couldn't open file '%s'", fileName->getCString());
       delete fileName2;
       errCode = errOpenFile;
       return;
      }
    }
    delete fileName2;
  }
#endif

  // create stream
  obj.initNull();
  str = new FileStream(file, 0, gFalse, 0, &obj);

  ok = setup(ownerPassword, userPassword);
}

Here is the call graph for this function:

PDFDoc::PDFDoc ( BaseStream strA,
GString ownerPassword = NULL,
GString userPassword = NULL 
)

Definition at line 99 of file PDFDoc.cc.

                                     {
  ok = gFalse;
  errCode = errNone;
  fileName = NULL;
  file = NULL;
  str = strA;
  xref = NULL;
  catalog = NULL;
  links = NULL;
#ifndef DISABLE_OUTLINE
  outline = NULL;
#endif
  ok = setup(ownerPassword, userPassword);
}

Here is the call graph for this function:

Definition at line 146 of file PDFDoc.cc.

                {
#ifndef DISABLE_OUTLINE
  if (outline) {
    delete outline;
  }
#endif
  if (catalog) {
    delete catalog;
  }
  if (xref) {
    delete xref;
  }
  if (str) {
    delete str;
  }
  if (file) {
    fclose(file);
  }
  if (fileName) {
    delete fileName;
  }
  if (links) {
    delete links;
  }
}

Member Function Documentation

void PDFDoc::checkHeader ( ) [private]

Definition at line 174 of file PDFDoc.cc.

                         {
  char hdrBuf[headerSearchSize+1];
  char *p;
  int i;

  pdfVersion = 0;
  for (i = 0; i < headerSearchSize; ++i) {
    hdrBuf[i] = str->getChar();
  }
  hdrBuf[headerSearchSize] = '\0';
  for (i = 0; i < headerSearchSize - 5; ++i) {
    if (!strncmp(&hdrBuf[i], "%PDF-", 5)) {
      break;
    }
  }
  if (i >= headerSearchSize - 5) {
    error(-1, "May not be a PDF file (continuing anyway)");
    return;
  }
  str->moveStart(i);
  p = strtok(&hdrBuf[i+5], " \t\n\r");
  pdfVersion = atof(p);
  if (!(hdrBuf[i+5] >= '0' && hdrBuf[i+5] <= '9') ||
      pdfVersion > supportedPDFVersionNum + 0.0001) {
    error(-1, "PDF version %s -- xpdf supports version %s"
         " (continuing anyway)", p, supportedPDFVersionStr);
  }
}

Here is the call graph for this function:

Here is the caller graph for this function:

void PDFDoc::displayPage ( OutputDev out,
int  page,
double  hDPI,
double  vDPI,
int  rotate,
GBool  crop,
GBool  doLinks,
GBool(*)(void *data abortCheckCbk = NULL,
void abortCheckCbkData = NULL 
)

Definition at line 203 of file PDFDoc.cc.

                                               {
  Page *p;

  if (globalParams->getPrintCommands()) {
    printf("***** page %d *****\n", page);
  }
  p = catalog->getPage(page);
  if (doLinks) {
    if (links) {
      delete links;
    }
    getLinks(p);
    p->display(out, hDPI, vDPI, rotate, crop, links, catalog,
              abortCheckCbk, abortCheckCbkData);
  } else {
    p->display(out, hDPI, vDPI, rotate, crop, NULL, catalog,
              abortCheckCbk, abortCheckCbkData);
  }
}

Here is the call graph for this function:

Here is the caller graph for this function:

void PDFDoc::displayPages ( OutputDev out,
int  firstPage,
int  lastPage,
double  hDPI,
double  vDPI,
int  rotate,
GBool  crop,
GBool  doLinks,
GBool(*)(void *data abortCheckCbk = NULL,
void abortCheckCbkData = NULL 
)

Definition at line 226 of file PDFDoc.cc.

                                                {
  int page;

  for (page = firstPage; page <= lastPage; ++page) {
    displayPage(out, page, hDPI, vDPI, rotate, crop, doLinks,
              abortCheckCbk, abortCheckCbkData);
  }
}

Here is the call graph for this function:

void PDFDoc::displayPageSlice ( OutputDev out,
int  page,
double  hDPI,
double  vDPI,
int  rotate,
GBool  crop,
int  sliceX,
int  sliceY,
int  sliceW,
int  sliceH,
GBool(*)(void *data abortCheckCbk = NULL,
void abortCheckCbkData = NULL 
)

Definition at line 239 of file PDFDoc.cc.

                                                    {
  Page *p;

  p = catalog->getPage(page);
  p->displaySlice(out, hDPI, vDPI, rotate, crop,
                sliceX, sliceY, sliceW, sliceH,
                NULL, catalog, abortCheckCbk, abortCheckCbkData);
}

Here is the call graph for this function:

LinkDest* PDFDoc::findDest ( GString name) [inline]

Definition at line 116 of file PDFDoc.h.

    { return catalog->findDest(name); }

Here is the call graph for this function:

Here is the caller graph for this function:

LinkAction* PDFDoc::findLink ( double  x,
double  y 
) [inline]

Definition at line 108 of file PDFDoc.h.

    { return links ? links->find(x, y) : (LinkAction *)NULL; }

Here is the call graph for this function:

int PDFDoc::findPage ( int  num,
int  gen 
) [inline]

Definition at line 104 of file PDFDoc.h.

{ return catalog->findPage(num, gen); }

Here is the call graph for this function:

Definition at line 61 of file PDFDoc.h.

{ return str; }
Catalog* PDFDoc::getCatalog ( ) [inline]

Definition at line 58 of file PDFDoc.h.

{ return catalog; }

Here is the caller graph for this function:

Object* PDFDoc::getDocInfo ( Object obj) [inline]

Definition at line 141 of file PDFDoc.h.

{ return xref->getDocInfo(obj); }

Here is the call graph for this function:

Object* PDFDoc::getDocInfoNF ( Object obj) [inline]

Definition at line 142 of file PDFDoc.h.

{ return xref->getDocInfoNF(obj); }

Here is the call graph for this function:

Here is the caller graph for this function:

int PDFDoc::getErrorCode ( ) [inline]

Definition at line 49 of file PDFDoc.h.

{ return errCode; }

Definition at line 52 of file PDFDoc.h.

{ return fileName; }
void PDFDoc::getLinks ( Page page) [private]

Definition at line 300 of file PDFDoc.cc.

                                {
  Object obj;

  links = new Links(page->getAnnots(&obj), catalog->getBaseURI());
  obj.free();
}

Here is the call graph for this function:

Here is the caller graph for this function:

int PDFDoc::getNumPages ( ) [inline]

Definition at line 72 of file PDFDoc.h.

{ return catalog->getNumPages(); }

Here is the call graph for this function:

Outline* PDFDoc::getOutline ( ) [inline]

Definition at line 121 of file PDFDoc.h.

{ return outline; }
double PDFDoc::getPageHeight ( int  page) [inline]

Definition at line 66 of file PDFDoc.h.

    { return catalog->getPage(page)->getHeight(); }

Here is the call graph for this function:

int PDFDoc::getPageRotate ( int  page) [inline]

Definition at line 68 of file PDFDoc.h.

    { return catalog->getPage(page)->getRotate(); }

Here is the call graph for this function:

double PDFDoc::getPageWidth ( int  page) [inline]

Definition at line 64 of file PDFDoc.h.

    { return catalog->getPage(page)->getWidth(); }

Here is the call graph for this function:

double PDFDoc::getPDFVersion ( ) [inline]

Definition at line 145 of file PDFDoc.h.

{ return pdfVersion; }

Here is the caller graph for this function:

Definition at line 79 of file PDFDoc.h.

{ return catalog->getStructTreeRoot(); }

Here is the call graph for this function:

XRef* PDFDoc::getXRef ( ) [inline]

Definition at line 55 of file PDFDoc.h.

{ return xref; }

Here is the caller graph for this function:

GBool PDFDoc::isEncrypted ( ) [inline]

Definition at line 125 of file PDFDoc.h.

{ return xref->isEncrypted(); }

Here is the call graph for this function:

Definition at line 253 of file PDFDoc.cc.

                           {
  Parser *parser;
  Object obj1, obj2, obj3, obj4, obj5;
  GBool lin;

  lin = gFalse;
  obj1.initNull();
  parser = new Parser(xref,
            new Lexer(xref,
              str->makeSubStream(str->getStart(), gFalse, 0, &obj1)));
  parser->getObj(&obj1);
  parser->getObj(&obj2);
  parser->getObj(&obj3);
  parser->getObj(&obj4);
  if (obj1.isInt() && obj2.isInt() && obj3.isCmd("obj") &&
      obj4.isDict()) {
    obj4.dictLookup("Linearized", &obj5);
    if (obj5.isNum() && obj5.getNum() > 0) {
      lin = gTrue;
    }
    obj5.free();
  }
  obj4.free();
  obj3.free();
  obj2.free();
  obj1.free();
  delete parser;
  return lin;
}

Here is the call graph for this function:

GBool PDFDoc::isOk ( ) [inline]

Definition at line 46 of file PDFDoc.h.

{ return ok; }

Here is the caller graph for this function:

GBool PDFDoc::okToAddNotes ( GBool  ignoreOwnerPW = gFalse) [inline]

Definition at line 134 of file PDFDoc.h.

    { return xref->okToAddNotes(ignoreOwnerPW); }

Here is the call graph for this function:

GBool PDFDoc::okToChange ( GBool  ignoreOwnerPW = gFalse) [inline]

Definition at line 130 of file PDFDoc.h.

    { return xref->okToChange(ignoreOwnerPW); }

Here is the call graph for this function:

GBool PDFDoc::okToCopy ( GBool  ignoreOwnerPW = gFalse) [inline]

Definition at line 132 of file PDFDoc.h.

    { return xref->okToCopy(ignoreOwnerPW); }

Here is the call graph for this function:

GBool PDFDoc::okToPrint ( GBool  ignoreOwnerPW = gFalse) [inline]

Definition at line 128 of file PDFDoc.h.

    { return xref->okToPrint(ignoreOwnerPW); }

Here is the call graph for this function:

Here is the caller graph for this function:

GBool PDFDoc::onLink ( double  x,
double  y 
) [inline]

Definition at line 112 of file PDFDoc.h.

{ return links->onLink(x, y); }

Here is the call graph for this function:

Definition at line 76 of file PDFDoc.h.

{ return catalog->readMetadata(); }

Here is the call graph for this function:

Definition at line 283 of file PDFDoc.cc.

                                  {
  FILE *f;
  int c;

  if (!(f = fopen(name->getCString(), "wb"))) {
    error(-1, "Couldn't open file '%s'", name->getCString());
    return gFalse;
  }
  str->reset();
  while ((c = str->getChar()) != EOF) {
    fputc(c, f);
  }
  str->close();
  fclose(f);
  return gTrue;
}

Here is the call graph for this function:

GBool PDFDoc::setup ( GString ownerPassword,
GString userPassword 
) [private]

Definition at line 115 of file PDFDoc.cc.

                                                                 {
  str->reset();

  // check header
  checkHeader();

  // read xref table
  xref = new XRef(str, ownerPassword, userPassword);
  if (!xref->isOk()) {
    error(-1, "Couldn't read xref table");
    errCode = xref->getErrorCode();
    return gFalse;
  }

  // read catalog
  catalog = new Catalog(xref);
  if (!catalog->isOk()) {
    error(-1, "Couldn't read page catalog");
    errCode = errBadCatalog;
    return gFalse;
  }

#ifndef DISABLE_OUTLINE
  // read outline
  outline = new Outline(catalog->getOutline(), xref);
#endif

  // done
  return gTrue;
}

Here is the call graph for this function:

Here is the caller graph for this function:


Member Data Documentation

Definition at line 162 of file PDFDoc.h.

int PDFDoc::errCode [private]

Definition at line 170 of file PDFDoc.h.

FILE* PDFDoc::file [private]

Definition at line 158 of file PDFDoc.h.

Definition at line 157 of file PDFDoc.h.

Links* PDFDoc::links [private]

Definition at line 163 of file PDFDoc.h.

GBool PDFDoc::ok [private]

Definition at line 169 of file PDFDoc.h.

Definition at line 165 of file PDFDoc.h.

double PDFDoc::pdfVersion [private]

Definition at line 160 of file PDFDoc.h.

BaseStream* PDFDoc::str [private]

Definition at line 159 of file PDFDoc.h.

XRef* PDFDoc::xref [private]

Definition at line 161 of file PDFDoc.h.


The documentation for this class was generated from the following files: