1
//========================================================================
5
// Copyright 1996-2003 Glyph & Cog, LLC
7
//========================================================================
9
//========================================================================
11
// Modified under the Poppler project - http://poppler.freedesktop.org
13
// All changes made under the Poppler project to this file are licensed
14
// under GPL version 2 or later
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
// Copyright (C) 2010 Srinivas Adicherla <srinivas.adicherla@geodesic.com>
26
// To see a description of the changes please see the Changelog file that
27
// came with your tarball or type make ChangeLog if you are building from git
29
//========================================================================
34
#ifdef USE_GCC_PRAGMAS
43
#include "OptionalContent.h"
53
class SecurityHandler;
62
//------------------------------------------------------------------------
64
//------------------------------------------------------------------------
69
PDFDoc(GooString *fileNameA, GooString *ownerPassword = NULL,
70
GooString *userPassword = NULL, void *guiDataA = NULL);
73
PDFDoc(wchar_t *fileNameA, int fileNameLen, GooString *ownerPassword = NULL,
74
GooString *userPassword = NULL, void *guiDataA = NULL);
77
PDFDoc(BaseStream *strA, GooString *ownerPassword = NULL,
78
GooString *userPassword = NULL, void *guiDataA = NULL);
81
static PDFDoc *ErrorPDFDoc(int errorCode, GooString *fileNameA = NULL);
83
// Was PDF document successfully opened?
84
GBool isOk() { return ok; }
86
// Get the error code (if isOk() returns false).
87
int getErrorCode() { return errCode; }
89
// Get the error code returned by fopen() (if getErrorCode() ==
91
int getFopenErrno() { return fopenErrno; }
94
GooString *getFileName() { return fileName; }
96
// Get the linearization table.
97
Linearization *getLinearization();
99
// Get the xref table.
100
XRef *getXRef() { return xref; }
103
Catalog *getCatalog() { return catalog; }
105
// Get optional content configuration
106
OCGs *getOptContentConfig() { return catalog->getOptContentConfig(); }
109
BaseStream *getBaseStream() { return str; }
111
// Get page parameters.
112
double getPageMediaWidth(int page)
113
{ return getPage(page) ? getPage(page)->getMediaWidth() : 0.0 ; }
114
double getPageMediaHeight(int page)
115
{ return getPage(page) ? getPage(page)->getMediaHeight() : 0.0 ; }
116
double getPageCropWidth(int page)
117
{ return getPage(page) ? getPage(page)->getCropWidth() : 0.0 ; }
118
double getPageCropHeight(int page)
119
{ return getPage(page) ? getPage(page)->getCropHeight() : 0.0 ; }
120
int getPageRotate(int page)
121
{ return getPage(page) ? getPage(page)->getRotate() : 0 ; }
123
// Get number of pages.
126
// Return the contents of the metadata stream, or NULL if there is
128
GooString *readMetadata() { return catalog->readMetadata(); }
130
// Return the structure tree root object.
131
Object *getStructTreeRoot() { return catalog->getStructTreeRoot(); }
134
Page *getPage(int page);
137
void displayPage(OutputDev *out, int page,
138
double hDPI, double vDPI, int rotate,
139
GBool useMediaBox, GBool crop, GBool printing,
140
GBool (*abortCheckCbk)(void *data) = NULL,
141
void *abortCheckCbkData = NULL,
142
GBool (*annotDisplayDecideCbk)(Annot *annot, void *user_data) = NULL,
143
void *annotDisplayDecideCbkData = NULL);
145
// Display a range of pages.
146
void displayPages(OutputDev *out, int firstPage, int lastPage,
147
double hDPI, double vDPI, int rotate,
148
GBool useMediaBox, GBool crop, GBool printing,
149
GBool (*abortCheckCbk)(void *data) = NULL,
150
void *abortCheckCbkData = NULL,
151
GBool (*annotDisplayDecideCbk)(Annot *annot, void *user_data) = NULL,
152
void *annotDisplayDecideCbkData = NULL);
154
// Display part of a page.
155
void displayPageSlice(OutputDev *out, int page,
156
double hDPI, double vDPI, int rotate,
157
GBool useMediaBox, GBool crop, GBool printing,
158
int sliceX, int sliceY, int sliceW, int sliceH,
159
GBool (*abortCheckCbk)(void *data) = NULL,
160
void *abortCheckCbkData = NULL,
161
GBool (*annotDisplayDecideCbk)(Annot *annot, void *user_data) = NULL,
162
void *annotDisplayDecideCbkData = NULL);
164
// Find a page, given its object ID. Returns page number, or 0 if
166
int findPage(int num, int gen) { return catalog->findPage(num, gen); }
168
// Returns the links for the current page, transferring ownership to
170
Links *getLinks(int page);
172
// Find a named destination. Returns the link destination, or
173
// NULL if <name> is not a destination.
174
LinkDest *findDest(GooString *name)
175
{ return catalog->findDest(name); }
177
// Process the links for a page.
178
void processLinks(OutputDev *out, int page);
181
#ifndef DISABLE_OUTLINE
182
// Return the outline object.
183
Outline *getOutline();
186
// Is the file encrypted?
187
GBool isEncrypted() { return xref->isEncrypted(); }
189
// Check various permissions.
190
GBool okToPrint(GBool ignoreOwnerPW = gFalse)
191
{ return xref->okToPrint(ignoreOwnerPW); }
192
GBool okToPrintHighRes(GBool ignoreOwnerPW = gFalse)
193
{ return xref->okToPrintHighRes(ignoreOwnerPW); }
194
GBool okToChange(GBool ignoreOwnerPW = gFalse)
195
{ return xref->okToChange(ignoreOwnerPW); }
196
GBool okToCopy(GBool ignoreOwnerPW = gFalse)
197
{ return xref->okToCopy(ignoreOwnerPW); }
198
GBool okToAddNotes(GBool ignoreOwnerPW = gFalse)
199
{ return xref->okToAddNotes(ignoreOwnerPW); }
200
GBool okToFillForm(GBool ignoreOwnerPW = gFalse)
201
{ return xref->okToFillForm(ignoreOwnerPW); }
202
GBool okToAccessibility(GBool ignoreOwnerPW = gFalse)
203
{ return xref->okToAccessibility(ignoreOwnerPW); }
204
GBool okToAssemble(GBool ignoreOwnerPW = gFalse)
205
{ return xref->okToAssemble(ignoreOwnerPW); }
208
// Is this document linearized?
209
GBool isLinearized();
211
// Return the document's Info dictionary (if any).
212
Object *getDocInfo(Object *obj) { return xref->getDocInfo(obj); }
213
Object *getDocInfoNF(Object *obj) { return xref->getDocInfoNF(obj); }
215
// Return the PDF version specified by the file.
216
int getPDFMajorVersion() { return pdfMajorVersion; }
217
int getPDFMinorVersion() { return pdfMinorVersion; }
219
//Return the PDF ID in the trailer dictionary (if any).
220
GBool getID(GooString *permanent_id, GooString *update_id);
222
// Save this file with another name.
223
int saveAs(GooString *name, PDFWriteMode mode=writeStandard);
224
// Save this file in the given output stream.
225
int saveAs(OutStream *outStr, PDFWriteMode mode=writeStandard);
226
// Save this file with another name without saving changes
227
int saveWithoutChangesAs(GooString *name);
228
// Save this file in the given output stream without saving changes
229
int saveWithoutChangesAs(OutStream *outStr);
231
// Return a pointer to the GUI (XPDFCore or WinPDFCore object).
232
void *getGUIData() { return guiData; }
235
// Add object to current file stream and return the offset of the beginning of the object
236
Guint writeObject (Object *obj, Ref *ref, OutStream* outStr);
237
void writeDictionnary (Dict* dict, OutStream* outStr);
238
void writeStream (Stream* str, OutStream* outStr);
239
void writeRawStream (Stream* str, OutStream* outStr);
240
void writeTrailer (Guint uxrefOffset, int uxrefSize, OutStream* outStr, GBool incrUpdate);
241
void writeString (GooString* s, OutStream* outStr);
242
void saveIncrementalUpdate (OutStream* outStr);
243
void saveCompleteRewrite (OutStream* outStr);
245
Page *parsePage(int page);
252
GBool setup(GooString *ownerPassword, GooString *userPassword);
255
GBool checkEncryption(GooString *ownerPassword, GooString *userPassword);
256
// Get the offset of the start xref table.
257
Guint getStartXRef();
258
// Get the offset of the entries in the main XRef table of a
259
// linearized document (0 for non linearized documents).
260
Guint getMainXRefEntriesOffset();
261
Guint strToUnsigned(char *s);
269
Linearization *linearization;
271
SecurityHandler *secHdlr;
274
#ifndef DISABLE_OUTLINE
281
//If there is an error opening the PDF file with fopen() in the constructor,
282
//then the POSIX errno will be here.
285
Guint startXRefPos; // offset of last xref table