filters

PDFDoc.h

00001 //========================================================================
00002 //
00003 // PDFDoc.h
00004 //
00005 // Copyright 1996-2002 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 zoom,
00083            int rotate, 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             int zoom, int rotate, GBool doLinks,
00090             GBool (*abortCheckCbk)(void *data) = NULL,
00091             void *abortCheckCbkData = NULL);
00092 
00093   // Display part of a page.
00094   void displayPageSlice(OutputDev *out, int page, double zoom,
00095             int rotate, int sliceX, int sliceY,
00096             int sliceW, int sliceH,
00097             GBool (*abortCheckCbk)(void *data) = NULL,
00098             void *abortCheckCbkData = NULL);
00099 
00100   // Find a page, given its object ID.  Returns page number, or 0 if
00101   // not found.
00102   int findPage(int num, int gen) { return catalog->findPage(num, gen); }
00103 
00104   // If point <x>,<y> is in a link, return the associated action;
00105   // else return NULL.
00106   LinkAction *findLink(double x, double y) { return links->find(x, y); }
00107 
00108   // Return true if <x>,<y> is in a link.
00109   GBool onLink(double x, double y) { return links->onLink(x, y); }
00110 
00111   // Find a named destination.  Returns the link destination, or
00112   // NULL if <name> is not a destination.
00113   LinkDest *findDest(GString *name)
00114     { return catalog->findDest(name); }
00115 
00116 #ifndef DISABLE_OUTLINE
00117   // Return the outline object.
00118   Outline *getOutline() { return outline; }
00119 #endif
00120 
00121   // Is the file encrypted?
00122   GBool isEncrypted() { return xref->isEncrypted(); }
00123 
00124   // Check various permissions.
00125   GBool okToPrint(GBool ignoreOwnerPW = gFalse)
00126     { return xref->okToPrint(ignoreOwnerPW); }
00127   GBool okToChange(GBool ignoreOwnerPW = gFalse)
00128     { return xref->okToChange(ignoreOwnerPW); }
00129   GBool okToCopy(GBool ignoreOwnerPW = gFalse)
00130     { return xref->okToCopy(ignoreOwnerPW); }
00131   GBool okToAddNotes(GBool ignoreOwnerPW = gFalse)
00132     { return xref->okToAddNotes(ignoreOwnerPW); }
00133 
00134   // Is this document linearized?
00135   GBool isLinearized();
00136 
00137   // Return the document's Info dictionary (if any).
00138   Object *getDocInfo(Object *obj) { return xref->getDocInfo(obj); }
00139   Object *getDocInfoNF(Object *obj) { return xref->getDocInfoNF(obj); }
00140 
00141   // Return the PDF version specified by the file.
00142   double getPDFVersion() { return pdfVersion; }
00143 
00144   // Save this file with another name.
00145   GBool saveAs(GString *name);
00146 
00147 
00148 private:
00149 
00150   GBool setup(GString *ownerPassword, GString *userPassword);
00151   void checkHeader();
00152   void getLinks(Page *page);
00153 
00154   GString *fileName;
00155   FILE *file;
00156   BaseStream *str;
00157   double pdfVersion;
00158   XRef *xref;
00159   Catalog *catalog;
00160   Links *links;
00161 #ifndef DISABLE_OUTLINE
00162   Outline *outline;
00163 #endif
00164 
00165 
00166   GBool ok;
00167   int errCode;
00168 };
00169 
00170 #endif
KDE Home | KDE Accessibility Home | Description of Access Keys