File: pdf.h

package info (click to toggle)
pdfresurrect 0.11-1
  • links: PTS, VCS
  • area: main
  • in suites: wheezy
  • size: 336 kB
  • sloc: ansic: 1,206; makefile: 50
file content (135 lines) | stat: -rw-r--r-- 3,288 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
/******************************************************************************
 * pdf.h 
 *
 * pdfresurrect - PDF history extraction tool
 *
 * Copyright (C) 2008, 2009, 2012 Matt Davis (enferex) of 757Labs
 * (www.757labs.org)
 *
 * pdf.h is part of pdfresurrect.
 * pdfresurrect is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * pdfresurrect is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with pdfresurrect.  If not, see <http://www.gnu.org/licenses/>.
 *****************************************************************************/

#ifndef PDF_H_INCLUDE
#define PDF_H_INCLUDE

#include <stdio.h>


/* Bit-maskable flags */
typedef unsigned short pdf_flag_t;
#define PDF_FLAG_NONE         0
#define PDF_FLAG_QUIET        1
#define PDF_FLAG_DISP_CREATOR 2


/* Generic key/value structure */
#define KV_MAX_KEY_LENGTH   32
#define KV_MAX_VALUE_LENGTH 128
typedef struct _kv_t
{
    char key[KV_MAX_KEY_LENGTH];
    char value[KV_MAX_VALUE_LENGTH];
} kv_t;


/* Information about who/what created the PDF 
 * From 1.7 Spec for non-metadata entries
 */
typedef kv_t pdf_creator_t;


typedef struct _xref_entry
{
    int obj_id;
    long offset;
    int gen_num; 
    char f_or_n;
} xref_entry_t;


#define KIDS_PER_ALLOC 64
#define KID_SIZE sizeof(int)
typedef struct _xref_t
{
    long start;
    long end;

    /* Array of metadata about the pdf */    
    pdf_creator_t *creator;
    int n_creator_entries;

    int n_entries;
    xref_entry_t *entries;

    int  n_kids;
    int *kids;
    int  n_kids_allocs;
    
    /* PDF 1.5 or greater: xref can be encoded as a stream */
    int is_stream;
    
    /* If the PDF is linear multiple xrefs make up one single version */
    int is_linear;
    
    /* Version of the document this xref belongs */
    int version;
} xref_t;


typedef struct _pdf_t
{
    char  *name;
    short  pdf_major_version;
    short  pdf_minor_version;

    int     n_xrefs;
    xref_t *xrefs;
    
    /* PDF 1.5 or greater: xref can be encoded as a stream */
    int has_xref_streams;
} pdf_t;


extern pdf_t *pdf_new(const char *name);
extern void pdf_delete(pdf_t *pdf);

extern int pdf_is_pdf(FILE *fp);
extern void pdf_get_version(FILE *fp, pdf_t *pdf);

extern int pdf_load_xrefs(FILE *fp, pdf_t *pdf);
extern void pdf_load_pages_kids(FILE *fp, pdf_t *pdf);

extern char pdf_get_object_status(
    const pdf_t *pdf,
    int          xref_idx,
    int          entry_idx);

extern void pdf_zero_object(
    FILE        *fp,
    const pdf_t *pdf,
    int          xref_idx,
    int          entry_idx);

extern void pdf_summarize(
    FILE        *fp,
    const pdf_t *pdf,
    const char  *name,
    pdf_flag_t   flags);

/* Returns '1' if we successfully display data (means its probably not xml) */
extern int pdf_display_creator(const pdf_t *pdf, int xref_idx);


#endif /* PDF_H_INCLUDE */