How can I load a PDF file from the file picker and display it as an image in a canvas?
I want to be able to draw shapes to highlight areas of the (image of the?) PDF.
thanks,
chris
How can I load a PDF file from the file picker and display it as an image in a canvas?
I want to be able to draw shapes to highlight areas of the (image of the?) PDF.
thanks,
chris
It looks like Anvil has pdf2image
available as a server module (link).
You can pass the PDF object (or from file) and then send that to your image’s source.
OK, got the server module to generate a jpeg from the pdf using pdf2image. Now how do I send that back to the browser to stick in the canvas?
I’ve been playing around with the anvil.media module, but I can’t seem to find the happy path back…
thanks,
chris
Have you tried sending the resulting object from pdf2image
to the client?
@anvil.server.callable
def convert_pdf(pdf):
images = convert_from_path('/home/belval/example.pdf')
return images
Client:
images = anvil.server.call('convert_pdf', pdf_file)
One issue may be that a multipage PDF will result in multiple images. Otherwise you may need to convert the image object to an Anvil Media object. Check out the docs for various ways to convert media objects.