-
Hi guys. I have a PDF file which I'm trying to convert into the image(s) but for some reason vips shows some font thing failed message and removes some part of the text on the image. Currently my code on PHP is looking like this: $pdf = \Jcupitt\Vips\Image::newFromFile($filePath, ['access' => 'sequential']);
$pages = $pdf->get('n-pages');
for ($page = 0; $page < $pages; $page++) {
$image = \Jcupitt\Vips\Image::newFromFile($filePath, ['page' => $page, 'access' => 'sequential']);
$image = $image->thumbnail_image(1500);
$image->writeToFile(sys_get_temp_dir() . "/pdf_{$page}.jpeg", ['Q' => 50]);
} Guess this issue is not related to the php-vips bindings directly as I'm getting the same results when running:
Is possible to convert pdf to image correctly? |
Beta Was this translation helpful? Give feedback.
Replies: 4 comments 6 replies
-
Hello again,
What a hilarious error message. That's not us, I'd guess something inside poppler has gone wrong, perhaps because this PDF contains an error or uses some strange feature. Did you make the PDF yourself? PDF export often has an "embed fonts" option, ticking this box can help. I would try the same PDF in another poppler-based renderer, like xpdf or evince. If they can display it correctly, it's a libvips problem, if not (likely IMO) it's a poppler problem. If it's poppler, your best best is to try PDFium, the alternative PDF backend on libvips. You'd need to be able to build libvips from source for this. |
Beta Was this translation helpful? Give feedback.
-
Alpine Linux is minimal and doesn't include fonts or font discovery tools by default. Perhaps installing a font package such as |
Beta Was this translation helpful? Give feedback.
-
No. It was generated by 3rd-party service: vokaal.com.
I've seen that PDFium has some issue with musl and that's the reason why Alpine team didn't bring it into their ecosystem yet. But this is not your (Vips team problem) :) Alpine community request: https://gitlab.alpinelinux.org/alpine/aports/-/issues/16486
Firefox could open that PDF correctly. Also I tried imagemagick + ghostscript and it converts PDF to image correctly. I'm going to install fonts @kleisauke suggested above. Just in case (if it gives you ideas): I didn't install any fonts when played with imagemagick + ghostscript. |
Beta Was this translation helpful? Give feedback.
-
One more question related to particular this case: Is it possible to teach vips to throw an exception if something went wrong with poppler (for example) ? The idea is pretty simple: I'd like to know when something went wrong instead of silently converting pdf to image with issues like I faced now |
Beta Was this translation helpful? Give feedback.
Alpine Linux is minimal and doesn't include fonts or font discovery tools by default. Perhaps installing a font package such as
font-noto
(which should also addfontconfig
as a dependency) may help.