mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
Fix #1028 (Error converting PDF files in Calibre 0.4.84)
This commit is contained in:
parent
26a155d436
commit
2fce6a3792
10
setup.py
10
setup.py
@ -70,6 +70,15 @@ if __name__ == '__main__':
|
||||
def initialize_options(self): pass
|
||||
def finalize_options(self): pass
|
||||
|
||||
class sdist(Command):
|
||||
|
||||
description = "create a source distribution using bzr"
|
||||
|
||||
def run(self):
|
||||
name = 'dist/calibre-%s.tar.gz'%VERSION
|
||||
subprocess.check_call(('bzr export '+name).split())
|
||||
self.distribution.dist_files.append(('sdist', '', name))
|
||||
|
||||
class pot(Command):
|
||||
description = '''Create the .pot template for all translatable strings'''
|
||||
|
||||
@ -414,6 +423,7 @@ if __name__ == '__main__':
|
||||
'translations' : translations,
|
||||
'gui' : gui,
|
||||
'clean' : clean,
|
||||
'sdist' : sdist,
|
||||
},
|
||||
)
|
||||
|
||||
|
21
src/calibre/ebooks/epub/from_comic.py
Normal file
21
src/calibre/ebooks/epub/from_comic.py
Normal file
@ -0,0 +1,21 @@
|
||||
from __future__ import with_statement
|
||||
__license__ = 'GPL v3'
|
||||
__copyright__ = '2008, Kovid Goyal kovid@kovidgoyal.net'
|
||||
__docformat__ = 'restructuredtext en'
|
||||
|
||||
'Convert a comic in CBR/CBZ format to epub'
|
||||
|
||||
import sys
|
||||
from functools import partial
|
||||
from calibre.ebooks.lrf.comic.convert_from import do_convert, option_parser, config, main as _main
|
||||
|
||||
convert = partial(do_convert, output_format='epub')
|
||||
main = partial(_main, output_format='epub')
|
||||
|
||||
if __name__ == '__main__':
|
||||
sys.exit(main())
|
||||
|
||||
if False:
|
||||
option_parser
|
||||
config
|
||||
|
@ -3,7 +3,7 @@ from calibre.ebooks.metadata.opf import OPFReader
|
||||
__license__ = 'GPL v3'
|
||||
__copyright__ = '2008, Kovid Goyal kovid@kovidgoyal.net'
|
||||
__docformat__ = 'restructuredtext en'
|
||||
import os, sys, re, shutil, cStringIO
|
||||
import os, sys, re, cStringIO
|
||||
|
||||
from lxml.etree import XPath
|
||||
try:
|
||||
@ -121,8 +121,8 @@ def convert(htmlfile, opts, notification=None):
|
||||
cpath = '/'.join(('resources', os.path.basename(mi.cover)))
|
||||
cover = '''\
|
||||
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
|
||||
<head><title>Cover Page</title></head>
|
||||
<body>
|
||||
<head><title>Cover Page</title><style type="text/css">@page {padding: 0pt; margin:0pt}</style></head>
|
||||
<body style="padding: 0pt; margin: 0pt;}">
|
||||
<div style="text-align:center">
|
||||
<img src="%s" alt="cover" />
|
||||
</div>
|
||||
|
@ -7,7 +7,7 @@ __docformat__ = 'restructuredtext en'
|
||||
Based on ideas from comiclrf created by FangornUK.
|
||||
'''
|
||||
|
||||
import os, sys, shutil, traceback
|
||||
import os, sys, shutil, traceback, textwrap
|
||||
from uuid import uuid4
|
||||
|
||||
from calibre import extract, terminal_controller, __appname__, __version__
|
||||
@ -16,6 +16,9 @@ from calibre.ptempfile import PersistentTemporaryDirectory
|
||||
from calibre.parallel import Server, ParallelJob
|
||||
from calibre.utils.terminfo import ProgressBar
|
||||
from calibre.ebooks.lrf.pylrs.pylrs import Book, BookSetting, ImageStream, ImageBlock
|
||||
from calibre.ebooks.metadata import MetaInformation
|
||||
from calibre.ebooks.metadata.opf import OPFCreator
|
||||
from calibre.ebooks.epub.from_html import config as html2epub_config, convert as html2epub
|
||||
try:
|
||||
from calibre.utils.PythonMagickWand import \
|
||||
NewMagickWand, NewPixelWand, \
|
||||
@ -315,9 +318,37 @@ def option_parser():
|
||||
return c.option_parser(usage=_('''\
|
||||
%prog [options] comic.cb[z|r]
|
||||
|
||||
Convert a comic in a CBZ or CBR file to an LRF ebook.
|
||||
Convert a comic in a CBZ or CBR file to an ebook.
|
||||
'''))
|
||||
|
||||
def create_epub(pages, profile, opts, thumbnail=None):
|
||||
wrappers = []
|
||||
WRAPPER = textwrap.dedent('''\
|
||||
<html>
|
||||
<head></head>
|
||||
<body>
|
||||
<div style="text-align:center">
|
||||
<img src="%s" alt="comic page #%d" />
|
||||
</div>
|
||||
</body>
|
||||
</html>
|
||||
''')
|
||||
dir = os.path.dirname(pages[0])
|
||||
for i, page in enumerate(pages):
|
||||
wrapper = WRAPPER%(os.path.basename(page), i+1)
|
||||
page = os.path.join(dir, 'page_%d.html'%(i+1))
|
||||
open(page, 'wb').write(wrapper)
|
||||
wrappers.append(page)
|
||||
|
||||
mi = MetaInformation(opts.title, [opts.author])
|
||||
opf = OPFCreator(dir, mi)
|
||||
opf.create_manifest([(w, None) for w in wrappers])
|
||||
opf.create_spine(wrappers)
|
||||
metadata = os.path.join(dir, 'metadata.opf')
|
||||
opf.render(open(metadata, 'wb'))
|
||||
opts = html2epub_config('margin_left=0\nmargin_right=0\nmargin_top=0\nmargin_bottom=0').parse()
|
||||
html2epub(metadata, opts)
|
||||
|
||||
def create_lrf(pages, profile, opts, thumbnail=None):
|
||||
width, height = PROFILES[profile]
|
||||
ps = {}
|
||||
@ -341,12 +372,13 @@ def create_lrf(pages, profile, opts, thumbnail=None):
|
||||
|
||||
book.renderLrf(open(opts.output, 'wb'))
|
||||
|
||||
def do_convert(path_to_file, opts, notification=lambda m, p: p):
|
||||
|
||||
def do_convert(path_to_file, opts, notification=lambda m, p: p, output_format='lrf'):
|
||||
source = path_to_file
|
||||
if not opts.title:
|
||||
opts.title = os.path.splitext(os.path.basename(source))[0]
|
||||
if not opts.output:
|
||||
opts.output = os.path.abspath(os.path.splitext(os.path.basename(source))[0]+'.lrf')
|
||||
opts.output = os.path.abspath(os.path.splitext(os.path.basename(source))[0]+'.'+output_format)
|
||||
|
||||
tdir = extract_comic(source)
|
||||
pages = find_pages(tdir, sort_on_mtime=opts.no_sort, verbose=opts.verbose)
|
||||
@ -362,12 +394,15 @@ def do_convert(path_to_file, opts, notification=lambda m, p: p):
|
||||
thumbnail = os.path.join(tdir2, 'thumbnail.png')
|
||||
if not os.access(thumbnail, os.R_OK):
|
||||
thumbnail = None
|
||||
create_lrf(pages, opts.profile, opts, thumbnail=thumbnail)
|
||||
if output_format == 'lrf':
|
||||
create_lrf(pages, opts.profile, opts, thumbnail=thumbnail)
|
||||
else:
|
||||
create_epub(pages, opts.profile, opts, thumbnail=thumbnail)
|
||||
shutil.rmtree(tdir)
|
||||
shutil.rmtree(tdir2)
|
||||
|
||||
|
||||
def main(args=sys.argv, notification=None):
|
||||
def main(args=sys.argv, notification=None, output_format='lrf'):
|
||||
parser = option_parser()
|
||||
opts, args = parser.parse_args(args)
|
||||
if len(args) < 2:
|
||||
@ -381,7 +416,7 @@ def main(args=sys.argv, notification=None):
|
||||
notification = pb.update
|
||||
|
||||
source = os.path.abspath(args[1])
|
||||
do_convert(source, opts, notification)
|
||||
do_convert(source, opts, notification, output_format=output_format)
|
||||
print _('Output written to'), opts.output
|
||||
return 0
|
||||
|
||||
|
@ -35,7 +35,7 @@ def generate_html(pathtopdf, tdir):
|
||||
index = os.path.join(tdir, 'index.html')
|
||||
# This is neccessary as pdftohtml doesn't always (linux) respect absolute paths
|
||||
pathtopdf = os.path.abspath(pathtopdf)
|
||||
cmd = (PDFTOHTML, '-enc', 'UTF-8', '-noframes', '-p', '-nomerge', '-nodrm', pathtopdf, os.path.basename(index))
|
||||
cmd = (PDFTOHTML, '-enc', 'UTF-8', '-noframes', '-p', '-nomerge', pathtopdf, os.path.basename(index))
|
||||
cwd = os.getcwd()
|
||||
|
||||
try:
|
||||
|
@ -235,10 +235,9 @@ def stage_three():
|
||||
print 'Uploading to PyPI...'
|
||||
check_call('rm -f dist/*')
|
||||
check_call('python setup.py register')
|
||||
check_call('python setup.py bdist_egg --exclude-source-files')
|
||||
build_src_tarball()
|
||||
check_call('python setup.py bdist_egg --exclude-source-files upload')
|
||||
check_call('python setup.py sdist upload')
|
||||
upload_src_tarball()
|
||||
check_call('python setup.py upload')
|
||||
check_call('''rm -rf dist/* build/*''')
|
||||
check_call('''ssh divok bzr update /var/www/calibre.kovidgoyal.net/calibre/''')
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user