Thread: La Jornada
View Single Post
Old 12-30-2009, 05:49 PM   #8
kovidgoyal
creator of calibre
kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.
 
kovidgoyal's Avatar
 
Posts: 45,426
Karma: 27757236
Join Date: Oct 2006
Location: Mumbai, India
Device: Various
Using imagemagick to render PDf is not very portable as IIRC it requires ghostscript. Here's a patch to feeds/news.py taht will automatically handle a pdf cover, test it and let me know

Code:
=== modified file 'src/calibre/web/feeds/news.py'
--- src/calibre/web/feeds/news.py       2009-12-29 16:04:28 +0000
+++ src/calibre/web/feeds/news.py       2009-12-30 22:47:18 +0000
@@ -823,6 +823,14 @@
             cpath = os.path.join(self.output_dir, 'cover.'+ext)
             with nested(open(cpath, 'wb'), closing(self.browser.open(cu))) as (cfile, r):
                 cfile.write(r.read())
+            if ext.lower() == 'pdf':
+                from calibre.ebook.metadata.pdf import get_metadata
+                stream = open(cpath, 'rb')
+                mi = get_metadata(stream)
+                cpath = None
+                if mi.cover_data and mi.cover_data[1]:
+                    cpath = os.path.join(self.output_dir, 'cover.png')
+                    open(cpath, 'wb').write(mi.cover_data[1])
             self.cover_path = cpath
kovidgoyal is offline   Reply With Quote