zoukankan      html  css  js  c++  java
  • How to convert a PDF file to JPEGs using PHP

    Hey, Today I would like to show you how we can convert PDF to JPEG using imagick extension. Imagick is a native php extension to create and modify images using the ImageMagick API, which is mostly built-in in PHP installation so no need to include any thing. ImageMagick software suite allow us to create, read, edit, and compose bitmap images easily.

    PHP – Convert all PDF pages to JPEG

    Using following simple example you can convert all pages of PDF to JPEG images.

    As you are seeing, you have to pass a PDF file and it will produce JPEG files for each page of your given PDF file as output. writeImages() function second parameter is false, so it will not join the images, means it will produce image sequence(create images for each page) Example – converted-0.jpg, converted-1.jpg.

    How to Convert a PDF to JPEG using PHP

    PHP – Convert specific PDF page to JPEG

    If you want to convert specific page for example first page of your PDF file only then define PDF file name like this myfile.pdf[0] and run the script it will show convert only first page of your PDF file. Following is the example –

    PHP – Convert specific PDF page to JPEG with quality

    If you need better quality, try adding $imagick->setResolution(150, 150); before reading the file. setResolution() must be called before loading or creating an image.

    If you experience transparency problems when converting PDF to JPEG (black background), try flattening your file:

    shared hosting – Convert a PDF to JPEG using PHP

    Most of the shared hosting providers do not compile imagick extension with PHP, but imagick binaries will be available, so here is the code to convert PDF to JPEG with imagick binaries.

    You have to change binaries location (/usr/local/bin/convert) to your server location which you can get from your hosting admin.

    Lots of things can be done with Imagick extension, explore more about it at – http://php.net/manual/en/book.imagick.php

     

    I hope you like this Post, Please feel free to comment below, your suggestion and problems if you face - we are here to solve your problems.

  • 相关阅读:
    Excel打印视图模式,界面网格模式等设置
    如何跳槽,如何找工作?
    使用Typora编写Markdown的介绍及快捷键的使用
    Office 2016 简体中文批量授权版镜像下载(含Visio、Project)
    Microsoft SQL Server 2016 官方简体中文64位企业版下载(含激活序列号密钥)
    python解析库lxml的简单使用
    二分查找——Find Peak Element,主要是利用index+1和index-1来判断走向
    RCE——远程命令/代码执行
    Java反序列化漏洞原理和检测
    S-H-ESD——就是先识别出趋势(中位数),然后做残差,利用残差看看正态分布的偏离点
  • 原文地址:https://www.cnblogs.com/mouseleo/p/10070381.html
Copyright © 2011-2022 走看看