How to convert PDF to PNG in PHP without using a library such as ImageMagic

Asked 5 months ago, Updated 5 months ago, 15 views

Is it possible to convert PDF to PNG using the default PHP module such as PDFlib or GD in PHP?
I think there is a library for conversion, such as ImageMagic, but I do not import such an external library.


2022-09-30 12:02

3 Answers

Unfortunately, PHP standard modules do not have the ability to convert PDF to PNG.

By the way, the PDF lib and GD you mentioned are not standard PHP modules, but for some reason it seems that they happen to be usable.

2022-09-30 12:02

I'm not familiar with libraries that only PHP completes, but there seems to be a Ghostscript wrapper library.

As you can see in the document on the page above, it looks like ↓.

    'timeout' = > 42,
    'gs.binaries' = > '/opt/local/gs/bin/gs',
), $logger);
$transcoder->toImage(' document.pdf', 'output.jpg');

'gs.binaries'=>'/opt/local/gs/bin/gs', as you may have noticed,
gs must be installed.

2022-09-30 12:02

PDFlib does not have the ability to image PDF pages.

Although there is a function to paste images into PDF files, FoxIt is famous for making PDFs into images (effectively viewer functionality) (but PHP is not available).

2022-09-30 12:02

If you have any answers or tips

© 2023 OneMinuteCode. All rights reserved.