コード例 #1
0
ファイル: starter_pdfx.c プロジェクト: Distrotech/PDFlib-Lite
int
main(void)
{
    /* This is where the data files are. Adjust as necessary.*/
    const char * searchpath = "../data";

    PDF *p;
    const char * imagefile = "nesrin.jpg";
    char optlist[1024];

    int font, image, spot, icc;

    /* create a new PDFlib object */
    if ((p = PDF_new()) == (PDF *) 0) {
        printf("Couldn't create PDFlib object (out of memory)!\n");
        return(2);
    }

    PDF_TRY(p) {
        /* This means we must check return values of load_font() etc. */
        PDF_set_parameter(p, "errorpolicy", "return");

        PDF_set_parameter(p, "SearchPath", searchpath);

        if (PDF_begin_document(p, "starter_pdfx.pdf", 0, "pdfx=PDF/X-3:2002")
                == -1) {
            printf("Error: %s\n", PDF_get_errmsg(p));
            PDF_delete(p);
            return(2);
        }

        PDF_set_info(p, "Creator", "PDFlib starter sample");
        PDF_set_info(p, "Title", "starter_pdfx");

        /*
         * You can use one of the Standard output intents (e.g. for SWOP
         * printing) which do not require an ICC profile:

        PDF_load_iccprofile(p, "CGATS TR 001", 0, "usage=outputintent");

         * However, if you use ICC or Lab color you must load an ICC
         * profile as output intent:
         */

        if (PDF_load_iccprofile(p, "ISOcoated.icc", 0,
                "usage=outputintent") == -1)
        {
            printf("Error: %s\n", PDF_get_errmsg(p));
            printf("Please install the ICC profile package from "
                   "www.pdflib.com to run the PDF/X starter sample.\n");
            PDF_delete(p);
            return(2);
        }

        PDF_begin_page_ext(p, 595, 842, "");

        /* Font embedding is required for PDF/X */
        font = PDF_load_font(p, "LuciduxSans-Oblique", 0,
                "winansi", "embedding");

        if (font == -1) {
            printf("Error: %s\n", PDF_get_errmsg(p));
            PDF_delete(p);
            return(2);
        }

        PDF_setfont(p, font, 24);

        spot = PDF_makespotcolor(p, "PANTONE 123 C", 0);
        PDF_setcolor(p, "fill", "spot", spot, 1.0, 0.0, 0.0);
        PDF_fit_textline(p, "PDF/X-3:2002 starter", 0, 50, 700, "");

        /* The RGB image below needs an ICC profile; we use sRGB. */
        icc = PDF_load_iccprofile(p, "sRGB", 0, "");
        sprintf(optlist, "iccprofile=%d", icc);
        image = PDF_load_image(p, "auto", imagefile, 0, optlist);

        if (image == -1) {
            printf("Error: %s\n", PDF_get_errmsg(p));
            PDF_delete(p);
            return(2);
        }

        PDF_fit_image(p, image, (float) 0.0, (float) 0.0, "scale=0.5");

        PDF_end_page_ext(p, "");

        PDF_end_document(p, "");
    }

    PDF_CATCH(p) {
        printf("PDFlib exception occurred:\n");
        printf("[%d] %s: %s\n",
            PDF_get_errnum(p), PDF_get_apiname(p), PDF_get_errmsg(p));
        PDF_delete(p);
        return(2);
    }

    PDF_delete(p);

    return 0;
}
コード例 #2
0
int
main(void)
{
    /* This is where the data files are. Adjust as necessary.*/
    const char * searchpath = "../data";
    const char *targetname = "x5target.pdf";

    PDF *p;
    char optlist[1024];

    int font, proxy;
    double linewidth=2;
    double width, height;

    /* create a new PDFlib object */
    if ((p = PDF_new()) == (PDF *) 0) {
        printf("Couldn't create PDFlib object (out of memory)!\n");
        return(2);
    }

    PDF_TRY(p) {
        /* This means we must check return values of load_font() etc. */
        PDF_set_parameter(p, "errorpolicy", "return");

        PDF_set_parameter(p, "SearchPath", searchpath);

        if (PDF_begin_document(p, "starter_pdfx5g.pdf", 0, "pdfx=PDF/X-5g")
                == -1) {
            printf("Error: %s\n", PDF_get_errmsg(p));
            PDF_delete(p);
            return(2);
        }

        PDF_set_info(p, "Creator", "PDFlib starter sample");
        PDF_set_info(p, "Title", "starter_pdfx5g");

        /* Open the output intent profile */
        if (PDF_load_iccprofile(p, "ISOcoated.icc", 0,
                "usage=outputintent") == -1)
        {
            printf("Error: %s\n", PDF_get_errmsg(p));
            printf("Please install the ICC profile package from "
                   "www.pdflib.com to run the PDF/X-5g starter sample.\n");
            PDF_delete(p);
            return(2);
        }

        /* Font embedding is required for PDF/X */
        font = PDF_load_font(p, "LuciduxSans-Oblique", 0,
                "winansi", "embedding");

        if (font == -1) {
            printf("Error: %s\n", PDF_get_errmsg(p));
            PDF_delete(p);
            return(2);
        }

        /* Create a template which will serve as proxy. The referenced
         * page (the target) is attached to the proxy.
	 * The template width and height will be determined automatically,
	 * so we don't have to supply them.
         */
        sprintf(optlist, "reference={filename=%s pagenumber=1}", targetname);
        proxy = PDF_begin_template_ext(p, 0, 0, optlist);

        if (proxy == -1)
        {
            printf("Error: %s\n", PDF_get_errmsg(p));
            PDF_delete(p);
            return(2);
        }

	width  = PDF_info_image(p, proxy, "imagewidth", "");
	height = PDF_info_image(p, proxy, "imageheight", "");

        /* Draw a crossed-out rectangle to visualize the proxy.
         * Attention: if we use the exact corner points, one half of the
         * linewidth would end up outside the template, and therefore be
         * clipped.
         */
        PDF_setlinewidth(p, linewidth);
        PDF_moveto(p, linewidth/2, linewidth/2);
        PDF_lineto(p, width-linewidth/2, linewidth/2);
        PDF_lineto(p, width-linewidth/2, height-linewidth/2);
        PDF_lineto(p, linewidth/2, height-linewidth/2);
        PDF_lineto(p, linewidth/2, linewidth/2);
        PDF_lineto(p, width-linewidth/2, height-linewidth/2);

        PDF_moveto(p, width-linewidth/2, linewidth/2);
        PDF_lineto(p, linewidth/2, height-linewidth/2);
        PDF_stroke(p);

        PDF_setfont(p, font, 24);

        sprintf(optlist, "fitmethod=auto position=center boxsize={%f %f}",
            width, height);
        PDF_fit_textline(p, "Proxy replaces target here", 0,
            0, 0, optlist);

	PDF_end_template_ext(p, 0, 0);


        /* Create the page */
        PDF_begin_page_ext(p, 595, 842, "");

        PDF_setfont(p, font, 18);

        PDF_fit_textline(p,
            "PDF/X-5 starter sample with reference to an external page", 0,
            50, 700, "");

        /* Place the proxy on the page */
        PDF_fit_image(p, proxy, 50, 50, "boxsize={500 500} fitmethod=meet");

        PDF_end_page_ext(p, "");
        PDF_end_document(p, "");
    }

    PDF_CATCH(p) {
        printf("PDFlib exception occurred:\n");
        printf("[%d] %s: %s\n",
            PDF_get_errnum(p), PDF_get_apiname(p), PDF_get_errmsg(p));
        PDF_delete(p);
        return(2);
    }

    PDF_delete(p);

    return 0;
}
コード例 #3
0
int
main(void)
{

    /* This is where the data files are. Adjust as necessary. */
    const char* searchpath = "../data";
    const char* outfile = "starter_layer.pdf";

    PDF * p;
    const char* rgb = "nesrin.jpg";
    const char* gray = "nesrin_gray.jpg";

#define BUFLEN 1024
    char buf[BUFLEN];
    int font, imageRGB, imageGray, layerRGB, layerGray, layerEN, layerDE;

    /* create a new PDFlib object */
    if ((p = PDF_new()) == (PDF *) 0) {
        printf("Couldn't create PDFlib object (out of memory)!\n");
        return(2);
    }

    PDF_TRY(p) {
        PDF_set_parameter(p, "SearchPath", searchpath);

        /* This means we must check return values of load_font() etc. */
        PDF_set_parameter(p, "errorpolicy", "return");


        /* Open the document with the "Layers" navigation tab visible */
        if (PDF_begin_document(p, outfile, 0, "openmode=layers") == -1) {
            printf("Error: %s\n", PDF_get_errmsg(p));
            PDF_delete(p);
            return(2);
        }

        PDF_set_info(p, "Creator", "PDFlib starter sample");
        PDF_set_info(p, "Title", "starter_layer");

        /* Load the font */
        font = PDF_load_font(p, "Helvetica", 0, "winansi", "");

        if (font == -1) {
            printf("Error: %s\n", PDF_get_errmsg(p));
            PDF_delete(p);
            return(2);
        }

        /* Load the Grayscale image */
        imageGray = PDF_load_image(p, "auto", gray, 0, "");
        if (imageGray == -1) {
            printf("Error: %s\n", PDF_get_errmsg(p));
            PDF_delete(p);
            return(2);
        }

        /* Load the RGB image */
        imageRGB = PDF_load_image(p, "auto", rgb, 0, "");
        if (imageRGB == -1) {
            printf("Error: %s\n", PDF_get_errmsg(p));
            PDF_delete(p);
            return(2);
        }

        /*
         * Define all layers which will be used, and their relationships.
         * This should be done before the first page if the layers are
         * used on more than one page.
         */

        /* Define the layer "RGB" */
        layerRGB = PDF_define_layer(p, "RGB", 0, "");

        /* Define the layer "Grayscale" which is hidden when opening the
         * document or printing it. */
        layerGray = PDF_define_layer(p, "Grayscale", 0,
                    "initialviewstate=false initialprintstate=false");

        /* At most one of the "Grayscale" and "RGB" layers should be visible */
        sprintf(buf, "group={%d %d}", layerGray, layerRGB);
        PDF_set_layer_dependency(p, "Radiobtn", buf);

        /* Define the layer "English" */
        layerEN = PDF_define_layer(p, "English", 0, "");

        /* Define the layer "German" which is hidden when opening the document
         * or printing it. */
        layerDE = PDF_define_layer(p, "German", 0,
                    "initialviewstate=false initialprintstate=false");

        /* At most one of the "English" and "German" layers should be visible */
        sprintf(buf, "group={%d %d}", layerEN, layerDE);
        PDF_set_layer_dependency(p, "Radiobtn", buf);

        /* Start page */
        PDF_begin_page_ext(p, 0, 0, "width=a4.width height=a4.height");

	/* Place the RGB image on the layer "RGB" */
        PDF_begin_layer(p, layerRGB);
        PDF_fit_image(p, imageRGB, 100, 400,
                    "boxsize={400 300} fitmethod=meet");

	/* Place the Grayscale image on the layer "Grayscale" */
        PDF_begin_layer(p, layerGray);
        PDF_fit_image(p, imageGray, 100, 400,
                    "boxsize={400 300} fitmethod=meet");

	/* Place an English image caption on the layer "English" */
        PDF_begin_layer(p, layerEN);
        sprintf(buf, "font=%d fontsize=20", font);
        PDF_fit_textline(p, "This is the Nesrin image.", 0, 100, 370, buf);

	/* Place a German image caption on the layer "German".  */
        PDF_begin_layer(p, layerDE);
        sprintf(buf, "font=%d fontsize=20", font);
        PDF_fit_textline(p, "Das ist das Nesrin-Bild.", 0, 100, 370, buf);

        PDF_end_layer(p);

        PDF_end_page_ext(p, "");

        PDF_end_document(p, "");

    }

    PDF_CATCH(p) {
        printf("PDFlib exception occurred:\n");
        printf("[%d] %s: %s\n",
            PDF_get_errnum(p), PDF_get_apiname(p), PDF_get_errmsg(p));
        PDF_delete(p);
        return(2);
    }

    PDF_delete(p);
    return 0;
}