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 <pdf-document.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 100
34 evince_thumbnail_pngenc_get (const char *uri, const char *thumbnail)
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), 0, THUMBNAIL_SIZE);
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[])
103 g_print ("%s: thumbnailer for Nautilus\n", argv[0]);
104 g_print ("usage: %s <input-filename> <output-filename>\n", argv[0]);
108 res = gnome_vfs_init ();
110 uri = gnome_vfs_make_uri_from_shell_arg (argv[1]);
112 if (evince_thumbnail_pngenc_get (uri, argv[2])) {