source: trunk/poppler/mypoppler/poppler/PDFDoc.h @ 461

Last change on this file since 461 was 461, checked in by Silvan Scherrer, 11 years ago

poppler update to 0.14.2

File size: 8.5 KB
Line 
1//========================================================================
2//
3// PDFDoc.h
4//
5// Copyright 1996-2003 Glyph & Cog, LLC
6//
7//========================================================================
8
9//========================================================================
10//
11// Modified under the Poppler project - http://poppler.freedesktop.org
12//
13// All changes made under the Poppler project to this file are licensed
14// under GPL version 2 or later
15//
16// Copyright (C) 2005, 2006, 2008 Brad Hards <bradh@frogmouth.net>
17// Copyright (C) 2005, 2009 Albert Astals Cid <aacid@kde.org>
18// Copyright (C) 2008 Julien Rebetez <julienr@svn.gnome.org>
19// Copyright (C) 2008 Pino Toscano <pino@kde.org>
20// Copyright (C) 2008 Carlos Garcia Campos <carlosgc@gnome.org>
21// Copyright (C) 2009 Eric Toombs <ewtoombs@uwaterloo.ca>
22// Copyright (C) 2009 Kovid Goyal <kovid@kovidgoyal.net>
23// Copyright (C) 2010 Hib Eris <hib@hiberis.nl>
24//
25// To see a description of the changes please see the Changelog file that
26// came with your tarball or type make ChangeLog if you are building from git
27//
28//========================================================================
29
30#ifndef PDFDOC_H
31#define PDFDOC_H
32
33#ifdef USE_GCC_PRAGMAS
34#pragma interface
35#endif
36
37#include <stdio.h>
38#include "XRef.h"
39#include "Catalog.h"
40#include "Page.h"
41#include "Annot.h"
42#include "OptionalContent.h"
43
44class GooString;
45class BaseStream;
46class OutputDev;
47class Links;
48class LinkAction;
49class LinkDest;
50class Outline;
51
52enum PDFWriteMode {
53  writeStandard,
54  writeForceRewrite,
55  writeForceIncremental
56};
57
58//------------------------------------------------------------------------
59// PDFDoc
60//------------------------------------------------------------------------
61
62class PDFDoc {
63public:
64
65  PDFDoc(GooString *fileNameA, GooString *ownerPassword = NULL,
66         GooString *userPassword = NULL, void *guiDataA = NULL);
67
68#ifdef _WIN32
69  PDFDoc(wchar_t *fileNameA, int fileNameLen, GooString *ownerPassword = NULL,
70         GooString *userPassword = NULL, void *guiDataA = NULL);
71#endif
72
73  PDFDoc(BaseStream *strA, GooString *ownerPassword = NULL,
74         GooString *userPassword = NULL, void *guiDataA = NULL);
75  ~PDFDoc();
76
77  static PDFDoc *ErrorPDFDoc(int errorCode, GooString *fileNameA = NULL);
78
79  // Was PDF document successfully opened?
80  GBool isOk() { return ok; }
81
82  // Get the error code (if isOk() returns false).
83  int getErrorCode() { return errCode; }
84
85  // Get the error code returned by fopen() (if getErrorCode() ==
86  // errOpenFile).
87  int getFopenErrno() { return fopenErrno; }
88
89  // Get file name.
90  GooString *getFileName() { return fileName; }
91
92  // Get the xref table.
93  XRef *getXRef() { return xref; }
94
95  // Get catalog.
96  Catalog *getCatalog() { return catalog; }
97
98  // Get optional content configuration
99  OCGs *getOptContentConfig() { return catalog->getOptContentConfig(); }
100
101  // Get base stream.
102  BaseStream *getBaseStream() { return str; }
103
104  // Get page parameters.
105  double getPageMediaWidth(int page)
106    { return catalog->getPage(page)->getMediaWidth(); }
107  double getPageMediaHeight(int page)
108    { return catalog->getPage(page)->getMediaHeight(); }
109  double getPageCropWidth(int page)
110    { return catalog->getPage(page)->getCropWidth(); }
111  double getPageCropHeight(int page)
112    { return catalog->getPage(page)->getCropHeight(); }
113  int getPageRotate(int page)
114    { return catalog->getPage(page)->getRotate(); }
115
116  // Get number of pages.
117  int getNumPages() { return catalog->getNumPages(); }
118
119  // Return the contents of the metadata stream, or NULL if there is
120  // no metadata.
121  GooString *readMetadata() { return catalog->readMetadata(); }
122
123  // Return the structure tree root object.
124  Object *getStructTreeRoot() { return catalog->getStructTreeRoot(); }
125
126  // Display a page.
127  void displayPage(OutputDev *out, int page,
128                   double hDPI, double vDPI, int rotate,
129                   GBool useMediaBox, GBool crop, GBool printing,
130                   GBool (*abortCheckCbk)(void *data) = NULL,
131                   void *abortCheckCbkData = NULL,
132                   GBool (*annotDisplayDecideCbk)(Annot *annot, void *user_data) = NULL,
133                   void *annotDisplayDecideCbkData = NULL);
134
135  // Display a range of pages.
136  void displayPages(OutputDev *out, int firstPage, int lastPage,
137                    double hDPI, double vDPI, int rotate,
138                    GBool useMediaBox, GBool crop, GBool printing,
139                    GBool (*abortCheckCbk)(void *data) = NULL,
140                    void *abortCheckCbkData = NULL,
141                    GBool (*annotDisplayDecideCbk)(Annot *annot, void *user_data) = NULL,
142                    void *annotDisplayDecideCbkData = NULL);
143
144  // Display part of a page.
145  void displayPageSlice(OutputDev *out, int page,
146                        double hDPI, double vDPI, int rotate, 
147                        GBool useMediaBox, GBool crop, GBool printing,
148                        int sliceX, int sliceY, int sliceW, int sliceH,
149                        GBool (*abortCheckCbk)(void *data) = NULL,
150                        void *abortCheckCbkData = NULL,
151                        GBool (*annotDisplayDecideCbk)(Annot *annot, void *user_data) = NULL,
152                        void *annotDisplayDecideCbkData = NULL);
153
154  // Find a page, given its object ID.  Returns page number, or 0 if
155  // not found.
156  int findPage(int num, int gen) { return catalog->findPage(num, gen); }
157
158  // Returns the links for the current page, transferring ownership to
159  // the caller.
160  Links *getLinks(int page);
161
162  // Find a named destination.  Returns the link destination, or
163  // NULL if <name> is not a destination.
164  LinkDest *findDest(GooString *name)
165    { return catalog->findDest(name); }
166
167  // Process the links for a page.
168  void processLinks(OutputDev *out, int page);
169
170
171#ifndef DISABLE_OUTLINE
172  // Return the outline object.
173  Outline *getOutline();
174#endif
175
176  // Is the file encrypted?
177  GBool isEncrypted() { return xref->isEncrypted(); }
178
179  // Check various permissions.
180  GBool okToPrint(GBool ignoreOwnerPW = gFalse)
181    { return xref->okToPrint(ignoreOwnerPW); }
182  GBool okToPrintHighRes(GBool ignoreOwnerPW = gFalse)
183    { return xref->okToPrintHighRes(ignoreOwnerPW); }
184  GBool okToChange(GBool ignoreOwnerPW = gFalse)
185    { return xref->okToChange(ignoreOwnerPW); }
186  GBool okToCopy(GBool ignoreOwnerPW = gFalse)
187    { return xref->okToCopy(ignoreOwnerPW); }
188  GBool okToAddNotes(GBool ignoreOwnerPW = gFalse)
189    { return xref->okToAddNotes(ignoreOwnerPW); }
190  GBool okToFillForm(GBool ignoreOwnerPW = gFalse)
191    { return xref->okToFillForm(ignoreOwnerPW); }
192  GBool okToAccessibility(GBool ignoreOwnerPW = gFalse)
193    { return xref->okToAccessibility(ignoreOwnerPW); }
194  GBool okToAssemble(GBool ignoreOwnerPW = gFalse)
195    { return xref->okToAssemble(ignoreOwnerPW); }
196
197
198  // Is this document linearized?
199  GBool isLinearized();
200
201  // Return the document's Info dictionary (if any).
202  Object *getDocInfo(Object *obj) { return xref->getDocInfo(obj); }
203  Object *getDocInfoNF(Object *obj) { return xref->getDocInfoNF(obj); }
204
205  // Return the PDF version specified by the file.
206  int getPDFMajorVersion() { return pdfMajorVersion; }
207  int getPDFMinorVersion() { return pdfMinorVersion; }
208
209  // Save this file with another name.
210  int saveAs(GooString *name, PDFWriteMode mode=writeStandard);
211  // Save this file in the given output stream.
212  int saveAs(OutStream *outStr, PDFWriteMode mode=writeStandard);
213  // Save this file with another name without saving changes
214  int saveWithoutChangesAs(GooString *name);
215  // Save this file in the given output stream without saving changes
216  int saveWithoutChangesAs(OutStream *outStr);
217
218  // Return a pointer to the GUI (XPDFCore or WinPDFCore object).
219  void *getGUIData() { return guiData; }
220
221private:
222  // Add object to current file stream and return the offset of the beginning of the object
223  Guint writeObject (Object *obj, Ref *ref, OutStream* outStr);
224  void writeDictionnary (Dict* dict, OutStream* outStr);
225  void writeStream (Stream* str, OutStream* outStr);
226  void writeRawStream (Stream* str, OutStream* outStr);
227  void writeTrailer (Guint uxrefOffset, int uxrefSize, OutStream* outStr, GBool incrUpdate);
228  void writeString (GooString* s, OutStream* outStr);
229  void saveIncrementalUpdate (OutStream* outStr);
230  void saveCompleteRewrite (OutStream* outStr);
231
232  PDFDoc();
233  void init();
234  GBool setup(GooString *ownerPassword, GooString *userPassword);
235  GBool checkFooter();
236  void checkHeader();
237  GBool checkEncryption(GooString *ownerPassword, GooString *userPassword);
238
239  GooString *fileName;
240  FILE *file;
241  BaseStream *str;
242  void *guiData;
243  int pdfMajorVersion;
244  int pdfMinorVersion;
245  XRef *xref;
246  Catalog *catalog;
247#ifndef DISABLE_OUTLINE
248  Outline *outline;
249#endif
250
251  GBool ok;
252  int errCode;
253  //If there is an error opening the PDF file with fopen() in the constructor,
254  //then the POSIX errno will be here.
255  int fopenErrno;
256};
257
258#endif
Note: See TracBrowser for help on using the repository browser.