upgrade to xpdf 3.00.
[swftools.git] / pdf2swf / xpdf / PDFDoc.h
blobbdcbd65d8694ea56b6c606b18283953b8d7cebe5
1 //========================================================================
2 //
3 // PDFDoc.h
4 //
5 // Copyright 1996-2003 Glyph & Cog, LLC
6 //
7 //========================================================================
9 #ifndef PDFDOC_H
10 #define PDFDOC_H
12 #include <aconf.h>
14 #ifdef USE_GCC_PRAGMAS
15 #pragma interface
16 #endif
18 #include <stdio.h>
19 #include "XRef.h"
20 #include "Link.h"
21 #include "Catalog.h"
22 #include "Page.h"
24 class GString;
25 class BaseStream;
26 class OutputDev;
27 class Links;
28 class LinkAction;
29 class LinkDest;
30 class Outline;
32 //------------------------------------------------------------------------
33 // PDFDoc
34 //------------------------------------------------------------------------
36 class PDFDoc {
37 public:
39 PDFDoc(GString *fileNameA, GString *ownerPassword = NULL,
40 GString *userPassword = NULL);
41 PDFDoc(BaseStream *strA, GString *ownerPassword = NULL,
42 GString *userPassword = NULL);
43 ~PDFDoc();
45 // Was PDF document successfully opened?
46 GBool isOk() { return ok; }
48 // Get the error code (if isOk() returns false).
49 int getErrorCode() { return errCode; }
51 // Get file name.
52 GString *getFileName() { return fileName; }
54 // Get the xref table.
55 XRef *getXRef() { return xref; }
57 // Get catalog.
58 Catalog *getCatalog() { return catalog; }
60 // Get base stream.
61 BaseStream *getBaseStream() { return str; }
63 // Get page parameters.
64 double getPageWidth(int page)
65 { return catalog->getPage(page)->getWidth(); }
66 double getPageHeight(int page)
67 { return catalog->getPage(page)->getHeight(); }
68 int getPageRotate(int page)
69 { return catalog->getPage(page)->getRotate(); }
71 // Get number of pages.
72 int getNumPages() { return catalog->getNumPages(); }
74 // Return the contents of the metadata stream, or NULL if there is
75 // no metadata.
76 GString *readMetadata() { return catalog->readMetadata(); }
78 // Return the structure tree root object.
79 Object *getStructTreeRoot() { return catalog->getStructTreeRoot(); }
81 // Display a page.
82 void displayPage(OutputDev *out, int page, double hDPI, double vDPI,
83 int rotate, GBool crop, GBool doLinks,
84 GBool (*abortCheckCbk)(void *data) = NULL,
85 void *abortCheckCbkData = NULL);
87 // Display a range of pages.
88 void displayPages(OutputDev *out, int firstPage, int lastPage,
89 double hDPI, double vDPI, int rotate,
90 GBool crop, GBool doLinks,
91 GBool (*abortCheckCbk)(void *data) = NULL,
92 void *abortCheckCbkData = NULL);
94 // Display part of a page.
95 void displayPageSlice(OutputDev *out, int page,
96 double hDPI, double vDPI,
97 int rotate, GBool crop,
98 int sliceX, int sliceY, int sliceW, int sliceH,
99 GBool (*abortCheckCbk)(void *data) = NULL,
100 void *abortCheckCbkData = NULL);
102 // Find a page, given its object ID. Returns page number, or 0 if
103 // not found.
104 int findPage(int num, int gen) { return catalog->findPage(num, gen); }
106 // If point <x>,<y> is in a link, return the associated action;
107 // else return NULL.
108 LinkAction *findLink(double x, double y)
109 { return links ? links->find(x, y) : (LinkAction *)NULL; }
111 // Return true if <x>,<y> is in a link.
112 GBool onLink(double x, double y) { return links->onLink(x, y); }
114 // Find a named destination. Returns the link destination, or
115 // NULL if <name> is not a destination.
116 LinkDest *findDest(GString *name)
117 { return catalog->findDest(name); }
119 #ifndef DISABLE_OUTLINE
120 // Return the outline object.
121 Outline *getOutline() { return outline; }
122 #endif
124 // Is the file encrypted?
125 GBool isEncrypted() { return xref->isEncrypted(); }
127 // Check various permissions.
128 GBool okToPrint(GBool ignoreOwnerPW = gFalse)
129 { return xref->okToPrint(ignoreOwnerPW); }
130 GBool okToChange(GBool ignoreOwnerPW = gFalse)
131 { return xref->okToChange(ignoreOwnerPW); }
132 GBool okToCopy(GBool ignoreOwnerPW = gFalse)
133 { return xref->okToCopy(ignoreOwnerPW); }
134 GBool okToAddNotes(GBool ignoreOwnerPW = gFalse)
135 { return xref->okToAddNotes(ignoreOwnerPW); }
137 // Is this document linearized?
138 GBool isLinearized();
140 // Return the document's Info dictionary (if any).
141 Object *getDocInfo(Object *obj) { return xref->getDocInfo(obj); }
142 Object *getDocInfoNF(Object *obj) { return xref->getDocInfoNF(obj); }
144 // Return the PDF version specified by the file.
145 double getPDFVersion() { return pdfVersion; }
147 // Save this file with another name.
148 GBool saveAs(GString *name);
151 private:
153 GBool setup(GString *ownerPassword, GString *userPassword);
154 void checkHeader();
155 void getLinks(Page *page);
157 GString *fileName;
158 FILE *file;
159 BaseStream *str;
160 double pdfVersion;
161 XRef *xref;
162 Catalog *catalog;
163 Links *links;
164 #ifndef DISABLE_OUTLINE
165 Outline *outline;
166 #endif
169 GBool ok;
170 int errCode;
173 #endif