static void zoom_rect(int x1, int y1, int x2, int y2) { cairo_t *ctx; cairo_surface_t *buf, *t; t = cairo_xlib_surface_create(dpy, wshow, vis, sw, sh); buf = cairo_surface_create_similar(t, CAIRO_CONTENT_COLOR, sw, sh); ctx = cairo_create(buf); cairo_surface_destroy(t); PopplerDocument *pdf; pdf = poppler_document_new_from_file(show->uri, NULL, NULL); PopplerPage *page = poppler_document_get_page(pdf, show->cur); double pdfw, pdfh; poppler_page_get_size(page, &pdfw, &pdfh); cairo_set_source_rgba(ctx, 1, 1, 1, 1); cairo_paint(ctx); double scx = show->w / pdfw, scy = show->h / pdfh; double dx = 0.0, dy = 0.0; if (conf.lock_aspect) { if (scx > scy) dx = (show->w - pdfw * (scx=scy)) / 2.0; else dy = (show->h - pdfh * (scy=scx)) / 2.0; } cairo_scale(ctx, scx * show->w /(double) (x2-x1), scy * show->h /(double) (y2-y1)); cairo_translate(ctx, (dx - x1)/scx, (dy - y1)/scy); poppler_page_render(page, ctx); cairo_set_source_surface(show->target[0].ctx, buf, 0, 0); int i; for (i = conf.fade; i; i--) { cairo_paint_with_alpha(show->target[0].ctx, 1/(float)i); XFlush(dpy); usleep(5000); } cairo_destroy(ctx); cairo_surface_destroy(buf); }
static void gvloadimage_poppler_cairo(GVJ_t * job, usershape_t *us, boxf b, boolean filled) { PopplerDocument* document = gvloadimage_poppler_load(job, us); PopplerPage* page; cairo_t *cr = (cairo_t *) job->context; /* target context */ cairo_surface_t *surface; /* source surface */ if (document) { // already done this once, so no err checking page = poppler_document_get_page (document, 0); cairo_save(cr); // FIXME #define IMAGE_DPI 72 surface = cairo_image_surface_create (CAIRO_FORMAT_ARGB32, IMAGE_DPI*(us->w)/72.0, IMAGE_DPI*(us->h)/72.0); cairo_surface_reference(surface); cairo_set_source_surface(cr, surface, 0, 0); cairo_translate(cr, ROUND(b.LL.x), ROUND(-b.UR.y)); cairo_scale(cr, (b.UR.x - b.LL.x) / us->w, (b.UR.y - b.LL.y) / us->h); poppler_page_render (page, cr); cairo_paint (cr); cairo_restore(cr); } }
static cairo_surface_t * pgd_find_render_page (PgdFindDemo *demo) { cairo_t *cr; PopplerPage *page; gdouble width, height; cairo_surface_t *surface = NULL; page = poppler_document_get_page (demo->doc, demo->selected_page); if (!page) return NULL; poppler_page_get_size (page, &width, &height); gtk_widget_set_size_request (demo->darea, width, height); surface = cairo_image_surface_create (CAIRO_FORMAT_RGB24, width, height); cr = cairo_create (surface); cairo_save (cr); cairo_set_source_rgb (cr, 1, 1, 1); cairo_rectangle (cr, 0, 0, width, height); cairo_fill (cr); cairo_restore (cr); cairo_save (cr); poppler_page_render (page, cr); cairo_restore (cr); cairo_destroy (cr); g_object_unref (page); return surface; }
static void ease_pdf_actor_draw_page (EasePdfActor* self) { #line 415 "ease-pdf-actor.c" PopplerPage* page; double width; double height; cairo_t* cr; GError * _inner_error_ = NULL; #line 58 "ease-pdf-actor.vala" g_return_if_fail (self != NULL); #line 61 "ease-pdf-actor.vala" page = _g_object_ref0 (poppler_document_get_page (self->priv->doc, self->priv->current_page)); #line 62 "ease-pdf-actor.vala" width = (double) 0; #line 62 "ease-pdf-actor.vala" height = (double) 0; #line 63 "ease-pdf-actor.vala" poppler_page_get_size (page, &width, &height); #line 66 "ease-pdf-actor.vala" if (self->priv->texture == NULL) { #line 433 "ease-pdf-actor.c" ClutterCairoTexture* _tmp0_; ClutterActor* _tmp1_; #line 68 "ease-pdf-actor.vala" self->priv->texture = (_tmp0_ = g_object_ref_sink ((ClutterCairoTexture*) clutter_cairo_texture_new ((guint) ((gint) width), (guint) ((gint) height))), _g_object_unref0 (self->priv->texture), _tmp0_); #line 69 "ease-pdf-actor.vala" clutter_container_add_actor ((ClutterContainer*) (_tmp1_ = ((EaseActor*) self)->contents, CLUTTER_IS_GROUP (_tmp1_) ? ((ClutterGroup*) _tmp1_) : NULL), (ClutterActor*) self->priv->texture); #line 71 "ease-pdf-actor.vala" clutter_actor_set_width ((ClutterActor*) self->priv->texture, clutter_actor_get_width (((EaseActor*) self)->contents)); #line 72 "ease-pdf-actor.vala" clutter_actor_set_height ((ClutterActor*) self->priv->texture, clutter_actor_get_height (((EaseActor*) self)->contents)); #line 74 "ease-pdf-actor.vala" g_signal_connect_object ((GObject*) ((EaseActor*) self)->contents, "notify::width", (GCallback) __lambda53__g_object_notify, self, 0); #line 78 "ease-pdf-actor.vala" g_signal_connect_object ((GObject*) ((EaseActor*) self)->contents, "notify::height", (GCallback) __lambda54__g_object_notify, self, 0); #line 448 "ease-pdf-actor.c" } else { #line 86 "ease-pdf-actor.vala" clutter_cairo_texture_set_surface_size (self->priv->texture, (guint) ((gint) width), (guint) ((gint) height)); #line 452 "ease-pdf-actor.c" } #line 90 "ease-pdf-actor.vala" clutter_cairo_texture_clear (self->priv->texture); #line 91 "ease-pdf-actor.vala" cr = clutter_cairo_texture_create (self->priv->texture); #line 92 "ease-pdf-actor.vala" ease_background_cairo_render (self->priv->pdf_element->background, cr, (gint) width, (gint) height, ease_document_get_path (ease_slide_get_parent (ease_element_get_parent (((EaseActor*) self)->element))), &_inner_error_); #line 460 "ease-pdf-actor.c" if (_inner_error_ != NULL) { _cairo_destroy0 (cr); _g_object_unref0 (page); g_critical ("file %s: line %d: uncaught error: %s (%s, %d)", __FILE__, __LINE__, _inner_error_->message, g_quark_to_string (_inner_error_->domain), _inner_error_->code); g_clear_error (&_inner_error_); return; } #line 94 "ease-pdf-actor.vala" poppler_page_render (page, cr); #line 470 "ease-pdf-actor.c" _cairo_destroy0 (cr); _g_object_unref0 (page); }
virtual bool page(int pageNum) { if (!_doc) return false; if (pageNum<0 || pageNum>=getNumOfPages()) return false; PopplerPage* page = poppler_document_get_page(_doc, pageNum); if(!page) return false; _pageNum = pageNum; double w = 0.0f; double h = 0.0f; poppler_page_get_size(page, &w, &h); _cairoImage->create((unsigned int)(w*2.0),(unsigned int)(h*2.0)); osg::clearImageToColor(this, _backgroundColor); cairo_save(_cairoImage->getContext()); cairo_scale(_cairoImage->getContext(), double(s())/w, double(t())/h); poppler_page_render(page, _cairoImage->getContext()); cairo_restore(_cairoImage->getContext()); g_object_unref (page); dirty(); return true; }
static void draw_page(SDL_Surface * dst, cairo_t * cr, PopplerDocument * document, int page_num) { cairo_status_t status; PopplerPage *page; /* Create a cairo drawing context, normalize it and draw a clock. */ SDL_LockSurface(dst); { page = poppler_document_get_page(document, page_num - 1); if (page == NULL) { printf("poppler fail: page not found\n"); return; } cairo_save(cr); poppler_page_render(page, cr); cairo_restore(cr); g_object_unref(page); status = cairo_status(cr); } SDL_UnlockSurface(dst); /* Nasty nasty error handling. */ if (status != CAIRO_STATUS_SUCCESS) { fprintf(stderr, "Unable to create or draw with a cairo context " "for the screen: %s\n", cairo_status_to_string(status)); exit(1); } }
PageInfo *analyse_page (PopplerDocument *doc, guint page_num) { PopplerPage *page; PageInfo *info; GdkPixbuf *image; double width_points, height_points; int width, height; gboolean *white_rows, *white_cols; page = poppler_document_get_page (doc, page_num); if (!page) { g_error ("Couldn't open page %d of document", page_num); } /* There are 72 points in an inch. So width and height should be * multiplied by settings.dpi / 72.0 */ poppler_page_get_size (page, &width_points, &height_points); width = (int) ((width_points * settings.dpi / 72.0) + 0.5); height = (int) ((height_points * settings.dpi / 72.0) + 0.5); image = gdk_pixbuf_new(GDK_COLORSPACE_RGB, TRUE, 8, width, height); if (!image) { g_error ("Couldn't create an image (size %d x %d) for page %d", width, height, page_num); } poppler_page_render_to_pixbuf (page, 0, 0, width, height, settings.dpi / 72.0, 0, image); g_object_unref (page); find_white (image, &white_rows, &white_cols); g_object_unref (image); guint firstrow, lastrow, hunkscount; HunkData* hunks = find_hunks (white_rows, height, &firstrow, &lastrow, &hunkscount); info = g_new (PageInfo, 1); info->bbox.x = first_zero (white_cols, width); info->bbox.width = last_zero (white_cols, width) - info->bbox.x; if (info->bbox.width <= 0) { g_error ("Empty page (%d)? Couldn't find a nonwhite column.", page_num); } info->bbox.y = firstrow; info->bbox.height = lastrow - firstrow; info->num_hunks = hunkscount; info->hunks = hunks; g_free (white_rows); g_free (white_cols); return info; }
void zoom(const char *arg) { if (show.rendered < show.count - 1) { /* ensure rendering is done */ warn(); return; } XDefineCursor(dpy,win,XCreateFontCursor(dpy,130)); XEvent ev; int x1,y1,x2=-1,y2; while ( !XNextEvent(dpy,&ev) && ev.type!=ButtonPress && ev.type!=KeyPress ); if (ev.type == KeyPress) { XPutBackEvent(dpy,&ev); XDefineCursor(dpy,win,invisible_cursor); return; } XGrabPointer(dpy,ev.xbutton.window,True, PointerMotionMask | ButtonReleaseMask, GrabModeAsync, GrabModeAsync,None,None,CurrentTime); x1 = ev.xbutton.x; y1 = ev.xbutton.y; while (!XNextEvent(dpy,&ev) && ev.type != ButtonRelease && ev.type!=KeyPress) { XCopyArea(dpy,show.slide[show.num],win,gc,0,0, aspx*sw,aspy*sh,(sw-aspx*sw)/2,(sh-aspy*sh)/2); XDrawRectangle(dpy,win,hgc,x1,y1,ev.xbutton.x-x1,ev.xbutton.y-y1); XSync(dpy,True); } if (ev.type == KeyPress) { XPutBackEvent(dpy,&ev); XDefineCursor(dpy,win,invisible_cursor); return; } x2 = ev.xbutton.x; y2 = ev.xbutton.y; mute("black"); white_muted = True; Pixmap region = XCreatePixmap(dpy,root,sw,sh,DefaultDepth(dpy,scr)); XFillRectangle(dpy,region,wgc,0,0,sw,sh); PopplerPage *page = poppler_document_get_page(pdf,show.num); cairo_surface_t *target = cairo_xlib_surface_create( dpy, region, DefaultVisual(dpy,scr), sw, sh); cairo_t *cairo = cairo_create(target); double xscale = show.scale * sw/ (x2-x1); double yscale = show.scale * sh/ (y2-y1); if (arg) { if (xscale > yscale) xscale = yscale; else yscale = xscale; } double xoff = ((sw-aspx*sw)/2 - x1)/show.scale*xscale; double yoff = ((sh-aspy*sh)/2 - y1)/show.scale*yscale; cairo_translate(cairo,xoff,yoff); cairo_scale(cairo,xscale,yscale); poppler_page_render(page,cairo); cairo_surface_destroy(target); cairo_destroy(cairo); XCopyArea(dpy,region,win,gc,0,0,sw,sh,0,0); XFreePixmap(dpy,region); XDefineCursor(dpy,win,invisible_cursor); XFlush(dpy); }
static gboolean render_page(GtkWidget *widget) { /* GtkDrawingAreaにPDFを描画 */ static cairo_surface_t *surface = NULL; cairo_t *cr; double width,height; PopplerPage *page; GdkWindow *window; if (doc == NULL) { return FALSE; } if (surface != NULL) { cairo_surface_destroy(surface); surface = NULL; } /* PDFの1ページ目を表示する。第2引数を変えればそのページを表示 */ page = poppler_document_get_page(doc,0); /* PDFページのサイズを取得 */ poppler_page_get_size(page, &width, &height); /* DrawingAreaをPDFページのサイズに設定=等倍 */ gtk_widget_set_size_request(widget,(int)width,(int)height); /* cairo surface作成 */ surface = cairo_image_surface_create(CAIRO_FORMAT_ARGB32, width,height); cr = cairo_create(surface); cairo_save(cr); /* スケールを等倍 */ cairo_scale(cr,1.0,1.0); /* surfaceにページを描画 */ 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); cairo_destroy (cr); /* DrawingAreaのGdkWindowを取得 */ window = gtk_widget_get_window(widget); if (window != NULL) { /* GdkWindowにsurfaceを設定 */ cr = gdk_cairo_create(window); cairo_set_source_surface(cr,surface,0,0); cairo_paint(cr); cairo_destroy(cr); } g_object_unref(page); }
static GString * extract_content_text (PopplerDocument *document, gsize n_bytes) { gint n_pages, i = 0; GString *string; GTimer *timer; gsize remaining_bytes = n_bytes; n_pages = poppler_document_get_n_pages (document); string = g_string_new (""); timer = g_timer_new (); while (i < n_pages && remaining_bytes > 0) { PopplerPage *page; gsize written_bytes = 0; gchar *text; page = poppler_document_get_page (document, i); i++; text = poppler_page_get_text (page); if (!text) { g_object_unref (page); continue; } if (tracker_text_validate_utf8 (text, MIN (strlen (text), remaining_bytes), &string, &written_bytes)) { g_string_append_c (string, ' '); } remaining_bytes -= written_bytes; g_debug ("Child: Extracted %" G_GSIZE_FORMAT " bytes from page %d, " "%" G_GSIZE_FORMAT " bytes remaining", written_bytes, i, remaining_bytes); g_free (text); g_object_unref (page); } g_debug ("Child: Content extraction finished: %d/%d pages indexed in %2.2f seconds, " "%" G_GSIZE_FORMAT " bytes extracted", i, n_pages, g_timer_elapsed (timer, NULL), (n_bytes - remaining_bytes)); g_timer_destroy (timer); return string; }
static void pgd_page_get_info (GtkWidget *button, PgdPageDemo *demo) { PopplerPage *page; page = poppler_document_get_page (demo->doc, demo->page); pgd_page_set_page (demo, page); g_object_unref (page); }
int main(int argc, char *argv[]) { PopplerDocument *document; PopplerPage *page; GError *error; const char *pdf_file; gchar *absolute, *dir, *uri; int page_num, num_pages; char *tmpChar; if (argc < 2 && argc > 3) { printf ("Usage: pdftomapping input_file.pdf [page]\n"); return 0; } pdf_file = argv[1]; g_type_init (); error = NULL; if (g_path_is_absolute(pdf_file)) { absolute = g_strdup (pdf_file); } else { gchar *dir = g_get_current_dir (); absolute = g_build_filename (dir, pdf_file, (gchar *) 0); free (dir); } uri = g_filename_to_uri (absolute, NULL, &error); free (absolute); if (uri == NULL) { printf("%s\n", error->message); return 1; } document = poppler_document_new_from_file (uri, NULL, &error); if (document == NULL) { printf("%s\n", error->message); return 1; } num_pages = poppler_document_get_n_pages (document); int start = 1, end = num_pages; if (argc >= 3) { start = end = atoi(argv[2]); } for (page_num = start; page_num <= end ;page_num++) { page = poppler_document_get_page (document, page_num - 1); if (page == NULL) { printf("poppler fail: page not found\n"); return 1; } write_mapping(page_num, page); } return 0; }
void * xv_doc_get_paint (struct xv_doc_t *doc, unsigned int n, double scale, PgdRenderMode mode, double * width, double *height) { struct xv_page_t *page; if (n >= doc->n_pages) { return NULL; } if (!doc->pages[n]) { doc->pages[n] = g_malloc0(sizeof(struct xv_page_t)); doc->pages[n]->page = poppler_document_get_page(doc->doc, n); if (!doc->pages[n]->page) { printf("Could not open page %d of document\n", n); return NULL; } poppler_page_get_size(doc->pages[n]->page, &doc->pages[n]->width, &doc->pages[n]->height); } page = doc->pages[n]; /* auto scale */ if (scale == 0) { double a, b; a = *width / page->width; b = *height / page->height; scale = a < b? a : b; } /* A4 paper size */ if (scale == -1) { GdkScreen * def = gdk_screen_get_default(); gdouble res; g_assert (def != NULL); res = gdk_screen_get_resolution (def); scale = 8.3 * res / page->width; } /* rendering */ if (mode == PGD_RENDER_CAIRO) { xv_doc_get_surface (page, mode, scale); } else { xv_doc_get_gdkbuf (page, mode, scale); } *width = doc->pages[n]->width * scale; *height = doc->pages[n]->height * scale; return page->pixbuf; }
static void redraw_handler(struct widget *widget, void *data) { struct view *view = data; struct rectangle allocation; cairo_surface_t *surface; cairo_t *cr; PopplerPage *page; double width, height, doc_aspect, window_aspect, scale; widget_get_allocation(view->widget, &allocation); surface = window_get_surface(view->window); cr = cairo_create(surface); cairo_rectangle(cr, allocation.x, allocation.y, allocation.width, allocation.height); cairo_clip(cr); cairo_set_source_rgba(cr, 0, 0, 0, 0.8); cairo_set_operator(cr, CAIRO_OPERATOR_SOURCE); cairo_paint(cr); if(!view->document) { cairo_destroy(cr); cairo_surface_destroy(surface); window_flush(view->window); return; } page = poppler_document_get_page(view->document, view->page); poppler_page_get_size(page, &width, &height); doc_aspect = width / height; window_aspect = (double) allocation.width / allocation.height; if (doc_aspect < window_aspect) scale = allocation.height / height; else scale = allocation.width / width; cairo_translate(cr, allocation.x, allocation.y); cairo_scale(cr, scale, scale); cairo_translate(cr, (allocation.width - width * scale) / 2 / scale, (allocation.height - height * scale) / 2 / scale); cairo_rectangle(cr, 0, 0, width, height); cairo_set_operator(cr, CAIRO_OPERATOR_OVER); cairo_set_source_rgb(cr, 1, 1, 1); cairo_fill(cr); poppler_page_render(page, cr); cairo_destroy(cr); cairo_surface_destroy(surface); g_object_unref(G_OBJECT(page)); }
int main(int argc, char const *argv[]) { char *path; PopplerDocument *doc; GError *err; gchar *gbuf; char *buf; page_t page_meta; int file_length, n; g_type_init(); if (argc != 2) { return 1; } err = NULL; buf = open_pdf_file(argv[1], &file_length); sandboxify(); doc = poppler_document_new_from_data(buf, file_length, NULL, &err); if (err != NULL) { fprintf(stderr, "Unable to open file: %s\n", err->message); return 2; } n = poppler_document_get_n_pages(doc); for (int i = 0; i < n; i++) { PopplerPage *page = poppler_document_get_page(doc, i); page_meta.pagenum = i; page_meta.text = poppler_page_get_text(page); page_meta.svg_len = 0; page_meta.svg = malloc(SVG_BUFLEN); if (!page_meta.svg) ERROR("Cannot allocate svg buffer, not enought memory?"); page_meta.free_space = SVG_BUFLEN; render_page(&page_meta, page); if (page_meta.text) free(page_meta.text); g_object_unref(page); } if (munmap(buf, file_length) == -1) PERROR("munmap()"); return 0; }
static int executeJump(void) { /* * 0 = No jump pending, nothing done. * 1 = Jump succeeded. * 2 = Jump was pending, but target page invalid. */ int retval = 0; /* Jump? */ if (target_page >= 0) { int label = 0; int runs = 0; int page_number = target_page-1; while (runs < doc_n_pages && page_number >= 0 && page_number < doc_n_pages) { PopplerPage *page = poppler_document_get_page(doc, page_number); label = atoi(poppler_page_get_label(page)); if (label == target_page) break; if (label < target_page) page_number++; else if (label > target_page) page_number--; runs++; g_object_unref(G_OBJECT(page)); } target_page = page_number; /* Restrict to valid range. */ if (target_page >= 0 && target_page < doc_n_pages) { doc_page = target_page; doc_page_beamer = target_page; setStatusText_strdup("Ready."); retval = 1; } else { setStatusText_strdup("Invalid page."); retval = 2; } /* Reset value to: "no jump pending". */ target_page = -1; } return retval; }
void DocumentView::drawTexImage(cairo_t* cr, TexImage* texImage) { XOJ_CHECK_TYPE(DocumentView); cairo_matrix_t defaultMatrix = { 0 }; cairo_get_matrix(cr, &defaultMatrix); PopplerDocument* pdf = texImage->getPdf(); cairo_surface_t* img = texImage->getImage(); if (pdf != nullptr) { if (poppler_document_get_n_pages(pdf) < 1) { g_warning("Got latex PDf without pages!: %s", texImage->getText().c_str()); return; } PopplerPage* page = poppler_document_get_page(pdf, 0); double pageWidth = 0; double pageHeight = 0; poppler_page_get_size(page, &pageWidth, &pageHeight); double xFactor = texImage->getElementWidth() / pageWidth; double yFactor = texImage->getElementHeight() / pageHeight; cairo_translate(cr, texImage->getX(), texImage->getY()); cairo_scale(cr, xFactor, yFactor); poppler_page_render(page, cr); } else if (img != nullptr) { int width = cairo_image_surface_get_width(img); int height = cairo_image_surface_get_height(img); cairo_set_operator(cr, CAIRO_OPERATOR_OVER); double xFactor = texImage->getElementWidth() / width; double yFactor = texImage->getElementHeight() / height; cairo_scale(cr, xFactor, yFactor); cairo_set_source_surface(cr, img, texImage->getX() / xFactor, texImage->getY() / yFactor); cairo_paint(cr); } cairo_set_matrix(cr, &defaultMatrix); }
// 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__); }
static void render_pdf_page( PopplerDocument* doc, int n_page, cairo_surface_t* surface, int width, int height ) { PopplerPage* page = poppler_document_get_page(doc, n_page); cairo_t* cr = cairo_create(surface); cairo_rectangle(cr, 0, 0, width, height); cairo_set_source_rgb(cr, 1, 1, 1); cairo_fill(cr); cairo_paint(cr); poppler_page_render(page, cr); g_object_unref(page); cairo_destroy(cr); }
static void pgd_annots_get_annots (PgdAnnotsDemo *demo) { GList *mapping, *l; gint n_fields; GTimer *timer; gtk_list_store_clear (demo->model); pgd_annot_view_set_annot (demo, NULL); if (demo->page) { g_object_unref (demo->page); demo->page = NULL; } demo->page = poppler_document_get_page (demo->doc, demo->num_page); if (!demo->page) return; timer = g_timer_new (); mapping = poppler_page_get_annot_mapping (demo->page); g_timer_stop (timer); n_fields = g_list_length (mapping); if (n_fields > 0) { gchar *str; str = g_strdup_printf ("<i>%d annotations found in %.4f seconds</i>", n_fields, g_timer_elapsed (timer, NULL)); gtk_label_set_markup (GTK_LABEL (demo->timer_label), str); g_free (str); } else { gtk_label_set_markup (GTK_LABEL (demo->timer_label), "<i>No annotations found</i>"); } g_timer_destroy (timer); for (l = mapping; l; l = g_list_next (l)) { PopplerAnnotMapping *amapping; amapping = (PopplerAnnotMapping *) l->data; pgd_annots_add_annot_to_model (demo, amapping->annot, amapping->area, FALSE); } poppler_page_free_annot_mapping (mapping); }
static GdkPixbuf * get_thumbnail (PopplerDocument *doc, gint page_num, gint preferred_size) { PopplerPage *page; GdkPixbuf *pixbuf; page = poppler_document_get_page (doc, page_num); if (! page) return NULL; /* XXX: Remove conditional when we depend on poppler 0.8.0, but also * add configure check to make sure POPPLER_WITH_GDK is enabled! */ #ifdef POPPLER_WITH_GDK pixbuf = poppler_page_get_thumbnail_pixbuf (page); #else pixbuf = poppler_page_get_thumbnail (page); #endif if (! pixbuf) { gdouble width; gdouble height; gdouble scale; poppler_page_get_size (page, &width, &height); scale = (gdouble) preferred_size / MAX (width, height); width *= scale; height *= scale; pixbuf = gdk_pixbuf_new (GDK_COLORSPACE_RGB, FALSE, 8, width, height); poppler_page_render_to_pixbuf (page, 0, 0, width, height, scale, 0, pixbuf); } g_object_unref (page); return pixbuf; }
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; } }
static void pgd_selections_render (GtkButton *button, PgdSelectionsDemo *demo) { gdouble page_width, page_height; cairo_t *cr; if (!demo->page) demo->page = poppler_document_get_page (demo->doc, demo->page_index); if (!demo->page) return; pgd_selections_clear_selections (demo); pgd_selections_update_selection_region (demo); gtk_widget_set_sensitive (demo->copy_button, FALSE); if (demo->surface) cairo_surface_destroy (demo->surface); demo->surface = NULL; poppler_page_get_size (demo->page, &page_width, &page_height); page_width *= demo->scale; page_height *= demo->scale; demo->surface = cairo_image_surface_create (CAIRO_FORMAT_ARGB32, page_width, page_height); cr = cairo_create (demo->surface); cairo_save (cr); if (demo->scale != 1.0) cairo_scale (cr, demo->scale, demo->scale); poppler_page_render (demo->page, cr); cairo_restore (cr); cairo_set_operator (cr, CAIRO_OPERATOR_DEST_OVER); cairo_set_source_rgb (cr, 1., 1., 1.); cairo_paint (cr); cairo_destroy (cr); gtk_widget_set_size_request (demo->darea, page_width, page_height); gtk_widget_queue_draw (demo->darea); }
static gboolean pgd_text_view_query_tooltip (GtkTextView *textview, gint x, gint y, gboolean keyboard_tip, GtkTooltip *tooltip, PgdTextDemo *demo) { GtkTreeModel *model; GtkTreeIter iter; GtkTreeSelection *selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (demo->treeview)); if (gtk_tree_selection_get_selected (selection, &model, &iter)) { PopplerPage *page; gchar *x1, *y1, *x2, *y2; PopplerRectangle rect; gchar *text; gtk_tree_model_get (model, &iter, TEXT_X1_COLUMN, &x1, TEXT_Y1_COLUMN, &y1, TEXT_X2_COLUMN, &x2, TEXT_Y2_COLUMN, &y2, -1); rect.x1 = g_strtod (x1, NULL); rect.y1 = g_strtod (y1, NULL); rect.x2 = g_strtod (x2, NULL); rect.y2 = g_strtod (y2, NULL); g_free (x1); g_free (y1); g_free (x2); g_free (y2); page = poppler_document_get_page (demo->doc, demo->page); text = poppler_page_get_selected_text (page, POPPLER_SELECTION_GLYPH, &rect); gtk_tooltip_set_text (tooltip, text); g_free (text); g_object_unref (page); return TRUE; } else { return FALSE; } }
static int vips_foreign_load_pdf_get_page( VipsForeignLoadPdf *pdf, int page_no ) { if( pdf->current_page != page_no ) { VipsObjectClass *class = VIPS_OBJECT_GET_CLASS( pdf ); VIPS_UNREF( pdf->page ); pdf->current_page = -1; #ifdef DEBUG printf( "vips_foreign_load_pdf_get_page: %d\n", page_no ); #endif /*DEBUG*/ if( !(pdf->page = poppler_document_get_page( pdf->doc, page_no )) ) { vips_error( class->nickname, _( "unable to load page %d" ), page_no ); return( -1 ); }
static void pgd_text_get_text (GtkWidget *button, PgdTextDemo *demo) { PopplerPage *page; PopplerRectangle rect; gdouble width, height; gchar *text; GTimer *timer; page = poppler_document_get_page (demo->doc, demo->page); if (!page) return; poppler_page_get_size (page, &width, &height); rect.x1 = rect.y1 = 0; rect.x2 = width; rect.y2 = height; timer = g_timer_new (); text = poppler_page_get_text (page, POPPLER_SELECTION_GLYPH, &rect); g_timer_stop (timer); if (text) { gchar *str; str = g_strdup_printf ("<i>got text in %.4f seconds</i>", g_timer_elapsed (timer, NULL)); gtk_label_set_markup (GTK_LABEL (demo->timer_label), str); g_free (str); } else { gtk_label_set_markup (GTK_LABEL (demo->timer_label), "<i>No text found</i>"); } g_timer_destroy (timer); g_object_unref (page); if (text) { gtk_text_buffer_set_text (demo->buffer, text, strlen (text)); g_free (text); } }
static VALUE rg_each(VALUE self) { PopplerDocument *document; int i, n_pages; document = RVAL2DOC(self); n_pages = poppler_document_get_n_pages(document); for (i = 0; i < n_pages; i++) { PopplerPage *page; VALUE rb_page; page = poppler_document_get_page(document, i); rb_page = GOBJ2RVAL(page); if (page) g_object_unref(page); rb_yield(rb_page); } return self; }
cairo_surface_t* get_pdf_thumbnail_cairo_surface(char* filename, int width, int height) { PopplerDocument* doc; GError* err = NULL; g_print("Thumbnail %s\n", filename); gchar* uri = g_strconcat("file:", filename, NULL); doc = poppler_document_new_from_file(uri, NULL, &err); if (NULL != err) { g_print(err->message); return NULL; } PopplerPage* page = poppler_document_get_page(doc, 0); cairo_surface_t* result = poppler_page_get_thumbnail(page); if (NULL == result) { result = cairo_image_surface_create(CAIRO_FORMAT_RGB24, width, height); render_pdf_page(doc, 0, result, width, height); } g_object_unref(doc); g_object_unref(page); return result; }
/* operations for doc */ struct xv_doc_t * xv_doc_new(const char * file) { GError *err = NULL; struct xv_doc_t *xv_doc; xv_doc = g_malloc0(sizeof(struct xv_doc_t)); xv_doc->doc = poppler_document_new_from_file(file, NULL, &err); if (!xv_doc->doc) { printf("%s\n", err->message); g_error_free(err); g_free(xv_doc); return NULL; } xv_doc->n_pages = poppler_document_get_n_pages(xv_doc->doc); /* initialize the pages */ xv_doc->pages = g_malloc0(xv_doc->n_pages * sizeof(struct xv_page_t *)); /* initial the first page */ xv_doc->pages[0] = g_malloc0(sizeof(struct xv_page_t)); xv_doc->pages[0]-> page = poppler_document_get_page(xv_doc->doc, 0); if (!xv_doc->pages[0]->page) { printf("Could not open page %d of document\n", 0); g_object_unref(xv_doc->doc); g_free(xv_doc->pages[0]); g_free(xv_doc->pages); g_free(xv_doc); return NULL; } poppler_page_get_size(xv_doc->pages[0]->page, &xv_doc->pages[0]->width, &xv_doc->pages[0]->height); return xv_doc; }
static void pgd_images_selection_changed (GtkTreeSelection *treeselection, PgdImagesDemo *demo) { GtkTreeModel *model; GtkTreeIter iter; if (gtk_tree_selection_get_selected (treeselection, &model, &iter)) { PopplerPage *page; gint image_id; gtk_tree_model_get (model, &iter, IMAGES_ID_COLUMN, &image_id, -1); page = poppler_document_get_page (demo->doc, demo->page); #if defined (HAVE_CAIRO) pgd_image_view_set_image (demo->image_view, poppler_page_get_image (page, image_id)); #endif g_object_unref (page); } }