aboutsummaryrefslogtreecommitdiffstats
path: root/src/org/apache/fop/pdf/PDFObject.java
blob: a20f358f0571ce3b3d34f6eb1a0ab180230a985b (plain)
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
/*
 * $Id$
 * Copyright (C) 2001 The Apache Software Foundation. All rights reserved.
 * For details on use and redistribution please refer to the
 * LICENSE file included with these sources.
 */

package org.apache.fop.pdf;

// Java
import java.io.IOException;
import java.io.OutputStream;

/**
 * generic PDF object.
 *
 * A PDF Document is essentially a collection of these objects. A PDF
 * Object has a number and a generation (although the generation will always
 * be 0 in new documents).
 */
public abstract class PDFObject {

    /**
     * the object's number
     */
    protected int number;

    /**
     * the object's generation (0 in new documents)
     */
    protected int generation = 0;

    /**
     * create an empty object
     *
     * @param number the object's number
     */
    public PDFObject(int number) {
        this.number = number;
    }

    public PDFObject() {
        // do nothing
    }

    /**
     * @return the PDF Object number
     */
    public int getNumber() {
        return this.number;
    }

    /**
     * write the PDF represention of this object
     *
     * @param stream the stream to write the PDF to
     * @return the number of bytes written
     */
    protected int output(OutputStream stream) throws IOException {
        byte[] pdf = this.toPDF();
        stream.write(pdf);
        return pdf.length;
    }

    /**
     * the PDF representation of a reference to this object
     *
     * @return the reference string
     */
    public String referencePDF() {
        String p = this.number + " " + this.generation + " R";
        return p;
    }

    /**
     * represent object as PDF
     *
     * @return PDF string
     */
    abstract byte[] toPDF();
}