libvips / pyvips

python binding for libvips using cffi

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Thumbnail creation taking too long

anirudhagarwal1 opened this issue · comments

I want to convert pdf to png and somehow for a few PDF files, the conversion process takes a very long time. The page size is A4 only.

I am attaching a sample PDF file.
temp-6.pdf

# Extract each page as an image
image = pyvips.Image.new_from_file(pdf_file, dpi=300, page=i)

# Save the image
image.pngsave(f"page_{i+1}.{format}")

The pngsave function takes about 50 seconds on my Macbook Pro. I have tried to save jpeg as well, which takes almost the same time.

What could be the issue? Any inputs would be highly appreciated.

Hi @anirudhagarwal1,

Wow, that is slow. I tried your file on my PC:

$ time vips copy very-slow.pdf[dpi=300] x.jpg 

real	0m39.694s
user	0m37.869s
sys	0m1.938s

And it's almost as bad.

I tried firefox preview and it's also very slow.

By default, libvips uses poppler for PDF rendering and I think your file probably just uses some feature with a slow implementation in poppler. libvips can also use PDFium as a PDF backend, perhaps that's quicker? I'll try it.

I recompiled my libvips against PDFium 5947 and I now see:

$ time vips copy very-slow.pdf[dpi=300] x.jpg 

real	0m2.216s
user	0m1.324s
sys	0m1.014s

So I think I'd look into installing pdfium on your macbook.