src/pdfio.c
l_int32
pixWriteStreamPdf(FILE        *fp,
                  PIX         *pix,
                  l_int32      res,
                  const char  *title)
{
l_uint8  *data;
l_int32   ret, d, type;
size_t    nbytes;
PIXCMAP  *cmap;

    PROCNAME("pixWriteStreamPdf");

    if (!fp)
        return ERROR_INT("stream not opened", procName, 1);
    if (!pix)
        return ERROR_INT("pix not defined", procName, 1);

    d = pixGetDepth(pix);
    cmap = pixGetColormap(pix);
    if (d == 1)
        type = L_G4_ENCODE;
    else if (cmap || d == 2 || d == 4 || d == 16)
        type = L_FLATE_ENCODE;
    else  /* d == 8 (no cmap) or d == 32 */
        type = L_JPEG_ENCODE;
    if (pixConvertToPdfData(pix, type, 75, &data, &nbytes,
                            0, 0, res, NULL, 0, title))
        return ERROR_INT("pdf data not made", procName, 1);
    ret = fwrite(data, 1, nbytes, fp);

    FREE(data);
    if (ret)
        return ERROR_INT("pdf data not written to stream", procName, 1);
    return 0;
}
/*!
 *  pixWriteStreamPdf()
 *
 *      Input:  fp (stream opened for writing)
 *              pix (all depths, cmap OK)
 *              res (override the resolution of the input image, in ppi;
 *                   use 0 to respect the resolution embedded in the input)
 *              title (<optional> pdf title; taken from the first image
 *                     placed on a page; e.g., an input image filename)
 *      Return: 0 if OK, 1 on error
 *
 *  Notes:
 *      (1) This is the simplest interface for writing a single image
 *          with pdf encoding.  It uses G4 encoding for 1 bpp,
 *          JPEG encoding for 8 bpp (no cmap) and 32 bpp, and FLATE
 *          encoding for everything else.
 */
pixWriteStreamPdf()
Input:  fp (stream opened for writing)
pix (all depths, cmap OK)
res (override the resolution of the input image, in ppi;
use 0 to respect the resolution embedded in the input)
title ( pdf title; taken from the first image
placed on a page; e.g., an input image filename)
Return: 0 if OK, 1 on error

(1) This is the simplest interface for writing a single image
with pdf encoding.  It uses G4 encoding for 1 bpp,
JPEG encoding for 8 bpp (no cmap) and 32 bpp, and FLATE
encoding for everything else.
pixWriteStreamPdf () Input : fp ( stream opened for writing ) pix ( all depths cmap OK ) res ( override the resolution of the input image in ppi ; use 0 to respect the resolution embedded in the input ) title ( pdf title ; taken from the first image placed on a page ; e . g . an input image filename ) Return : 0 if OK 1 on error ( 1 ) This is the simplest interface for writing a single image with pdf encoding . It uses G4 encoding for 1 bpp JPEG encoding for 8 bpp ( no cmap ) and 32 bpp and FLATE encoding for everything else .
l_int32
pixWriteStreamPdf(FILE        *fp,
                  PIX         *pix,
                  l_int32      res,
                  const char  *title)
{
l_uint8  *data;
l_int32   ret, d, type;
size_t    nbytes;
PIXCMAP  *cmap;
    PROCNAME("pixWriteStreamPdf");
    if (!fp)
        return ERROR_INT("stream not opened", procName, 1);
    if (!pix)
        return ERROR_INT("pix not defined", procName, 1);
    d = pixGetDepth(pix);
    cmap = pixGetColormap(pix);
    if (d == 1)
        type = L_G4_ENCODE;
    else if (cmap || d == 2 || d == 4 || d == 16)
        type = L_FLATE_ENCODE;
    else  
        type = L_JPEG_ENCODE;
    if (pixConvertToPdfData(pix, type, 75, &data, &nbytes,
                            0, 0, res, NULL, 0, title))
        return ERROR_INT("pdf data not made", procName, 1);
    ret = fwrite(data, 1, nbytes, fp);
    FREE(data);
    if (ret)
        return ERROR_INT("pdf data not written to stream", procName, 1);
    return 0;
}
l_int32 pixWriteStreamPdf ( FILE * fp , PIX * pix , l_int32 res , const char * title ) { l_uint8 * data ; l_int32 ret , d , type ; size_t nbytes ; PIXCMAP * cmap ; PROCNAME ( " " ) ; if ( ! fp ) return ERROR_INT ( " " , procName , 1 ) ; if ( ! pix ) return ERROR_INT ( " " , procName , 1 ) ; d = pixGetDepth ( pix ) ; cmap = pixGetColormap ( pix ) ; if ( d == 1 ) type = L_G4_ENCODE ; else if ( cmap || d == 2 || d == 4 || d == 16 ) type = L_FLATE_ENCODE ; else type = L_JPEG_ENCODE ; if ( pixConvertToPdfData ( pix , type , 75 , & data , & nbytes , 0 , 0 , res , NULL , 0 , title ) ) return ERROR_INT ( " " , procName , 1 ) ; ret = fwrite ( data , 1 , nbytes , fp ) ; FREE ( data ) ; if ( ret ) return ERROR_INT ( " " , procName , 1 ) ; return 0 ; }
pixWriteStreamPdf()
      Input:  fp (stream opened for writing)
              pix (all depths, cmap OK)
              res (override the resolution of the input image, in ppi;
                   use 0 to respect the resolution embedded in the input)
              title (<optional> pdf title; taken from the first image
                     placed on a page; e.g., an input image filename)
      Return: 0 if OK, 1 on error
pixWriteStreamPdf () Input : fp ( stream opened for writing ) pix ( all depths cmap OK ) res ( override the resolution of the input image in ppi ; use 0 to respect the resolution embedded in the input ) title ( <optional > pdf title ; taken from the first image placed on a page ; e . g . an input image filename ) Return : 0 if OK 1 on error
/* d == 8 (no cmap) or d == 32 */