Example #1
0
void
pdf__delete(PDF *p)
{
    /*
     * Close the output stream, because it could be open
     */
    pdc_close_output(p->out);

    /*
     * Clean up page-related stuff if necessary. Do not raise
     * an error here since we may be called from the error handler.
     */
    pdf_cleanup_document(p);
    pdf_cleanup_stringlists(p);
    pdf_cleanup_font_curroptions(p);
    pdc_cleanup_output(p->out, pdc_false);




    if (p->out)
	pdc_free(p->pdc, p->out);

    /* we never reach this point if (p->pdc == NULL).
    */
    pdc_delete_core(p->pdc);

    /* free the PDF structure and try to protect against duplicated calls */

    p->magic = 0L;		/* we don't reach this with the wrong magic */
    (*p->freeproc)(p, (void *) p);
}
Example #2
0
pdc_bool
pdc_init_output(
    void *opaque,
    pdc_output *out,
    int compatibility,
    pdc_outctl *oc)
{
    static const char *fn = "pdc_init_output";
    pdc_core *pdc = out->pdc;
    int i;

    pdc_cleanup_output(out, pdc_false);

    out->opaque		= opaque;

    out->lastobj	= 0;
#if defined(MVS) || defined(MVS_TEST)
    out->fopenparams    = oc->fopenparams;
    out->recordsize     = oc->recordsize;
#endif

    if (out->file_offset == NULL) {
	out->file_offset_capacity = ID_CHUNKSIZE;

	out->file_offset = (pdc_off_t *) pdc_malloc(pdc,
		sizeof(pdc_off_t) * out->file_offset_capacity, fn);
    }

    for (i = 1; i < out->file_offset_capacity; ++i)
	out->file_offset[i] = PDC_BAD_ID;

    out->compresslevel	= PDF_DEFAULT_COMPRESSION;
    out->compr_changed	= pdc_false;
    out->flush = oc->flush;

    memcpy(out->id[0], out->id[1], MD5_DIGEST_LENGTH);


    if (!pdc_init_stream(pdc, out, oc->filename, oc->fp, oc->writeproc))
	return pdc_false;


    {
	/* Write the document header */
	pdc_printf(out, "%%PDF-%s\n", pdc_get_pdfversion(pdc, compatibility));

#define PDC_MAGIC_BINARY "\045\344\343\317\322\012"
	pdc_write(out, PDC_MAGIC_BINARY, sizeof(PDC_MAGIC_BINARY) - 1);
    }

    out->open = pdc_true;

    return pdc_true;
}