Beispiel #1
0
int convertPage(PopplerPage *page, const char* svgFilename)
{
	// Poppler stuff 
	double width, height;

	// Cairo stuff
	cairo_surface_t *surface;
	cairo_t *drawcontext;

	if (page == NULL) {
		fprintf(stderr, "Page does not exist\n");
		return -1;
	}
	poppler_page_get_size (page, &width, &height);

	// Open the SVG file
	surface = cairo_svg_surface_create(svgFilename, width, height);
	drawcontext = cairo_create(surface);

	// Render the PDF file into the SVG file
	poppler_page_render_for_printing(page, drawcontext);
	cairo_show_page(drawcontext);

	// Close the SVG file
	cairo_destroy(drawcontext);
	cairo_surface_destroy(surface);

	// Close the PDF file
	g_object_unref(page);
	
	return 0;     
}
Beispiel #2
0
// method: draw all the pages to appropriate recording surfaces and then get ink extents
void evenodd_cropboxes(PopplerDocument *document, cairo_rectangle_t *odd_page_crop_box, cairo_rectangle_t *even_page_crop_box) {
	GError *error = NULL;
	int num_document_pages = poppler_document_get_n_pages(document);

	cairo_surface_t *odd_pages = cairo_recording_surface_create(CAIRO_CONTENT_COLOR_ALPHA, NULL);
	cairo_surface_t *even_pages = cairo_recording_surface_create(CAIRO_CONTENT_COLOR_ALPHA, NULL);
	int page_num;
	for (page_num = 0; page_num < num_document_pages; page_num++) {
		cairo_surface_t *surface = odd_pages;
		if (page_num % 2 == 1) {
			surface = even_pages;
		}
		cairo_t *cr = cairo_create(surface);

		PopplerPage *page = poppler_document_get_page(document, page_num);
		if (page == NULL) {
			printf("%s:%d: %s\n", __FILE__, __LINE__, error->message);
			exit(1);		
		}

		poppler_page_render_for_printing(page, cr);
		g_object_unref(page);

		exit_if_cairo_status_not_success(cr, __FILE__, __LINE__);
		cairo_destroy(cr);
	}

	cairo_recording_surface_ink_extents(odd_pages,
		&odd_page_crop_box->x,
		&odd_page_crop_box->y,
		&odd_page_crop_box->width,
		&odd_page_crop_box->height);
	cairo_recording_surface_ink_extents(even_pages,
		&even_page_crop_box->x,
		&even_page_crop_box->y,
		&even_page_crop_box->width,
		&even_page_crop_box->height);

	// use to check extent and crop box handling
	// write_surface_to_file_showing_crop_box("odd.pdf", odd_pages, odd_page_crop_box);
	// write_surface_to_file_showing_crop_box("even.pdf", even_pages, even_page_crop_box);

	// cleanup surfaces used to get crop boxes
	cairo_surface_destroy(odd_pages);
	exit_if_cairo_surface_status_not_success(odd_pages, __FILE__, __LINE__);
	cairo_surface_destroy(even_pages);
	exit_if_cairo_surface_status_not_success(even_pages, __FILE__, __LINE__);
}
Beispiel #3
0
zathura_error_t
pdf_page_render_cairo(zathura_page_t* page, PopplerPage* poppler_page, cairo_t*
    cairo, bool printing)
{
  if (page == NULL || poppler_page == NULL || cairo == NULL) {
    return ZATHURA_ERROR_INVALID_ARGUMENTS;
  }

  if (printing == false) {
    poppler_page_render(poppler_page, cairo);
  } else {
    poppler_page_render_for_printing(poppler_page, cairo);
  }

  return ZATHURA_ERROR_OK;
}
Beispiel #4
0
void add_per_page_cropboxes(PopplerDocument *document, struct pages_t *pages) {
	GError *error = NULL;
	int num_document_pages = poppler_document_get_n_pages(document);	

	int page_num;
	for (page_num = 0; page_num < pages->npages; page_num++) {
		int document_page_num = pages->pages[page_num].num;

		printf("document_page_num: %d\n", document_page_num);

		if (document_page_num >= num_document_pages) {
			printf("ERROR: The document does not have page %d, it only has %d pages\n", document_page_num, num_document_pages);
			exit(2);
		}

		cairo_surface_t *surface = cairo_recording_surface_create(CAIRO_CONTENT_COLOR_ALPHA, NULL);
		cairo_t *cr = cairo_create(surface);

		PopplerPage *page = poppler_document_get_page(document, document_page_num);
		if (page == NULL) {
			printf("%s:%d: %s\n", __FILE__, __LINE__, error->message);
			exit(1);		
		}

		poppler_page_render_for_printing(page, cr);
		g_object_unref(page);

		exit_if_cairo_status_not_success(cr, __FILE__, __LINE__);
		cairo_destroy(cr);

		cairo_rectangle_t *crop_box = malloc(sizeof(cairo_rectangle_t));
		cairo_recording_surface_ink_extents(surface,
			&crop_box->x,
			&crop_box->y,
			&crop_box->width,
			&crop_box->height);

		// use to check extent and crop box handling
		// write_surface_to_file_showing_crop_box("per_page.pdf", surface, crop_box);

		// cleanup surfaces used to get crop boxes
		cairo_surface_destroy(surface);
		exit_if_cairo_surface_status_not_success(surface, __FILE__, __LINE__);

		pages->pages[page_num].crop_box = crop_box;
	}
}
Beispiel #5
0
static void
pgd_render_start (GtkButton     *button,
		  PgdRenderDemo *demo)
{
	PopplerPage *page;
	gdouble      page_width, page_height;
	gdouble      width, height;
	gint         x, y;
	gchar       *str;
	GTimer      *timer;
        cairo_t     *cr;

	page = poppler_document_get_page (demo->doc, demo->page);
	if (!page)
		return;

	if (demo->surface)
		cairo_surface_destroy (demo->surface);
	demo->surface = NULL;

	poppler_page_get_size (page, &page_width, &page_height);

	if (demo->rotate == 0 || demo->rotate == 180) {
		width = demo->slice.width * demo->scale;
		height = demo->slice.height * demo->scale;
		x = demo->slice.x * demo->scale;
		y = demo->slice.y * demo->scale;
	} else {
		width = demo->slice.height * demo->scale;
		height = demo->slice.width * demo->scale;
		x = demo->slice.y * demo->scale;
		y = demo->slice.x * demo->scale;
	}

        timer = g_timer_new ();
        demo->surface = cairo_image_surface_create (CAIRO_FORMAT_ARGB32,
                                                    width, height);
        cr = cairo_create (demo->surface);

        cairo_save (cr);
        switch (demo->rotate) {
        case 90:
                cairo_translate (cr, x + width, -y);
                break;
        case 180:
                cairo_translate (cr, x + width, y + height);
                break;
        case 270:
                cairo_translate (cr, -x, y + height);
                break;
        default:
                cairo_translate (cr, -x, -y);
        }

        if (demo->scale != 1.0)
                cairo_scale (cr, demo->scale, demo->scale);

        if (demo->rotate != 0)
                cairo_rotate (cr, demo->rotate * G_PI / 180.0);

        if (demo->printing)
                poppler_page_render_for_printing (page, cr);
        else
                poppler_page_render (page, cr);
        cairo_restore (cr);

        cairo_set_operator (cr, CAIRO_OPERATOR_DEST_OVER);
        cairo_set_source_rgb (cr, 1., 1., 1.);
        cairo_paint (cr);

        g_timer_stop (timer);

        cairo_destroy (cr);
	g_object_unref (page);

	str = g_strdup_printf ("<i>Page rendered in %.4f seconds</i>",
			       g_timer_elapsed (timer, NULL));
	gtk_label_set_markup (GTK_LABEL (demo->timer_label), str);
	g_free (str);

	g_timer_destroy (timer);

	gtk_widget_set_size_request (demo->darea, width, height);
	gtk_widget_queue_draw (demo->darea);
}
Beispiel #6
0
static VALUE
page_render_for_printing(VALUE self, VALUE cairo)
{
    poppler_page_render_for_printing(SELF(self), RVAL2CRCONTEXT(cairo));
    return Qnil;
}