JagPDF
Prev Up Home Next

Besides writing the document to a file JagPDF allows clients to supply a custom handler which receives a stream of generated PDF data. This section describes how to implement such custom handler in individual languages.

C++

Derive your stream class from pdf::StreamOut and implement write() and close() methods. In these methods, return non-zero value on failure. The final step is to pass an instance of your class to the document creation function.

class MyStream
    : public pdf::StreamOut
{
    pdf::Int write(void const* data, pdf::ULong size) { 
        // write data
        return 0;
    }

    pdf::Int close() {
        // finish
        return 0;
    }
};

MyStream stream;
pdf::Document doc(pdf::create_stream(&stream));
C

Implement write() and close() functions. These functions should return a non-zero value on error. Initialize an instance of jag_streamout with pointers to these functions and with your custom data and pass it to the document creation function.

jag_Int JAG_CALLSPEC my_write(void* custom, void const* data, jag_ULong size)
{ 
    /* write data */
    return 0;
}

jag_Int JAG_CALLSPEC my_close(void* custom)
{ 
    /* finish */
    return 0;
}

void use_custom_stream(void* custom)
{ 
    /* ... */
    jag_streamout my_stream;
    my_stream.write = my_write;
    my_stream.close = my_close;
    my_stream.custom_data = (void*)custom;
    doc = jag_create_stream(&my_stream, profile);
    /* ... */
}
Python

Derive your stream class from jagpdf.StreamOut and implement write() and close() methods. In case of failure you can raise an exception in these functions. Pass an instance of your class to the document creation function.

class MyStream(jagpdf.StreamOut):
    def write(self, data):
        # write data
    def close(self):
        # finish

doc = jagpdf.create_stream(MyStream())
Java

Derive your stream class from com.jagpdf.StreamOut and implement write() and close() methods. In case of failure you can throw an exception in these functions. Pass an instance of your class to the document creation function.

class MyStream extends StreamOut
{
    public void write(byte[] data_in) {
        // write data
    }

    public void close() {
        // finish
    }
}

MyStream myStream = new MyStream();
Document doc = jagpdf.create_stream(myStream);
Prev Up Home Next