示例#1
0
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(int argc, char *argv[])
{
    char	*pdffilename = NULL;
    char	*imagetype = "auto";
    char	*useroptions = "";
    PDF		*p;
    int		image;
#ifndef PDFLIB_LITE
    int		tagged, opt;
    int		item=0;
    char 	*pdfalevel = NULL, *intent = "sRGB";
#endif /* PDFLIB_LITE */
    int		resolution = 0;
    int		page_numbering = 0;
    double	graylevel = -1.0;
    int		frame;
    int		current_page = 1;
#define BUFLEN	1024
    char	optlist[BUFLEN];
    char	buf[BUFLEN];

#ifndef PDFLIB_LITE
    while ((opt = getopt(argc, argv, "a:g:I:i:o:p:r:t:")) != -1)
#else
    while ((opt = getopt(argc, argv, "g:i:o:p:r:t:")) != -1)
#endif /* PDFLIB_LITE */
	switch (opt) {
#ifndef PDFLIB_LITE
	    case 'a':
		if (strcmp(optarg, "none"))
		    pdfalevel = optarg;
		break;
#endif /* PDFLIB_LITE */

	    case 'g':
		if (optarg) {
		    graylevel = atof(optarg);
		    if (graylevel < 0.0 || graylevel > 1.0)
		    {
			fprintf(stderr, "Error: Bad gray level %.2g for -g.\n",
				graylevel);
			usage();
		    }
		}
		break;

#ifndef PDFLIB_LITE
	    case 'I':
		if (!strcmp(optarg, "none"))
		    intent = NULL;
		else
		    intent = optarg;
		break;
#endif /* PDFLIB_LITE */

	    case 'i':
		useroptions = optarg;
		if (strlen(useroptions) > BUFLEN-20)
		{
		    fprintf(stderr, "Error: image option list too long.\n");
		    usage();
		}
		break;

	    case 'o':
		pdffilename = optarg;
		break;

	    case 'p':
		page_numbering = 1;
		if (optarg) {
		    current_page = atoi(optarg);
		}
		break;

	    case 'r':
		if (!optarg || (resolution = atoi(optarg)) <= 0) {
		    fprintf(stderr, "Error: non-positive resolution.\n");
		    usage();
		}
		break;

	    case 't':
		imagetype = optarg;
		break;

	    case '?':
	    default:
		usage();
	}

    if (optind == argc) {
	fprintf(stderr, "Error: no image files given.\n");
	usage();
    }

    if (pdffilename == NULL) {
	fprintf(stderr, "Error: no output file given.\n");
	usage();
    }

    if ((p = PDF_new()) == (PDF *) 0)
    {
        fprintf(stderr, "Couldn't create PDFlib object (out of memory)!\n");
	exit(99);
    }

    PDF_TRY(p)
    {
	optlist[0] = 0;

#ifndef PDFLIB_LITE
	tagged = pdfalevel && !strcmp(pdfalevel, "PDF/A-1a:2005");

	if (pdfalevel)
	{
            /* disabled (see bug #1577)
	    if (tagged)
		sprintf(optlist, "pdfa=%s lang=en", pdfalevel);
	    else
            */
		sprintf(optlist, "pdfa=%s", pdfalevel);
	}
#endif /* PDFLIB_LITE */

	if (PDF_begin_document(p, pdffilename, 0, optlist) == -1) {
	    fprintf(stderr, "Error: cannot open output file %s.\n",
		pdffilename);
	    exit(1);
	}

#ifndef PDFLIB_LITE
	if (pdfalevel && intent)
	{
	    if (strcmp("sRGB", intent))
	    {
		sprintf(optlist, "Intent=%s", intent);
		PDF_set_parameter(p, "ICCProfile", optlist);
	    }
	    fprintf(stderr, "Using '%s' as PDF/A output intent.\n", intent);
	    PDF_load_iccprofile(p, intent, 0, "usage=outputintent");
	}

	if (tagged)
	    item = PDF_begin_item(p, "Document",
	    	"Alt={Images converted with pdfimage by PDFlib GmbH}");
#endif /* PDFLIB_LITE */

	PDF_set_info(p, "Creator", "pdfimage");
	PDF_set_parameter(p, "warning", "false");

	while (optind++ < argc)
	{
#ifndef PDFLIB_LITE
	    int item2=0;
#endif /* PDFLIB_LITE */
	    int parent=0;

	    fprintf(stderr, "Processing image file '%s'...", argv[optind-1]);

	    /* process all frames in a multi-page image file */
	    for (frame=1; /* */; frame++)
	    {
		sprintf(optlist, "%s page %d", useroptions, frame);
		image = PDF_load_image(p, imagetype, argv[optind-1],0, optlist);

		if (image == -1) {
		    if (frame == 1)
			fprintf(stderr, "\n%s (skipped).\n", PDF_get_errmsg(p));
		    break;
		}

		/* dummy page size, will be adjusted later */
		PDF_begin_page_ext(p, 20, 20, "");

		if (graylevel >= 0.0)
		{
		    if (pdfalevel)
		    {
			PDF_setcolor(p, "fill",
				"lab", graylevel, 0.0, 0.0, 0.0);
		    }
		    else
		    {
			PDF_setcolor(p, "fill",
				"gray", graylevel, 0.0, 0.0, 0.0);
		    }
		    PDF_rect(p, 0, 0, 10000, 10000);
		    PDF_fill(p);
		}

		/* define outline with filename or page number */
		if (page_numbering)
		{
		    sprintf(buf, "Page %d", current_page++);
		    PDF_create_bookmark(p, buf, 0, "");
		}
		else {
		    if (frame == 1)
		    {
			parent = PDF_create_bookmark(p, argv[optind-1], 0,
						"open");
		    }
		    else
		    {
			sprintf(buf, "page %d", frame);
			sprintf(optlist, "parent=%d", parent);
			PDF_create_bookmark(p, buf, 0, optlist);
		    }
		}

#ifndef PDFLIB_LITE
		if (tagged)
		{
		    /* The file name is the best /Alt value we can provide */
		    sprintf(optlist, "Alt={%s}", argv[optind-1]);
		    item2 = PDF_begin_item(p, "Figure", optlist);
		}
#endif /* PDFLIB_LITE */

		if (resolution != 0)
		    sprintf(optlist, "dpi %d adjustpage", resolution);
		else
		    sprintf(optlist, "adjustpage");

		PDF_fit_image(p, image, 0.0, 0.0, optlist);

#ifndef PDFLIB_LITE
		if (tagged)
		    PDF_end_item(p, item2);
#endif /* PDFLIB_LITE */

		PDF_end_page_ext(p, "");
	    }

	    if (frame > 2)
		fprintf(stderr, "(%d frames)", frame-1);

	    fprintf(stderr, "\n");
	}

#ifndef PDFLIB_LITE
	if (tagged)
	    PDF_end_item(p, item);
#endif /* PDFLIB_LITE */

	PDF_end_document(p, "");
    }

    PDF_CATCH(p)
    {
        printf("\npdfimage: error while creating PDF output (%s(): %s)\n",
		PDF_get_apiname(p), PDF_get_errmsg(p));
        PDF_delete(p);
        exit(99);
    }

    PDF_delete(p);

    exit(0);
}