This commit is contained in:
Kovid Goyal 2012-12-29 11:02:38 +05:30
parent 7012bb1af2
commit 27a4657b2c
3 changed files with 12 additions and 4 deletions

View File

@ -251,9 +251,11 @@ class PdfEngine(QPaintEngine):
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 @@ class PdfEngine(QPaintEngine):
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 @@ if __name__ == '__main__':
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()

View File

@ -47,7 +47,7 @@ class Links(object):
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 @@ class Links(object):
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')})

View File

@ -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 @@ class PDFStream(object):
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