The cpdf_finalize() function ends the document. You still have to call cpdf_close(). Returns TRUE on success or FALSE on failure.
See also cpdf_close().