Ejemplo n.º 1
0
JNIEXPORT int JNICALL Java_com_artifex_mupdf_MuPDFCore_openFile(JNIEnv * env, jobject thiz, jstring jfilename)
{
    const char *filename;
    char *password = "";
    int accelerate = 1;
    fz_error error;

    filename = (*env)->GetStringUTFChars(env, jfilename, NULL);
    if (filename == NULL)
    {
        LOGE("Failed to get filename");
        return 0;
    }

    if (accelerate)
        fz_accelerate();
    glyphcache = fz_newglyphcache();
    colorspace = fz_devicergb;

    LOGE("Opening document...");
    error = pdf_openxref(&xref, filename, password);
    if (error)
    {
        LOGE("Cannot open document: '%s'\n", filename);
        return 0;
    }

    LOGE("Loading page tree...");
    error = pdf_loadpagetree(xref);
    if (error)
    {
        LOGE("Cannot load page tree: '%s'\n", filename);
        return 0;
    }
    LOGE("Done! %d pages", pdf_getpagecount(xref));

    return pdf_getpagecount(xref);
}
Ejemplo n.º 2
0
int main(int argc, char **argv)
{
	fz_error error;
	char *infile;
	char *outfile = "out.pdf";
	char *password = "";
	int c, num;
	int subset;

	while ((c = fz_getopt(argc, argv, "adgp:")) != -1)
	{
		switch (c)
		{
		case 'p': password = fz_optarg; break;
		case 'g': dogarbage ++; break;
		case 'd': doexpand ++; break;
		case 'a': doascii ++; break;
		default: usage(); break;
		}
	}

	if (argc - fz_optind < 1)
		usage();

	infile = argv[fz_optind++];

	if (argc - fz_optind > 0 &&
		(strstr(argv[fz_optind], ".pdf") || strstr(argv[fz_optind], ".PDF")))
	{
		outfile = argv[fz_optind++];
	}

	subset = 0;
	if (argc - fz_optind > 0)
		subset = 1;

	error = pdf_openxref(&xref, infile, password);
	if (error)
		die(fz_rethrow(error, "cannot open input file '%s'", infile));

	out = fopen(outfile, "wb");
	if (!out)
		die(fz_throw("cannot open output file '%s'", outfile));

	fprintf(out, "%%PDF-%d.%d\n", xref->version / 10, xref->version % 10);
	fprintf(out, "%%\316\274\341\277\246\n\n");

	uselist = fz_calloc(xref->len + 1, sizeof(char));
	ofslist = fz_calloc(xref->len + 1, sizeof(int));
	genlist = fz_calloc(xref->len + 1, sizeof(int));
	renumbermap = fz_calloc(xref->len + 1, sizeof(int));

	for (num = 0; num < xref->len; num++)
	{
		uselist[num] = 0;
		ofslist[num] = 0;
		genlist[num] = 0;
		renumbermap[num] = num;
	}

	/* Make sure any objects hidden in compressed streams have been loaded */
	preloadobjstms();

	/* Only retain the specified subset of the pages */
	if (subset)
		retainpages(argc, argv);

	/* Sweep & mark objects from the trailer */
	if (dogarbage >= 1)
		sweepobj(xref->trailer);

	/* Coalesce and renumber duplicate objects */
	if (dogarbage >= 3)
		removeduplicateobjs();

	/* Compact xref by renumbering and removing unused objects */
	if (dogarbage >= 2)
		compactxref();

	/* Make renumbering affect all indirect references and update xref */
	if (dogarbage >= 2)
		renumberobjs();

	writepdf();

	if (fclose(out))
		die(fz_throw("cannot close output file '%s'", outfile));

	fz_free(uselist);
	fz_free(ofslist);
	fz_free(genlist);
	fz_free(renumbermap);

	pdf_freexref(xref);

	fz_flushwarnings();

	return 0;
}
Ejemplo n.º 3
0
void pdfapp_open(pdfapp_t *app, char *filename)
{
    fz_obj *obj;
    fz_obj *info;
    char *password = "";

    /*
     * Open PDF and load xref table
     */

    app->filename = filename;

    app->xref = pdf_openxref(filename);
    if (!app->xref)
        pdfapp_error(app, -1);

    /*
     * Handle encrypted PDF files
     */

    if (pdf_needspassword(app->xref))
    {
        int okay = pdf_authenticatepassword(app->xref, password);
        while (!okay)
        {
            password = winpassword(app, filename);
            if (!password)
                exit(1);
            okay = pdf_authenticatepassword(app->xref, password);
            if (!okay)
                pdfapp_warn(app, "Invalid password.");
        }
    }

    /*
     * Load meta information
     */

    app->outline = pdf_loadoutline(app->xref);

    app->doctitle = filename;
    if (strrchr(app->doctitle, '\\'))
        app->doctitle = strrchr(app->doctitle, '\\') + 1;
    if (strrchr(app->doctitle, '/'))
        app->doctitle = strrchr(app->doctitle, '/') + 1;
    info = fz_dictgets(app->xref->trailer, "Info");
    if (info)
    {
        obj = fz_dictgets(info, "Title");
        if (obj)
            app->doctitle = pdf_toutf8(obj);
    }

    /*
     * Start at first page
     */

    app->pagecount = pdf_getpagecount(app->xref);

    app->shrinkwrap = 1;
    if (app->pageno < 1)
        app->pageno = 1;
    if (app->zoom < 0.1)
        app->zoom = 0.1;
    if (app->zoom > 3.0)
        app->zoom = 3.0;
    app->rotate = 0;
    app->panx = 0;
    app->pany = 0;

    //code change by kakai
    //highlight color settings
    kno_setHighlightColor(app, 0x00ffff00);
    //code change by kakai

    pdfapp_showpage(app, 1, 1);
}