I am using pdfmake to generate pdf's in node.js.
const imageBuffer = await imageToBase64('image path'); //image from azure blob storage
const pdfData = {
content: [
{
image: `data:image/jpeg;base64,${imageBuffer}`,
width: 100,
height: 100,
}
]
};
----rest of the pdf logic goes here----
Image is coming in default shape (rectangle) in the pdf. I know that there is no 'border-radius' property in pdfmake styles. But I need to stick with pdfmake. But I need to show the image in a round (circular) shape. Is there any way to convert the "imageBuffer" into circular one using any npm package or someother way?
Need someone's valuable help.
You can use the
canvasmodule to crop the image and thepdfmakemodule to create the PDF.AFAIK, the
pdfmakedoes not support rounded images out of the box. However, there are a few workarounds you can try to achieve this effect.Code:
The above code generates a PDF document using an image that has been cropped into a circle shape. It uses the
canvasmodule to crop the image and thepdfmakemodule to create the PDF.Output: