2 Copyright (C) 2005 Fernando Herrera <fherrera@onirica.com>
4 This program is free software; you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation; either version 2 of the License, or
7 (at your option) any later version.
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
14 You should have received a copy of the GNU General Public License
15 along with this program; if not, write to the Free Software
16 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
19 #include <ev-poppler.h>
21 #include <libgnomevfs/gnome-vfs-mime-utils.h>
22 #include <libgnomevfs/gnome-vfs-uri.h>
23 #include <libgnomevfs/gnome-vfs-utils.h>
24 #include <libgnomevfs/gnome-vfs-init.h>
26 #include <ev-document.h>
27 #include <ev-document-thumbnails.h>
31 #define THUMBNAIL_SIZE 128
34 evince_thumbnail_pngenc_get (const char *uri, const char *thumbnail, int size)
36 EvDocument *document = NULL;
41 mime_type = gnome_vfs_get_mime_type (uri);
42 if (mime_type == NULL)
45 if (!strcmp (mime_type, "application/pdf"))
46 document = g_object_new (PDF_TYPE_DOCUMENT, NULL);
50 if (!ev_document_load (document, uri, &error)) {
51 if (error->domain == EV_DOCUMENT_ERROR &&
52 error->code == EV_DOCUMENT_ERROR_ENCRYPTED) {
53 /* FIXME: Create a thumb for cryp docs */
59 pixbuf = ev_document_thumbnails_get_thumbnail
60 (EV_DOCUMENT_THUMBNAILS (document), 1, size, FALSE);
65 pdflogo = gdk_pixbuf_new_from_file (DATADIR"/pdf-icon.png", NULL);
66 if (pdflogo != NULL) {
67 int delta_height, delta_width;
69 delta_width = gdk_pixbuf_get_width (pixbuf) -
70 gdk_pixbuf_get_width (pdflogo);
71 delta_height = gdk_pixbuf_get_height (pixbuf) -
72 gdk_pixbuf_get_height (pdflogo);
74 gdk_pixbuf_composite (pdflogo, pixbuf,
75 delta_width, delta_height,
76 gdk_pixbuf_get_width (pdflogo),
77 gdk_pixbuf_get_height (pdflogo),
78 delta_width, delta_height,
80 GDK_INTERP_NEAREST, 100);
82 gdk_pixbuf_unref (pdflogo);
84 if (gdk_pixbuf_save (pixbuf, thumbnail, "png", NULL, NULL)) {
85 gdk_pixbuf_unref (pixbuf);
86 g_object_unref (document);
89 gdk_pixbuf_unref (pixbuf);
90 g_object_unref (document);
97 main (int argc, char *argv[])
100 char *input, *output;
104 if (argc <= 2 || argc > 5 || strcmp (argv[1], "-h") == 0 ||
105 strcmp (argv[1], "--help") == 0) {
106 g_print ("Usage: %s [-s <size>] <input> <output>\n", argv[0]);
110 res = gnome_vfs_init ();
112 if (!strcmp (argv[1], "-s")) {
115 size = g_strtod (argv[2], NULL);
119 size = THUMBNAIL_SIZE;
123 g_print ("Size cannot be smaller than 40 pixels\n");
127 uri = gnome_vfs_make_uri_from_shell_arg (input);
129 if (evince_thumbnail_pngenc_get (uri, output, size)) {