Convert PDF to PNG

Source: Internet
Author: User
Tags imagemagick

There is often a need to convert Word to PDF, convert Word to picture, and convert PDF to picture in project development.

For the above requirements, write your own implementation in this regard:

1, Word converted to PDF, the previous article has been written, reference address: http://blog.csdn.net/catoop/article/details/42527349

2, Word converted to a picture, the realization of ideas for word-->pdf-->png first step conversion reference previously written articles

3, PDF conversion to picture, we realize the idea pdf-->png


This article focuses on the conversion of PDF to PNG:

First we will prepare the following:

1, Ghostscript Installation

2, ImageMagick installation


Let's do the decomposition below:

First, Ghostscript installation and testing

We first download the installation Ghostscript, website address: http://ghostscript.com/download/gsdnld.html

(here download can be run directly version ghostscript-9.15-linux-x86_64.tgz, download unzip, use command alias gs= '/opt/shanhy/ghostscript-9.15-linux-x86_64/ Gs-915-linux_x86_64 ' configuration alias, before the configuration alias, to/usr/bin under check if there is already GS file, if it is possible that the system comes with, we can use directly, you can also change the GS file name Gs_bak and then use Alias Configure aliases)

After the installation is successful, enter the command gs-version if the following output indicates that the installation was successful and the version was printed.

GPL Ghostscript 9.15 (2014-09-22) Copyright (C) Artifex Software, Inc.  All rights reserved.

Then use the following command to convert the output of a PDF test, command:

Gs-dnosafer-r300-dbatch-sdevice=pngalpha-dnopause-depscrop-soutputfile=testfilepng/%d.png testfile.pdf

After executing the command, there will be the following output, where page is the converted page number, the other output is due to some font problems and data, as long as the output to the last page in the middle without interruption, the file resolution conversion is successful, the following is the output of a file I converted:

GPL Ghostscript 9.15 (2014-09-22) Copyright (C) Artifex Software, Inc.  All rights reserved. This software comes and NO warranty:see the file public for details. Processing pages 1 through 38.Page 1Page 2Page 3Substituting font Helvetica for arialmt.loading Nimbussanl-regu font from %rom%resource/font/nimbussanl-regu ... 5956124 4561384 9518216 8029777 3 done. Substituting font helvetica-bold for arial-boldmt.loading nimbussanl-bold font from%rom%resource/font/nimbussanl-bold ... 6013452 4628661 10043208 8183225 3 done. Page 4Page 5Page 6
At this point, the installation and testing of Ghostscript has been successful.

PS: About the GS command a lot of parameters, need to compare the official website to study it. Very powerful.

Second, ImageMagick installation

Download install ImageMagick, official website: http://www.imagemagick.org/script/download.php, there are many connections, find a download to download the installation (are foreign sites, need to dial VPN bar)

After the installation is successful, use the command convert-version to view the ImageMagick version number to verify that the installation was successful, as follows:

[Email protected] ghostscript-9.15-linux-x86_64]# convert-versionversion:imagemagick 6.5.4-7 2012-04-10 Q16 OpenMP Http://www.imagemagick.orgCopyright:Copyright (C) 1999-2009 ImageMagick Studio LLC

Execute the command and make a PDF conversion test:

convert/opt/shanhy/testfile.pdf/opt/shanhy/testpdfpng/%d. $pic

At this point, ImageMagick installation and testing is complete.


Some friends may ask, above we use Ghostscript already can convert file picture, why also install ImageMagick?

Here's an explanation: the focus and strength of the convert command in ImageMagick is the processing power of the image, and many times we need to work directly with the images converted from the PDF. In this case, using the convert command would satisfy many of our needs, with a lot of arguments about the convert command, and you can see the information about ImageMagick and don't repeat it here.

In addition, the convert command directly converts the PDF to a picture, which is a dependent Ghostscript library, so Ghostscript can do a separate picture conversion, and convert can only perform separate picture processing before installing Ghostscript. You cannot convert a PDF directly to a picture.


Finally, in our business application implementation, we recommend that you write the file conversion commands to the shell script, using the program call script. Although it is also possible to invoke API implementations through code, I think it would be more efficient to use the system's shell processing.


Thank you!










Convert PDF to PNG

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.