'How to add images to a Pdf file from static files using borb library and Django
I want to add an image to a pdf file, the images are in the static directory:
'static/images/logo.png'
Settings file:
STATIC_URL = '/static/'
Part of the Code:
from borb.pdf.canvas.layout.image.image import Image
page_layout.add(
Image(
"/static/images/logo.png",
width=Decimal(128),
height=Decimal(128),
))
Error Code:
MissingSchema: Invalid URL '/static/images/Logo.png': No schema supplied. Perhaps you meant http:///static/images/Logo.png?
I do not want to show it in a front end template, instead is a backend function to generate pdfs.
Do i have to provide/generate any kind of url link to the Image function?? how to do it?
Thanks !
Solution 1:[1]
Disclaimer: I am Joris Schellekens, author of aforementioned library borb.
The constructor of Image either accepts:
- a
strif you intend to grab the image from a URL - a
Pathif you intend to use a local image on your filesystem
You specified a str so borb is under the impression you want to use a file that is present on your filesystem.
It then tries to assert whether that file exists. Which is not the case. Hence the error.
The solution would be to either provide a Path or the fully resolved file-path as a str.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Joris Schellekens |
