bimg
bimg copied to clipboard
How to pass additional parameters to PDF loader
I'm developing a tool that convert pages in a PDF file to JPEG images. I need a way to specify which page to load from the PDF using this library, but it seems it is not currently possible.
From the libvips documentation, there are some parameters that allow for you to select which page, number of pages, DPI, and scale when loading the PDF: http://jcupitt.github.io/libvips/API/current/VipsForeignSave.html#vips-pdfload-buffer
Checking this repo code, apparently there is currently no way to use these parameters.
Is it possible to do that?
If not, would adding a new argument to the vips_init_image
containing all the possible optional parameters, and then passing it over to the vips_pdfload_buffer
function be the right way to tackle this?
We could allow using the additional parameters for all other image types as well.
@victorkohl I imagine you've found a solution for your use case by now, but I recently ran into the same issue and have added support for page selection when converting PDF, TIFF, and GIF (frames) images with bimg
: https://github.com/h2non/bimg/pull/243
@acaloiaro, I'm trying to use imaginary, used your PR in bimg - https://github.com/h2non/bimg/pull/243 and finally had multipage support for PDFs in imaginary.
However, PDF being vector based format is giving me pretty bad quality output on "enlarge" operation in imaginary. Is there a way to control quality/dpi of final image by enlarging PDF before image conversion? My end goal is to use that in imaginary.
Thanks :)
However, PDF being vector based format is giving me pretty bad quality output on "enlarge" operation in imaginary. Is there a way to control quality/dpi of final image by enlarging PDF before image conversion? My end goal is to use that in imaginary.
Sorry @vposhamod -- I'm not at all familiar with Imaginary. I'm not sure if it's possible to do what you want with the current bimg API(s), but I could be wrong.
Thanks for the reply - I tried PDFium and it worked for me. This was the one I was exactly looking for. - https://pdfium.googlesource.com/pdfium/#running-the-sample-program , however I'm not sure if I can integrate it with bimg.
The vips.h
file has to be updated to, for example, ~~use a generic "option" struct that could be reused and all optional parameters be set in the "loader" calls.~~ i just realized this is exactly what OP said.
Currently i’m using a patched version of vips.h with a hard coded value (because i have a very specific need):
diff --git a/vips.h b/vips.h
index 64d772f..07dbf5b 100644
--- a/vips.h
+++ b/vips.h
@@ -421,7 +421,7 @@ vips_init_image (void *buf, size_t len, int imageType, VipsImage **out) {
} else if (imageType == GIF) {
code = vips_gifload_buffer(buf, len, out, "access", VIPS_ACCESS_RANDOM, NULL);
} else if (imageType == PDF) {
- code = vips_pdfload_buffer(buf, len, out, "access", VIPS_ACCESS_RANDOM, NULL);
+ code = vips_pdfload_buffer(buf, len, out, "access", VIPS_ACCESS_RANDOM, "dpi", (gdouble)(300.0), NULL);
} else if (imageType == SVG) {
code = vips_svgload_buffer(buf, len, out, "access", VIPS_ACCESS_RANDOM, NULL);
#endif
i should send a PR next week to pass all options.
@Leryan Have a look at https://github.com/h2non/bimg/pull/243/files#diff-2f86e815e484a95ab8d5f25c812cffb82b627945ef4e4bc39fa9ab53ccc2af8c. It adds generic options, which I believe is what you want. Simpy add a new one to the options struct.