How to compress PDF through PHP code?

    When you need to compress through PHP code in the cheapest way, please refer to the following method. Maybe you just need to spend less than 20 dollars then you can finish developing software which aims function of compressing PDF through PHP code. Compare with buying a suit of software toolkit, this method is quite economic method.

   This method need to be processed under the help of software VeryPDF PDF Compressor Cloud API. This software is developed  for developers based on cloud service for compressing PDF together with other program languages, include C#, VB.NET, ASP.NET, ASP, PHP, Java, Ruby, Amazon, etc. And by this API service, you can compress PDF through compressing fonts in PDF, down sample image quality in PDF and set password to protected output compressed PDF file. Please check more related information of this software on homepage, in the following part, let us check how to use this software.

Step 1. Get an API code

  • Please register an account on registration page. When registration, you need to input email address and user name then you will get an free account on VeryPDF.
  • When you pay for it, then you will get an API code on account page. This API service is  licensed by per account, once you purchase a plan, you can use your APIKEY to access all of VeryPDF Cloud APIs, include 20+ APIs and 200+ parameters.

Step 2. Compress PDF through PHP code.

  • There are the following parameters you may use:
    pdfa: for converting PDF to PDF/A
    EmbedAllFonts: this parameter is for embedding all font in PDF
    SubsetFonts:subset fonts in PDF file
    CompressFonts:compress fonts in PDF file
    ColorImageFilter:compress color image with special arithmetic, it is support: jpg, jpx, zip methods, default is jpg.
    GrayImageFilter:compress grayscale image with special arithmetic, it is support: jpg, jpx, zip methods, default is jpg.
    MonoImageFilter:compress monochrome image with special arithmetic, it is support: jbig2, jbig2l, fax, zip, rle methods, default is jpg
    ColorImageRes: set the resolution when Downsample Color Images, default is 72dpi
    GrayImageRes:Set the resolution when Downsample grey Images, default is 72dpi
    MonoImageRes:set the resolution when Downsample mono Images, default is 72dpi
    PDFPassword:set password to protect PDF
    KeyLength: encrypt output PDF file by owner password
  • Now let us check how to call this software to compress PDF through PHP code:

    <?php
    //The Code
    /* gets the data from a URL */
    function get_data($url)
    {
        $ch = curl_init();
        $timeout = 5;
        curl_setopt($ch, CURLOPT_URL, $url);
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
        curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, $timeout);
        $data = curl_exec($ch);
        curl_close($ch);
        return $data;
    }

    //The Usage
    $returned_content = get_data('http://online.verypdf.com/api/index.php?apikey=XXXXXXXXXXXXX
    &app=pdfcompressor&outfile=out.pdf&infile=http://online.verypdf.com/examples/cloudapi/verypdf_web_raster.pdf
    &ColorImageRes=20&GrayImageRes=20&MonoImageRes=20');
    echo $returned_content;
    ?>

There are lots of functions of this software, I can not list of them here. During the using, if you have any question, please contact us as soon as possible.

VN:F [1.9.20_1166]
Rating: 7.8/10 (18 votes cast)
VN:F [1.9.20_1166]
Rating: -4 (from 6 votes)
How to compress PDF through PHP code?, 7.8 out of 10 based on 18 ratings

Related Posts

Leave a Reply

Your email address will not be published. Required fields are marked *


Verify Code   If you cannot see the CheckCode image,please refresh the page again!