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