コード例 #1
0
ファイル: pdfapp.c プロジェクト: arbitrary-dev/mupdf
static int make_fake_doc(pdfapp_t *app)
{
	fz_context *ctx = app->ctx;
	pdf_document *pdf = NULL;
	fz_buffer *contents = NULL;
	pdf_obj *page_obj = NULL;

	fz_var(contents);
	fz_var(page_obj);

	fz_try(ctx)
	{
		fz_rect mediabox = { 0, 0, app->winw, app->winh };
		int i;

		pdf = pdf_create_document(ctx);


		contents = fz_new_buffer(ctx, 100);
		fz_append_printf(ctx, contents, "1 0 0 RG %g w 0 0 m %g %g l 0 %g m %g 0 l s\n",
			fz_min(mediabox.x1, mediabox.y1) / 20,
			mediabox.x1, mediabox.y1,
			mediabox.y1, mediabox.x1);

		/* Create enough copies of our blank(ish) page so that the
		 * page number is preserved if and when a subsequent load
		 * works. */
		page_obj = pdf_add_page(ctx, pdf, &mediabox, 0, NULL, contents);
		for (i = 0; i < app->pagecount; i++)
			pdf_insert_page(ctx, pdf, -1, page_obj);
	}
	fz_always(ctx)
	{
		pdf_drop_obj(ctx, page_obj);
		fz_drop_buffer(ctx, contents);
	}
	fz_catch(ctx)
	{
		fz_drop_document(ctx, (fz_document *) pdf);
		return 1;
	}

	app->doc = (fz_document*)pdf;
	return 0;
}
コード例 #2
0
ファイル: pdfapp.c プロジェクト: asbloomf/mupdf
static int make_fake_doc(pdfapp_t *app)
{
	fz_context *ctx = app->ctx;
	pdf_document *pdf = NULL;
	fz_buffer *contents = NULL;

	fz_try(ctx)
	{
		fz_rect mediabox = { 0, 0, app->winw, app->winh };
		pdf_obj *page_obj;
		int i;

		contents = fz_new_buffer(ctx, 100);
		pdf = pdf_create_document(ctx);

		app->doc = (fz_document*)pdf;

		fz_buffer_printf(ctx, contents, "1 0 0 rg %f w 0 0 m %f %f l 0 %f m %f 0 l\n",
			fz_min(mediabox.x1, mediabox.y1) / 4,
			mediabox.x1, mediabox.y1,
			mediabox.y1, mediabox.x1);

		/* Create enough copies of our blank(ish) page so that the
		 * page number is preserved if and when a subsequent load
		 * works. */
		page_obj = pdf_add_page(ctx, pdf, &mediabox, 0, contents, NULL);
		for (i = 0; i < app->pagecount; i++)
			pdf_insert_page(ctx, pdf, -1, page_obj);
		pdf_drop_obj(ctx, page_obj);
	}
	fz_always(ctx)
	{
		fz_drop_buffer(ctx, contents);
	}
	fz_catch(ctx)
	{
		fz_rethrow(ctx);
	}
	return 0;
}
コード例 #3
0
ファイル: pdfportfolio.c プロジェクト: muennich/mupdf
			pdf_obj *font_obj, *page_obj;
			pdf_obj *resources;
			fz_buffer *contents;
			fz_rect mediabox = { 0, 0, 400, 500 };

			data = fz_lookup_base14_font(ctx, "Times-Roman", &size);
			font = fz_new_font_from_memory(ctx, "Times-Roman", data, size, 0, 0);
			font_obj = pdf_add_simple_font(ctx, doc, font, PDF_SIMPLE_ENCODING_LATIN);
			fz_drop_font(ctx, font);

			resources = pdf_add_new_dict(ctx, doc, 1);
			pdf_dict_putp_drop(ctx, resources, "Font/Tm", font_obj);

			contents = fz_new_buffer_from_shared_data(ctx, (const unsigned char *)template, strlen(template));

			page_obj = pdf_add_page(ctx, doc, &mediabox, 0, resources, contents);
			pdf_insert_page(ctx, doc, -1, page_obj);
			pdf_drop_obj(ctx, page_obj);
			pdf_drop_obj(ctx, resources);
			fz_drop_buffer(ctx, contents);
		}
	}

	if (fz_optind == argc)
		usage();

	while (fz_optind < argc)
	{
		fz_optarg = argv[fz_optind++];
		fz_try(ctx)
		{