Example #1
0
int
main(int argc, char *argv[])
{
    char	*pdffilename = NULL;
    FILE	*imagefile;
    PDF		*p;
    int		image;
    int		opt;
    int		resolution = 0;
    int		page_numbering = 0;
    int		current_page = 1;
    char	optlist[128];

    while ((opt = getopt(argc, argv, "r:o:p:w")) != -1)
	switch (opt) {
	    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();
		}

	    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();
    }

    p = PDF_new();

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

    PDF_set_info(p, "Creator", "pdfimage");

    while (optind++ < argc) {
	fprintf(stderr, "Processing image file '%s'...\n", argv[optind-1]);

	image = PDF_load_image(p, "auto", argv[optind-1], 0, "");

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

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

	/* define outline with filename or page number */
	if (page_numbering) {
	    char buf[32];
	    sprintf(buf, "Page %d", current_page++);
	    PDF_add_bookmark(p, buf, 0, 0);
	} else {
	    PDF_add_bookmark(p, argv[optind-1], 0, 0);
	}

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

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

	PDF_end_page(p);
    }

    PDF_close(p);
    PDF_delete(p);
    exit(0);
}
Example #2
0
int
main(void)
{
    PDF *p;
    int image;
    char *imagefile = "nesrin.jpg";

    /* This is where font/image/PDF input files live. Adjust as necessary. */
    char *searchpath = "../data";

    /* 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){
	/* open new PDF file */
	if (PDF_open_file(p, "image.pdf") == -1) {
	    printf("Error: %s\n", PDF_get_errmsg(p));
	    return(2);
	}

	PDF_set_parameter(p, "SearchPath", searchpath);

	/* This line is required to avoid problems on Japanese systems */
	PDF_set_parameter(p, "hypertextencoding", "host");

	PDF_set_info(p, "Creator", "image.c");
	PDF_set_info(p, "Author", "Thomas Merz");
	PDF_set_info(p, "Title", "image sample (C)");

	image = PDF_load_image(p, "auto", imagefile, 0, "");

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

	/* dummy page size, will be adjusted by PDF_fit_image() */
	PDF_begin_page(p, 10, 10);
	PDF_fit_image(p, image, (float) 0.0, (float) 0.0, "adjustpage");
	PDF_close_image(p, image);
	PDF_end_page(p);			/* close page		*/

	PDF_close(p);				/* close PDF document	*/
    }

    PDF_CATCH(p) {
        printf("PDFlib exception occurred in image sample:\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);				/* delete the PDFlib object */

    return 0;
}
Example #3
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;
}
Example #4
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;
}
Example #5
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;
}
BOOL CTWainHelper::SaveAsPdf(const char* pFileName, std::vector< HANDLE > m_pic_handles)
{
	PDF *p;
    int image;
    const char *imagefile = "/pvf/pic.jpg";
	
    /* This is where font/image/PDF input files live. Adjust as necessary. */
    const char *searchpath = "./";
	
    /* create a new PDFlib object */
    if ((p = PDF_new()) == (PDF *) 0)
    {
        printf("Couldn't create PDFlib object (out of memory)!\n");
        return FALSE;
    }
	
    PDF_TRY(p){
		/* This means we must check return values of load_font() etc. */
		PDF_set_parameter(p, "errorpolicy", "return");
		
		/* This line is required to avoid problems on Japanese systems */
		PDF_set_parameter(p, "hypertextencoding", "host");

		if (PDF_begin_document(p, pFileName, 0, "") == -1) {
			printf("Error: %s\n", PDF_get_errmsg(p));
			return FALSE;
		}
		
		PDF_set_parameter(p, "SearchPath", searchpath);
		
		PDF_set_info(p, "Creator", "TWainApp");
		PDF_set_info(p, "Author", "Snail");
		PDF_set_info(p, "Title", "image sample (C)");

		std::vector< HANDLE >::iterator it;
		for(it = m_pic_handles.begin(); it != m_pic_handles.end(); it++)
		{
			//将Handle转换为CxImage对象
			HANDLE imageHandle = (HANDLE)(*it);
			CxImage cxImage;
			cxImage.CreateFromHANDLE(imageHandle);
			//cxImage.Save("C:\\bmp.bmp", CXIMAGE_FORMAT_BMP);
			cxImage.Save(".\\temp\\temp.jpg", CXIMAGE_FORMAT_JPG);

			char* imagedata = NULL;
			DWORD size = 0;

			CFile file(".\\temp\\temp.jpg", CFile::modeRead);
			size = file.GetLength();
			imagedata = new char[size];
			memset(imagedata, 0, size);
			file.Read(imagedata, size);
			file.Close();

			PDF_create_pvf(p, imagefile, 0, (const char*)imagedata, size, "");

			image = PDF_load_image(p, "auto", imagefile, 0, "");

			if (image == -1) {
				char logInfo[LOGSIZE];
				sprintf(logInfo, "Error: 加载PVF图像数据失败!错误号:%d, %s:%d\r\n", PDF_get_errmsg(p), __FILE__, __LINE__);
				CTWainHelper::LogMessage(logInfo);

				if(imagedata)
					delete imagedata;
				
				continue;
			}

			/* dummy page size, will be adjusted by PDF_fit_image() */
			PDF_begin_page_ext(p, 10, 10, "");
			PDF_fit_image(p, image, 0.0, 0.0, "adjustpage dpi {300 300}");
			PDF_end_page_ext(p, "");

			/* Delete the virtual file to free the allocated memory */
			PDF_delete_pvf(p, imagefile, 0);

			if(imagedata)
				delete imagedata;
		}

		PDF_end_document(p, "");    

		::DeleteFile(".\\temp\\temp.jpg");
	}	
    PDF_CATCH(p) {

		char logInfo[LOGSIZE];
		sprintf(logInfo, "EXCEPTION: PDFlib接口调用过程发生异常!错误信息:[%d] %s: %s, %s:%d\r\n", 
			PDF_get_errmsg(p), PDF_get_apiname(p), PDF_get_errmsg(p), __FILE__, __LINE__);
		CTWainHelper::LogMessage(logInfo);

        PDF_delete(p);
        return FALSE;
    }
	
    PDF_delete(p);
	return TRUE;
}
Example #7
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);
}
Example #8
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;
    int font, image;

    /* 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_basic.pdf", 0, "") == -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_basic");

        /* We load the image before the first page, and use it
         * on all pages
         */
        image = PDF_load_image(p, "auto", imagefile, 0, "");

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

        /* Page 1 */
        PDF_begin_page_ext(p, 595, 842, "");

        font = PDF_load_font(p, "Helvetica-Bold", 0, "winansi", "");

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

        PDF_setfont(p, font, 24);

        PDF_set_text_pos(p, 50, 700);
        PDF_show(p, "Hello world!");

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

        PDF_end_page_ext(p, "");

        /* Page 2 */
        PDF_begin_page_ext(p, 595, 842, "");

        /* red rectangle */
        PDF_setcolor(p, "fill", "rgb", 1.0, 0.0, 0.0, 0.0);
        PDF_rect(p, 200, 200, 250, 150);
        PDF_fill(p);

        /* blue circle */
        PDF_setcolor(p, "fill", "rgb", 0.0, 0.0, 1.0, 0.0);
        PDF_arc(p, 400, 600, 100, 0, 360);
        PDF_fill(p);

        /* thick gray line */
        PDF_setcolor(p, "stroke", "gray", 0.5, 0.0, 0.0, 0.0);
        PDF_setlinewidth(p, 10);
        PDF_moveto(p, 100, 500);
        PDF_lineto(p, 300, 700);
        PDF_stroke(p);

        /* Using the same image handle means the data will be copied
         * to the PDF only once, which saves space.
         */
        PDF_fit_image(p, image, 150.0, 25.0, "scale=0.25");
        PDF_end_page_ext(p, "");

        /* Page 3 */
        PDF_begin_page_ext(p, 595, 842, "");

        /* Fit the image to a box of predefined size (without distortion) */
        optlist =
        "boxsize={400 400} position={center} fitmethod=meet";

        PDF_fit_image(p, image, 100, 200, optlist);

        PDF_end_page_ext(p, "");

        PDF_close_image(p, image);
        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;
}