Glom already had an Image field type, letting you store pictures in the database and view them. It used GtkImage.
It can now store and preview PDFs, or anything else supported by Evince, via its evince-view library.
The contents can also now be opened in the external application via the context menu, and an Open With menu item even offers a choice of suitable applications via GtkAppChooserDialog. That’s why I haven’t bothered to add page navigation or zooming for PDFs in Glom itself.
It can even store arbitrary file contents, though it will just show a standard icon in that case. As a hack, it saves the contents as a temporary file in order to use GFileInfo to get the standard file icon. I haven’t managed to get the thumbnail via the G_FILE_ATTRIBUTE_THUMBNAIL_PATH attribute, but it’s probably not reasonable to expect to get that thumbnail for a completely new file.
In fact, I use the same temporary file hack to get the PDF data into the Evince EvView. I must figure out how to make EvView render from data in memory instead of a filepath.
It would be nice to show a simple video player for video files, but I haven’t found a suitable gstreamer-based library for that yet, though I guess I could copy/paste some code. And anyway, it doesn’t like huge files right now.
I use glib’s mime-type sniffing function to guess the mime-type, to decide how to display or open the document. This works surprisingly well but we really need to store the original mime type, and probably the file name, in extra database fields.
Update: I’ve given up on getting a thumbnail, so I’m just using g_content_type_get_icon(), which avoids the need to save a temporary file to disk. And for EvView, I’ll try to add API to allow loading from memory.
One thought on “Glom: Storing PDFs”
Comments are closed.