コード例 #1
0
ファイル: SamplePdfTool.cpp プロジェクト: iroot/sopdf
void
drawmain(int argc, char **argv)
{
	fz_error *error;
	char *password = "";
	int c;
	enum { NO_FILE_OPENED, NO_PAGES_DRAWN, DREW_PAGES } state;

	while ((c = getopt(argc, argv, "b:d:o:r:txm")) != -1)
	{
		switch (c)
		{
		case 'b': drawbands = atoi(optarg); break;
		case 'd': password = optarg; break;
		case 'o': drawpattern = optarg; break;
		case 'r': drawzoom = (float)(atof(optarg) / 72.0); break;
		case 't': drawmode = DRAWTXT; break;
		case 'x': drawmode = DRAWXML; break;
		case 'm': benchmark = 1; break;
		default:
			  drawusage();
			  break;
		}
	}

	if (optind == argc)
		drawusage();

	error = fz_newrenderer(&drawgc, pdf_devicergb, 0, 1024 * 512);
	if (error)
		die(error);

	state = NO_FILE_OPENED;
	while (optind < argc)
	{
		if (strstr(argv[optind], ".pdf"))
		{
			if (state == NO_PAGES_DRAWN)
				drawpages("1-");

			opensrc(argv[optind], password, 1);
			state = NO_PAGES_DRAWN;
		}
		else
		{
			drawpages(argv[optind]);
			state = DREW_PAGES;
		}
		optind++;
	}

	if (state == NO_PAGES_DRAWN)
		drawpages("1-");

	closesrc();

	fz_droprenderer(drawgc);
}
コード例 #2
0
ファイル: copyout.c プロジェクト: Distrotech/hfsutils
/*
 * NAME:	openfiles()
 * DESCRIPTION:	open source and destination files
 */
static
int openfiles(hfsvol *vol, const char *srcname, const char *dstname,
	      const char *ext, hfsfile **ifile, int *ofile)
{
  const char *dsthint;

  *ifile = opensrc(vol, srcname, &dsthint, ext);
  if (*ifile == 0)
    return -1;

  *ofile = opendst(dstname, dsthint);
  if (*ofile == -1)
    {
      hfs_close(*ifile);
      return -1;
    }

  return 0;
}
コード例 #3
0
void
drawmain(int argc, char **argv)
{
    fz_error *error;
    char *password = "";
    int c;

    while ((c = getopt(argc, argv, "b:d:o:r:tx")) != -1)
    {
        switch (c)
        {
        case 'b': drawbands = atoi(optarg); break;
        case 'd': password = optarg; break;
        case 'o': drawpattern = optarg; break;
        case 'r': drawzoom = atof(optarg) / 72.0; break;
        case 't': drawmode = DRAWTXT; break;
        case 'x': drawmode = DRAWXML; break;
        default:
                  drawusage();
                  break;
        }
    }

    if (optind == argc)
        drawusage();

    error = fz_newrenderer(&drawgc, pdf_devicergb, 0, 1024 * 512);
    if (error)
        die(error);

    while (optind < argc)
    {
        if (strstr(argv[optind], ".pdf"))
            opensrc(argv[optind], password, 1);
        else
            drawpages(argv[optind]);
        optind++;
    }

    closesrc();

    fz_droprenderer(drawgc);
}
コード例 #4
0
ファイル: SamplePdfTool.cpp プロジェクト: iroot/sopdf
void
showmain(int argc, char **argv)
{
	int c;

	while ((c = getopt(argc, argv, "bd")) != -1)
	{
		switch (c)
		{
		case 'b': showbinary ++; break;
		case 'd': showdecode ++; break;
		default:
			  showusage();
			  break;
		}
	}

	if (optind == argc)
		showusage();

	opensrc(argv[optind++], "", 0);

	if (optind == argc)
		showtrailer();

	while (optind < argc)
	{
		if (!strcmp(argv[optind], "trailer"))
			showtrailer();
		else if (!strcmp(argv[optind], "xref"))
			showxref();
		else
			showobject(atoi(argv[optind]), 0);
		optind++;
	}
}
コード例 #5
0
ファイル: SamplePdfTool.cpp プロジェクト: iroot/sopdf
void
cleanmain(int argc, char **argv)
{
	int doencrypt = 0;
	int dogarbage = 0;
	int doexpand = 0;
	pdf_crypt *encrypt = nil;
	char *infile;
	char *outfile = "out.pdf";
	char *userpw = "";
	char *ownerpw = "";
	unsigned perms = 0xfffff0c0;	/* nothing allowed */
	int keylen = 40;
	char *password = "";
	fz_error *error;
	int c;

	while ((c = getopt(argc, argv, "d:egn:o:p:u:x")) != -1)
	{
		switch (c)
		{
		case 'p':
			/* see TABLE 3.15 User access permissions */
			perms = 0xfffff0c0;
			if (strchr(optarg, 'p')) /* print */
				perms |= (1 << 2) | (1 << 11);
			if (strchr(optarg, 'm')) /* modify */
				perms |= (1 << 3) | (1 << 10);
			if (strchr(optarg, 'c')) /* copy */
				perms |= (1 << 4) | (1 << 9);
			if (strchr(optarg, 'a')) /* annotate / forms */
				perms |= (1 << 5) | (1 << 8);
			break;
		case 'd': password = optarg; break;
		case 'e': doencrypt ++; break;
		case 'g': dogarbage ++; break;
		case 'n': keylen = atoi(optarg); break;
		case 'o': ownerpw = optarg; break;
		case 'u': userpw = optarg; break;
		case 'x': doexpand ++; break;
		default: cleanusage(); break;
		}
	}

	if (argc - optind < 1)
		cleanusage();

	infile = argv[optind++];
	if (argc - optind > 0)
		outfile = argv[optind++];

	opensrc(infile, password, 0);

	if (doencrypt)
	{
		fz_obj *id = fz_dictgets(src->trailer, "ID");
		if (!id)
		{
			error = fz_packobj(&id, "[(ABCDEFGHIJKLMNOP)(ABCDEFGHIJKLMNOP)]");
			if (error)
				die(error);
		}
		else
			fz_keepobj(id);

		error = pdf_newencrypt(&encrypt, userpw, ownerpw, perms, keylen, id);
		if (error)
			die(error);

		fz_dropobj(id);
	}

	if (doexpand)
		cleanexpand();

	if (dogarbage)
	{
		preloadobjstms();
		pdf_garbagecollect(src);
	}

	error = pdf_savexref(src, outfile, encrypt);
	if (error)
		die(error);

	if (encrypt)
		pdf_dropcrypt(encrypt);

	pdf_closexref(src);
}
コード例 #6
0
ファイル: SamplePdfTool.cpp プロジェクト: iroot/sopdf
void
editmain(int argc, char **argv)
{
	char *outfile = "out.pdf";
	fz_error *error;
	int c;

	while ((c = getopt(argc, argv, "o:")) != -1)
	{
		switch (c)
		{
		case 'o':
			outfile = optarg;
			break;
		default:
			editusage();
			break;
		}
	}

	if (optind == argc)
		editusage();

	error = pdf_newxref(&editxref);
	if (error)
		die(error);

	error = pdf_initxref(editxref);
	if (error)
		die(error);

	error = fz_newarray(&editpagelist, 100);
	if (error)
		die(error);

	error = fz_newarray(&editmodelist, 100);
	if (error)
		die(error);

	while (optind < argc)
	{
		if (strstr(argv[optind], ".pdf"))
		{
			if (editobjects)
				editflushobjects();

			opensrc(argv[optind], "", 1);

			error = fz_newarray(&editobjects, 100);
			if (error)
				die(error);
		}
		else if (!strcmp(argv[optind], "copy"))
			editmode = COPY;
		else if (!strcmp(argv[optind], "over"))
			editmode = OVER;
		else if (!strcmp(argv[optind], "2up"))
			editmode = NUP2;
		else if (!strcmp(argv[optind], "4up"))
			editmode = NUP4;
		else if (!strcmp(argv[optind], "8up"))
			editmode = NUP8;
		else
			editpages(argv[optind]);
		optind++;
	}

	if (editobjects)
		editflushobjects();

	closesrc();

	editflushpagetree();
	editflushcatalog();

	error = pdf_savexref(editxref, outfile, nil);
	if (error)
		die(error);

	pdf_closexref(editxref);
}