Back to index

tetex-bin  3.0
PDFDoc.h
Go to the documentation of this file.
00001 //========================================================================
00002 //
00003 // PDFDoc.h
00004 //
00005 // Copyright 1996-2003 Glyph & Cog, LLC
00006 //
00007 //========================================================================
00008 
00009 #ifndef PDFDOC_H
00010 #define PDFDOC_H
00011 
00012 #include <aconf.h>
00013 
00014 #ifdef USE_GCC_PRAGMAS
00015 #pragma interface
00016 #endif
00017 
00018 #include <stdio.h>
00019 #include "XRef.h"
00020 #include "Link.h"
00021 #include "Catalog.h"
00022 #include "Page.h"
00023 
00024 class GString;
00025 class BaseStream;
00026 class OutputDev;
00027 class Links;
00028 class LinkAction;
00029 class LinkDest;
00030 class Outline;
00031 
00032 //------------------------------------------------------------------------
00033 // PDFDoc
00034 //------------------------------------------------------------------------
00035 
00036 class PDFDoc {
00037 public:
00038 
00039   PDFDoc(GString *fileNameA, GString *ownerPassword = NULL,
00040         GString *userPassword = NULL);
00041   PDFDoc(BaseStream *strA, GString *ownerPassword = NULL,
00042         GString *userPassword = NULL);
00043   ~PDFDoc();
00044 
00045   // Was PDF document successfully opened?
00046   GBool isOk() { return ok; }
00047 
00048   // Get the error code (if isOk() returns false).
00049   int getErrorCode() { return errCode; }
00050 
00051   // Get file name.
00052   GString *getFileName() { return fileName; }
00053 
00054   // Get the xref table.
00055   XRef *getXRef() { return xref; }
00056 
00057   // Get catalog.
00058   Catalog *getCatalog() { return catalog; }
00059 
00060   // Get base stream.
00061   BaseStream *getBaseStream() { return str; }
00062 
00063   // Get page parameters.
00064   double getPageWidth(int page)
00065     { return catalog->getPage(page)->getWidth(); }
00066   double getPageHeight(int page)
00067     { return catalog->getPage(page)->getHeight(); }
00068   int getPageRotate(int page)
00069     { return catalog->getPage(page)->getRotate(); }
00070 
00071   // Get number of pages.
00072   int getNumPages() { return catalog->getNumPages(); }
00073 
00074   // Return the contents of the metadata stream, or NULL if there is
00075   // no metadata.
00076   GString *readMetadata() { return catalog->readMetadata(); }
00077 
00078   // Return the structure tree root object.
00079   Object *getStructTreeRoot() { return catalog->getStructTreeRoot(); }
00080 
00081   // Display a page.
00082   void displayPage(OutputDev *out, int page, double hDPI, double vDPI,
00083                  int rotate, GBool crop, GBool doLinks,
00084                  GBool (*abortCheckCbk)(void *data) = NULL,
00085                  void *abortCheckCbkData = NULL);
00086 
00087   // Display a range of pages.
00088   void displayPages(OutputDev *out, int firstPage, int lastPage,
00089                   double hDPI, double vDPI, int rotate,
00090                   GBool crop, GBool doLinks,
00091                   GBool (*abortCheckCbk)(void *data) = NULL,
00092                   void *abortCheckCbkData = NULL);
00093 
00094   // Display part of a page.
00095   void displayPageSlice(OutputDev *out, int page,
00096                      double hDPI, double vDPI,
00097                      int rotate, GBool crop,
00098                      int sliceX, int sliceY, int sliceW, int sliceH,
00099                      GBool (*abortCheckCbk)(void *data) = NULL,
00100                      void *abortCheckCbkData = NULL);
00101 
00102   // Find a page, given its object ID.  Returns page number, or 0 if
00103   // not found.
00104   int findPage(int num, int gen) { return catalog->findPage(num, gen); }
00105 
00106   // If point <x>,<y> is in a link, return the associated action;
00107   // else return NULL.
00108   LinkAction *findLink(double x, double y)
00109     { return links ? links->find(x, y) : (LinkAction *)NULL; }
00110 
00111   // Return true if <x>,<y> is in a link.
00112   GBool onLink(double x, double y) { return links->onLink(x, y); }
00113 
00114   // Find a named destination.  Returns the link destination, or
00115   // NULL if <name> is not a destination.
00116   LinkDest *findDest(GString *name)
00117     { return catalog->findDest(name); }
00118 
00119 #ifndef DISABLE_OUTLINE
00120   // Return the outline object.
00121   Outline *getOutline() { return outline; }
00122 #endif
00123 
00124   // Is the file encrypted?
00125   GBool isEncrypted() { return xref->isEncrypted(); }
00126 
00127   // Check various permissions.
00128   GBool okToPrint(GBool ignoreOwnerPW = gFalse)
00129     { return xref->okToPrint(ignoreOwnerPW); }
00130   GBool okToChange(GBool ignoreOwnerPW = gFalse)
00131     { return xref->okToChange(ignoreOwnerPW); }
00132   GBool okToCopy(GBool ignoreOwnerPW = gFalse)
00133     { return xref->okToCopy(ignoreOwnerPW); }
00134   GBool okToAddNotes(GBool ignoreOwnerPW = gFalse)
00135     { return xref->okToAddNotes(ignoreOwnerPW); }
00136 
00137   // Is this document linearized?
00138   GBool isLinearized();
00139 
00140   // Return the document's Info dictionary (if any).
00141   Object *getDocInfo(Object *obj) { return xref->getDocInfo(obj); }
00142   Object *getDocInfoNF(Object *obj) { return xref->getDocInfoNF(obj); }
00143 
00144   // Return the PDF version specified by the file.
00145   double getPDFVersion() { return pdfVersion; }
00146 
00147   // Save this file with another name.
00148   GBool saveAs(GString *name);
00149 
00150 
00151 private:
00152 
00153   GBool setup(GString *ownerPassword, GString *userPassword);
00154   void checkHeader();
00155   void getLinks(Page *page);
00156 
00157   GString *fileName;
00158   FILE *file;
00159   BaseStream *str;
00160   double pdfVersion;
00161   XRef *xref;
00162   Catalog *catalog;
00163   Links *links;
00164 #ifndef DISABLE_OUTLINE
00165   Outline *outline;
00166 #endif
00167 
00168 
00169   GBool ok;
00170   int errCode;
00171 };
00172 
00173 #endif