"Fossies" - the Fresh Open Source Software Archive

Member "xpdf-4.04/xpdf/PDFDoc.h" (18 Apr 2022, 6774 Bytes) of package /linux/misc/xpdf-4.04.tar.gz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) C and C++ source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file. For more information about "PDFDoc.h" see the Fossies "Dox" file reference documentation and the latest Fossies "Diffs" side-by-side code changes report: 4.03_vs_4.04.

    1 //========================================================================
    2 //
    3 // PDFDoc.h
    4 //
    5 // Copyright 1996-2003 Glyph & Cog, LLC
    6 //
    7 //========================================================================
    8 
    9 #ifndef PDFDOC_H
   10 #define PDFDOC_H
   11 
   12 #include <aconf.h>
   13 
   14 #ifdef USE_GCC_PRAGMAS
   15 #pragma interface
   16 #endif
   17 
   18 #include <stdio.h>
   19 #include "XRef.h"
   20 #include "Catalog.h"
   21 #include "Page.h"
   22 
   23 class GString;
   24 class BaseStream;
   25 class OutputDev;
   26 class Links;
   27 class LinkAction;
   28 class LinkDest;
   29 class Outline;
   30 class OutlineItem;
   31 class OptionalContent;
   32 class PDFCore;
   33 
   34 //------------------------------------------------------------------------
   35 // PDFDoc
   36 //------------------------------------------------------------------------
   37 
   38 class PDFDoc {
   39 public:
   40 
   41   PDFDoc(GString *fileNameA, GString *ownerPassword = NULL,
   42      GString *userPassword = NULL, PDFCore *coreA = NULL);
   43 
   44 #ifdef _WIN32
   45   PDFDoc(wchar_t *fileNameA, int fileNameLen, GString *ownerPassword = NULL,
   46      GString *userPassword = NULL, PDFCore *coreA = NULL);
   47 #endif
   48 
   49   // This version takes a UTF-8 file name (which is only relevant on
   50   // Windows).
   51   PDFDoc(char *fileNameA, GString *ownerPassword = NULL,
   52      GString *userPassword = NULL, PDFCore *coreA = NULL);
   53 
   54   PDFDoc(BaseStream *strA, GString *ownerPassword = NULL,
   55      GString *userPassword = NULL, PDFCore *coreA = NULL);
   56 
   57   ~PDFDoc();
   58 
   59   // Was PDF document successfully opened?
   60   GBool isOk() { return ok; }
   61 
   62   // Get the error code (if isOk() returns false).
   63   int getErrorCode() { return errCode; }
   64 
   65   // Get file name.
   66   GString *getFileName() { return fileName; }
   67 #ifdef _WIN32
   68   wchar_t *getFileNameU() { return fileNameU; }
   69 #endif
   70 
   71   // Get the xref table.
   72   XRef *getXRef() { return xref; }
   73 
   74   // Get catalog.
   75   Catalog *getCatalog() { return catalog; }
   76 
   77   // Get base stream.
   78   BaseStream *getBaseStream() { return str; }
   79 
   80   // Get page parameters.
   81   double getPageMediaWidth(int page)
   82     { return catalog->getPage(page)->getMediaWidth(); }
   83   double getPageMediaHeight(int page)
   84     { return catalog->getPage(page)->getMediaHeight(); }
   85   double getPageCropWidth(int page)
   86     { return catalog->getPage(page)->getCropWidth(); }
   87   double getPageCropHeight(int page)
   88     { return catalog->getPage(page)->getCropHeight(); }
   89   int getPageRotate(int page)
   90     { return catalog->getPage(page)->getRotate(); }
   91 
   92   // Get number of pages.
   93   int getNumPages() { return catalog->getNumPages(); }
   94 
   95   // Return the contents of the metadata stream, or NULL if there is
   96   // no metadata.
   97   GString *readMetadata() { return catalog->readMetadata(); }
   98 
   99   // Return the structure tree root object.
  100   Object *getStructTreeRoot() { return catalog->getStructTreeRoot(); }
  101 
  102   // Display a page.
  103   void displayPage(OutputDev *out, int page,
  104            double hDPI, double vDPI, int rotate,
  105            GBool useMediaBox, GBool crop, GBool printing,
  106            GBool (*abortCheckCbk)(void *data) = NULL,
  107            void *abortCheckCbkData = NULL);
  108 
  109   // Display a range of pages.
  110   void displayPages(OutputDev *out, int firstPage, int lastPage,
  111             double hDPI, double vDPI, int rotate,
  112             GBool useMediaBox, GBool crop, GBool printing,
  113             GBool (*abortCheckCbk)(void *data) = NULL,
  114             void *abortCheckCbkData = NULL);
  115 
  116   // Display part of a page.
  117   void displayPageSlice(OutputDev *out, int page,
  118             double hDPI, double vDPI, int rotate,
  119             GBool useMediaBox, GBool crop, GBool printing,
  120             int sliceX, int sliceY, int sliceW, int sliceH,
  121             GBool (*abortCheckCbk)(void *data) = NULL,
  122             void *abortCheckCbkData = NULL);
  123 
  124   // Find a page, given its object ID.  Returns page number, or 0 if
  125   // not found.
  126   int findPage(int num, int gen) { return catalog->findPage(num, gen); }
  127 
  128   // Returns the links for the current page, transferring ownership to
  129   // the caller.
  130   Links *getLinks(int page);
  131 
  132   // Find a named destination.  Returns the link destination, or
  133   // NULL if <name> is not a destination.
  134   LinkDest *findDest(GString *name)
  135     { return catalog->findDest(name); }
  136 
  137   // Process the links for a page.
  138   void processLinks(OutputDev *out, int page);
  139 
  140 #ifndef DISABLE_OUTLINE
  141   // Return the outline object.
  142   Outline *getOutline() { return outline; }
  143 
  144   // Return the target page number for an outline item.  Returns 0 if
  145   // the item doesn't target a page in this PDF file.
  146   int getOutlineTargetPage(OutlineItem *outlineItem);
  147 #endif
  148 
  149   // Return the OptionalContent object.
  150   OptionalContent *getOptionalContent() { return optContent; }
  151 
  152   // Is the file encrypted?
  153   GBool isEncrypted() { return xref->isEncrypted(); }
  154 
  155   // Check various permissions.
  156   GBool okToPrint(GBool ignoreOwnerPW = gFalse)
  157     { return xref->okToPrint(ignoreOwnerPW); }
  158   GBool okToChange(GBool ignoreOwnerPW = gFalse)
  159     { return xref->okToChange(ignoreOwnerPW); }
  160   GBool okToCopy(GBool ignoreOwnerPW = gFalse)
  161     { return xref->okToCopy(ignoreOwnerPW); }
  162   GBool okToAddNotes(GBool ignoreOwnerPW = gFalse)
  163     { return xref->okToAddNotes(ignoreOwnerPW); }
  164 
  165   // Is the PDF file damaged?  This checks to see if the xref table
  166   // was constructed by the repair code.
  167   GBool isDamaged() { return xref->isRepaired(); }
  168 
  169   // Is this document linearized?
  170   GBool isLinearized();
  171 
  172   // Return the document's Info dictionary (if any).
  173   Object *getDocInfo(Object *obj) { return xref->getDocInfo(obj); }
  174   Object *getDocInfoNF(Object *obj) { return xref->getDocInfoNF(obj); }
  175 
  176   // Return the PDF version specified by the file.
  177   double getPDFVersion() { return pdfVersion; }
  178 
  179   // Save this file with another name.
  180   GBool saveAs(GString *name);
  181 
  182   // Return a pointer to the PDFCore object.
  183   PDFCore *getCore() { return core; }
  184 
  185   // Get the list of embedded files.
  186   int getNumEmbeddedFiles() { return catalog->getNumEmbeddedFiles(); }
  187   Unicode *getEmbeddedFileName(int idx)
  188     { return catalog->getEmbeddedFileName(idx); }
  189   int getEmbeddedFileNameLength(int idx)
  190     { return catalog->getEmbeddedFileNameLength(idx); }
  191   GBool saveEmbeddedFile(int idx, const char *path);
  192   GBool saveEmbeddedFileU(int idx, const char *path);
  193 #ifdef _WIN32
  194   GBool saveEmbeddedFile(int idx, const wchar_t *path, int pathLen);
  195 #endif
  196   char *getEmbeddedFileMem(int idx, int *size);
  197 
  198 
  199 private:
  200 
  201   void init(PDFCore *coreA);
  202   GBool setup(GString *ownerPassword, GString *userPassword);
  203   GBool setup2(GString *ownerPassword, GString *userPassword,
  204            GBool repairXRef);
  205   void checkHeader();
  206   GBool checkEncryption(GString *ownerPassword, GString *userPassword);
  207   GBool saveEmbeddedFile2(int idx, FILE *f);
  208 
  209   GString *fileName;
  210 #ifdef _WIN32
  211   wchar_t *fileNameU;
  212 #endif
  213   FILE *file;
  214   BaseStream *str;
  215   PDFCore *core;
  216   double pdfVersion;
  217   XRef *xref;
  218   Catalog *catalog;
  219 #ifndef DISABLE_OUTLINE
  220   Outline *outline;
  221 #endif
  222   OptionalContent *optContent;
  223 
  224   GBool ok;
  225   int errCode;
  226 };
  227 
  228 #endif