[reportlab-users] Adding annotations to a pdf
pianoslum
pianoslum at mailbox.org
Mon Dec 10 17:29:55 EST 2018
Hi Robin,
thanks for your quick answer.
Actually I modified a SO example (), here's my code:
from PyPDF2 import PdfFileWriter, PdfFileReader
import io
from reportlab.pdfgen import canvas
from reportlab.lib.pagesizes import letter
packet = io.BytesIO()
# create a new PDF with Reportlab
can = canvas.Canvas(packet, pagesize=letter)
can.drawString(10, 100, "Hello world")
#can.highlightAnnotation("TEST", Rect=[1, 1, 1, 1], relative=1)
can.save()
#move to the beginning of the StringIO buffer
packet.seek(0)
new_pdf = PdfFileReader(packet)
# read your existing PDF
existing_pdf = PdfFileReader(open("original.pdf", "rb"))
output = PdfFileWriter()
# add the "watermark" (which is the new pdf) on the existing page
page = existing_pdf.getPage(0)
page.mergePage(new_pdf.getPage(0))
output.addPage(page)
# finally, write "output" to a real file
outputStream = open("destination.pdf", "wb")
output.write(outputStream)
outputStream.close()
The drawString-call works as intended, but the highlightAnnotation
results in the crash.
I tried your example (stripped it of some test code) and it results in
the same crash. Does the example above work for you?
I'm on ArchLinux x64, python 3.7.1, evince 3.30.2, reportlab 3.5.12
Sorry, if I miss something :-)
Cheers!
Am 10.12.18 um 09:36 schrieb Robin Becker:
> Hi pianoslum,
>
> I suspect there may be something amiss with your code as we have a
> test of highlightAnnotation in the reportlab source code tests see
>
> https://bitbucket.org/rptlab/reportlab/src/default/tests/test_pdfgen_links.py#
>
>
>
> I have just run this with Python2.7 and tested that the annotations
> work using both acrobat reader and evince (running in ubuntu 16.04).
>
>
> Perhaps you could post the actual code that your are testing with (or
> a cut down example) and some details of the envirnment eg python
> version, os etc etc.
>
More information about the reportlab-users
mailing list