| Server IP : 202.61.199.114 / Your IP : 216.73.217.139 Web Server : nginx/1.22.1 System : Linux de.arni-solutions.de 6.1.0-49-amd64 #1 SMP PREEMPT_DYNAMIC Debian 6.1.174-1 (2026-05-26) x86_64 User : web20 ( 1018) PHP Version : 8.4.23 Disable Function : NONE MySQL : OFF | cURL : ON | WGET : ON | Perl : ON | Python : OFF | Sudo : ON | Pkexec : ON Directory : /tmp/calpy/weasyprint/pdf/ |
Upload File : |
"""PDF generation with debug information."""
import pydyf
from ..matrix import Matrix
def debug(pdf, metadata, document, page_streams, attachments, compress):
"""Set debug PDF metadata."""
# Add links on ids.
pages = zip(pdf.pages['Kids'][::3], document.pages, page_streams)
for pdf_page_number, document_page, stream in pages:
if not document_page.anchors:
continue
page = pdf.objects[pdf_page_number]
if 'Annots' not in page:
page['Annots'] = pydyf.Array()
for id, (x1, y1, x2, y2) in document_page.anchors.items():
# TODO: handle zoom correctly.
matrix = Matrix(0.75, 0, 0, 0.75) @ stream.ctm
x1, y1 = matrix.transform_point(x1, y1)
x2, y2 = matrix.transform_point(x2, y2)
annotation = pydyf.Dictionary({
'Type': '/Annot',
'Subtype': '/Link',
'Rect': pydyf.Array([x1, y1, x2, y2]),
'BS': pydyf.Dictionary({'W': 0}),
'P': page.reference,
'T': pydyf.String(id), # id added as metadata
})
# The next line makes all of this relevent to use
# with PDFjs
annotation['Dest'] = pydyf.String(id)
pdf.add_object(annotation)
page['Annots'].append(annotation.reference)
VARIANTS = {'debug': (debug, {})}