mirror of
git://github.com/kovidgoyal/calibre.git
synced 2026-05-09 11:14:02 +02:00
...
This commit is contained in:
parent
7012bb1af2
commit
27a4657b2c
3 changed files with 12 additions and 4 deletions
|
|
@ -251,9 +251,11 @@ def begin(self, device):
|
|||
try:
|
||||
self.pdf = PDFStream(self.file_object, (self.page_width,
|
||||
self.page_height), compress=self.compress,
|
||||
mark_links=self.mark_links)
|
||||
mark_links=self.mark_links,
|
||||
debug=self.debug)
|
||||
except:
|
||||
self.errors(traceback.format_exc())
|
||||
self.errors_occurred = True
|
||||
return False
|
||||
return True
|
||||
|
||||
|
|
@ -270,6 +272,7 @@ def end(self):
|
|||
self.pdf.end()
|
||||
except:
|
||||
self.errors(traceback.format_exc())
|
||||
self.errors_occurred = True
|
||||
return False
|
||||
finally:
|
||||
self.pdf = self.file_object = None
|
||||
|
|
@ -581,7 +584,7 @@ def set_metadata(self, *args, **kwargs):
|
|||
QBrush, QColor, QPoint, QPixmap
|
||||
app = QApplication([])
|
||||
p = QPainter()
|
||||
with open('/tmp/painter.pdf', 'wb') as f:
|
||||
with open('/t/painter.pdf', 'wb') as f:
|
||||
dev = PdfDevice(f, compress=False)
|
||||
p.begin(dev)
|
||||
dev.init_page()
|
||||
|
|
|
|||
|
|
@ -47,7 +47,7 @@ def add_links(self):
|
|||
for link in self.links:
|
||||
path, href, frag = link[0]
|
||||
page, rect = link[1:]
|
||||
combined_path = os.path.abspath(os.path.join(path, *href.split('/')))
|
||||
combined_path = os.path.abspath(os.path.join(os.path.dirname(path), *href.split('/')))
|
||||
is_local = not href or combined_path in self.anchors
|
||||
annot = Dictionary({
|
||||
'Type':Name('Annot'), 'Subtype':Name('Link'),
|
||||
|
|
@ -76,6 +76,9 @@ def add_links(self):
|
|||
if 'Annots' not in page:
|
||||
page['Annots'] = Array()
|
||||
page['Annots'].append(self.pdf.objects.add(annot))
|
||||
else:
|
||||
self.pdf.debug('Could not find destination for link: %s in file %s'%
|
||||
(href, path))
|
||||
|
||||
def add_outline(self, toc):
|
||||
parent = Dictionary({'Type':Name('Outlines')})
|
||||
|
|
|
|||
|
|
@ -281,7 +281,8 @@ class PDFStream(object):
|
|||
( True, True, 'evenodd') : 'B*',
|
||||
}
|
||||
|
||||
def __init__(self, stream, page_size, compress=False, mark_links=False):
|
||||
def __init__(self, stream, page_size, compress=False, mark_links=False,
|
||||
debug=print):
|
||||
self.stream = HashingStream(stream)
|
||||
self.compress = compress
|
||||
self.write_line(PDFVER)
|
||||
|
|
@ -298,6 +299,7 @@ def __init__(self, stream, page_size, compress=False, mark_links=False):
|
|||
self.stroke_opacities, self.fill_opacities = {}, {}
|
||||
self.font_manager = FontManager(self.objects, self.compress)
|
||||
self.image_cache = {}
|
||||
self.debug = debug
|
||||
self.links = Links(self, mark_links)
|
||||
|
||||
@property
|
||||
|
|
|
|||
Loading…
Reference in a new issue