How to Convert WebP to PDF with Python? Any Efficient Solutions?

20 Replies, 1454 Views

Hey! I’ve actually done this before using PIL and img2pdf. It’s pretty straightforward once you get the hang of it. Here’s a quick snippet:

```python
from PIL import Image
import img2pdf

with open("output.pdf", "wb") as f:
img = Image.open("image.webp").convert("RGB")
f.write(img2pdf.convert(img.filename))
```

This should work for single images. For batch conversion, just loop through your webp files. Hope this helps!

Messages In This Thread



Users browsing this thread: 1 Guest(s)