]> git.ipfire.org Git - thirdparty/cups.git/blame - pdftops/PDFDoc.h
Merge changes from CUPS 1.4svn-r7199.
[thirdparty/cups.git] / pdftops / PDFDoc.h
CommitLineData
ef416fc2 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 <config.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
23class GString;
24class BaseStream;
25class OutputDev;
26class Links;
27class LinkAction;
28class LinkDest;
29class Outline;
30
31//------------------------------------------------------------------------
32// PDFDoc
33//------------------------------------------------------------------------
34
35class PDFDoc {
36public:
37
38 PDFDoc(GString *fileNameA, GString *ownerPassword = NULL,
39 GString *userPassword = NULL, void *guiDataA = NULL);
40#ifdef WIN32
41 PDFDoc(wchar_t *fileNameA, int fileNameLen, GString *ownerPassword = NULL,
42 GString *userPassword = NULL, void *guiDataA = NULL);
43#endif
44 PDFDoc(BaseStream *strA, GString *ownerPassword = NULL,
45 GString *userPassword = NULL, void *guiDataA = NULL);
46 ~PDFDoc();
47
48 // Was PDF document successfully opened?
49 GBool isOk() { return ok; }
50
51 // Get the error code (if isOk() returns false).
52 int getErrorCode() { return errCode; }
53
54 // Get file name.
55 GString *getFileName() { return fileName; }
56
57 // Get the xref table.
58 XRef *getXRef() { return xref; }
59
60 // Get catalog.
61 Catalog *getCatalog() { return catalog; }
62
63 // Get base stream.
64 BaseStream *getBaseStream() { return str; }
65
66 // Get page parameters.
67 double getPageMediaWidth(int page)
68 { return catalog->getPage(page)->getMediaWidth(); }
69 double getPageMediaHeight(int page)
70 { return catalog->getPage(page)->getMediaHeight(); }
71 double getPageCropWidth(int page)
72 { return catalog->getPage(page)->getCropWidth(); }
73 double getPageCropHeight(int page)
74 { return catalog->getPage(page)->getCropHeight(); }
75 int getPageRotate(int page)
76 { return catalog->getPage(page)->getRotate(); }
77
78 // Get number of pages.
79 int getNumPages() { return catalog->getNumPages(); }
80
81 // Return the contents of the metadata stream, or NULL if there is
82 // no metadata.
83 GString *readMetadata() { return catalog->readMetadata(); }
84
85 // Return the structure tree root object.
86 Object *getStructTreeRoot() { return catalog->getStructTreeRoot(); }
87
88 // Display a page.
89 void displayPage(OutputDev *out, int page, double hDPI, double vDPI,
90 int rotate, GBool useMediaBox, GBool crop,
91 GBool doLinks,
92 GBool (*abortCheckCbk)(void *data) = NULL,
93 void *abortCheckCbkData = NULL);
94
95 // Display a range of pages.
96 void displayPages(OutputDev *out, int firstPage, int lastPage,
97 double hDPI, double vDPI, int rotate,
98 GBool useMediaBox, GBool crop, GBool doLinks,
99 GBool (*abortCheckCbk)(void *data) = NULL,
100 void *abortCheckCbkData = NULL);
101
102 // Display part of a page.
103 void displayPageSlice(OutputDev *out, int page,
104 double hDPI, double vDPI, int rotate,
105 GBool useMediaBox, GBool crop, GBool doLinks,
106 int sliceX, int sliceY, int sliceW, int sliceH,
107 GBool (*abortCheckCbk)(void *data) = NULL,
108 void *abortCheckCbkData = NULL);
109
110 // Find a page, given its object ID. Returns page number, or 0 if
111 // not found.
112 int findPage(int num, int gen) { return catalog->findPage(num, gen); }
113
114 // Returns the links for the current page, transferring ownership to
115 // the caller.
116 Links *takeLinks();
117
118 // Find a named destination. Returns the link destination, or
119 // NULL if <name> is not a destination.
120 LinkDest *findDest(GString *name)
121 { return catalog->findDest(name); }
122
123#ifndef DISABLE_OUTLINE
124 // Return the outline object.
125 Outline *getOutline() { return outline; }
126#endif
127
128 // Is the file encrypted?
129 GBool isEncrypted() { return xref->isEncrypted(); }
130
131 // Check various permissions.
132 GBool okToPrint(GBool ignoreOwnerPW = gFalse)
133 { return xref->okToPrint(ignoreOwnerPW); }
134 GBool okToChange(GBool ignoreOwnerPW = gFalse)
135 { return xref->okToChange(ignoreOwnerPW); }
136 GBool okToCopy(GBool ignoreOwnerPW = gFalse)
137 { return xref->okToCopy(ignoreOwnerPW); }
138 GBool okToAddNotes(GBool ignoreOwnerPW = gFalse)
139 { return xref->okToAddNotes(ignoreOwnerPW); }
140
141 // Is this document linearized?
142 GBool isLinearized();
143
144 // Return the document's Info dictionary (if any).
145 Object *getDocInfo(Object *obj) { return xref->getDocInfo(obj); }
146 Object *getDocInfoNF(Object *obj) { return xref->getDocInfoNF(obj); }
147
148 // Return the PDF version specified by the file.
149 double getPDFVersion() { return pdfVersion; }
150
151 // Save this file with another name.
152 GBool saveAs(GString *name);
153
154 // Return a pointer to the GUI (XPDFCore or WinPDFCore object).
155 void *getGUIData() { return guiData; }
156
157
158private:
159
160 GBool setup(GString *ownerPassword, GString *userPassword);
161 void checkHeader();
162 GBool checkEncryption(GString *ownerPassword, GString *userPassword);
163 void getLinks(Page *page);
164
165 GString *fileName;
166 FILE *file;
167 BaseStream *str;
168 void *guiData;
169 double pdfVersion;
170 XRef *xref;
171 Catalog *catalog;
172 Links *links;
173#ifndef DISABLE_OUTLINE
174 Outline *outline;
175#endif
176
177
178 GBool ok;
179 int errCode;
180};
181
182#endif