c12531e9387c76bf7c89c9a8e146cb1e9e5500e8
[swftools.git] / pdf2swf / xpdf / PDFDoc.h
1 //========================================================================
2 //
3 // PDFDoc.h
4 //
5 // Copyright 1996-2002 Glyph & Cog, LLC
6 //
7 //========================================================================
8
9 #ifndef PDFDOC_H
10 #define PDFDOC_H
11
12 #ifdef __GNUC__
13 #pragma interface
14 #endif
15
16 #include <stdio.h>
17 #include "XRef.h"
18 #include "Link.h"
19 #include "Catalog.h"
20 #include "Page.h"
21
22 class GString;
23 class BaseStream;
24 class OutputDev;
25 class Links;
26 class LinkAction;
27 class LinkDest;
28
29 //------------------------------------------------------------------------
30 // PDFDoc
31 //------------------------------------------------------------------------
32
33 class PDFDoc {
34 public:
35
36   PDFDoc(GString *fileNameA, GString *ownerPassword = NULL,
37          GString *userPassword = NULL, GBool printCommandsA = gFalse);
38   PDFDoc(BaseStream *strA, GString *ownerPassword = NULL,
39          GString *userPassword = NULL, GBool printCommandsA = gFalse);
40   ~PDFDoc();
41
42   // Was PDF document successfully opened?
43   GBool isOk() { return ok; }
44
45   // Get the error code (if isOk() returns false).
46   int getErrorCode() { return errCode; }
47
48   // Get file name.
49   GString *getFileName() { return fileName; }
50
51   // Get the xref table.
52   XRef *getXRef() { return xref; }
53
54   // Get catalog.
55   Catalog *getCatalog() { return catalog; }
56
57   // Get base stream.
58   BaseStream *getBaseStream() { return str; }
59
60   // Get page parameters.
61   double getPageWidth(int page)
62     { return catalog->getPage(page)->getWidth(); }
63   double getPageHeight(int page)
64     { return catalog->getPage(page)->getHeight(); }
65   int getPageRotate(int page)
66     { return catalog->getPage(page)->getRotate(); }
67
68   // Get number of pages.
69   int getNumPages() { return catalog->getNumPages(); }
70
71   // Return the contents of the metadata stream, or NULL if there is
72   // no metadata.
73   GString *readMetadata() { return catalog->readMetadata(); }
74
75   // Return the structure tree root object.
76   Object *getStructTreeRoot() { return catalog->getStructTreeRoot(); }
77
78   // Display a page.
79   void displayPage(OutputDev *out, int page, double zoom,
80                    int rotate, GBool doLinks);
81
82   // Display a range of pages.
83   void displayPages(OutputDev *out, int firstPage, int lastPage,
84                     int zoom, int rotate, GBool doLinks);
85
86   // Find a page, given its object ID.  Returns page number, or 0 if
87   // not found.
88   int findPage(int num, int gen) { return catalog->findPage(num, gen); }
89
90   // If point <x>,<y> is in a link, return the associated action;
91   // else return NULL.
92   LinkAction *findLink(double x, double y) { return links->find(x, y); }
93
94   // Return true if <x>,<y> is in a link.
95   GBool onLink(double x, double y) { return links->onLink(x, y); }
96
97   // Find a named destination.  Returns the link destination, or
98   // NULL if <name> is not a destination.
99   LinkDest *findDest(GString *name)
100     { return catalog->findDest(name); }
101
102   // Is the file encrypted?
103   GBool isEncrypted() { return xref->isEncrypted(); }
104
105   // Check various permissions.
106   GBool okToPrint(GBool ignoreOwnerPW = gFalse)
107     { return xref->okToPrint(ignoreOwnerPW); }
108   GBool okToChange(GBool ignoreOwnerPW = gFalse)
109     { return xref->okToChange(ignoreOwnerPW); }
110   GBool okToCopy(GBool ignoreOwnerPW = gFalse)
111     { return xref->okToCopy(ignoreOwnerPW); }
112   GBool okToAddNotes(GBool ignoreOwnerPW = gFalse)
113     { return xref->okToAddNotes(ignoreOwnerPW); }
114
115   // Is this document linearized?
116   GBool isLinearized();
117
118   // Return the document's Info dictionary (if any).
119   Object *getDocInfo(Object *obj) { return xref->getDocInfo(obj); }
120
121   // Return the PDF version specified by the file.
122   double getPDFVersion() { return pdfVersion; }
123
124   // Save this file with another name.
125   GBool saveAs(GString *name);
126
127 private:
128
129   GBool setup(GString *ownerPassword, GString *userPassword);
130   void checkHeader();
131   void getLinks(Page *page);
132
133   GString *fileName;
134   FILE *file;
135   BaseStream *str;
136   double pdfVersion;
137   XRef *xref;
138   Catalog *catalog;
139   Links *links;
140   GBool printCommands;
141
142   GBool ok;
143   int errCode;
144 };
145
146 #endif