How to compress PDF with embedded fonts by cloud API?

Question:We have an application generates dynamic PDF files with embedded NMSYS fonts.But it's size is very large in comparison to the original file having larger data then dynamically generated having same fonts.Is it possible to reduce size of such PDF with PHP any script, API or extension ? Is there any solution on VeryPDF?

Answer: After checking your PDF files and comparing difference we find that the fonts take up close to 96% of the space in the file. So subsetting the font used in this file is basically your only option to make it smaller. Different libraries or applications have different options to enable subsetting, in the article I will show you subset PDF fonts by VeryPDF PDF Compressor Cloud API, by which you can compress PDF through API operation. If you need to run the compression process from PHP this API application also can help you make it. However, if you need to compress PDF from script, please choose the command line version of PDF Compressor.  Please know more information of this software on homepage, in the following part, I will show you how to compress PDF by cloud API.

Know how VeryPDF cloud API works.

  • All the VeryPDF cloud based APIs run within browsers, so you do not need to download any other applications.
  • When you compress PDF by cloud API, please open browser and input URL following the below example.
  • http://online.verypdf.com/api/index.php?apikey=XXXXXXXXXXXXX
    &app=pdfcompressor&outfile=out.pdf
    &infile=http://online.verypdf.com/examples/cloud-api/verypdf_web_raster.pdf
    &ColorImageRes=20&GrayImageRes=20&MonoImageRes=20&SubsetFonts&CompressFonts
    By the above URL, we can compress PDF through both compressing images in PDF and fonts in PDF. For compressing images in PDF, the above example uses downsample image resolution. For compressing fonts, the above example uses subset fonts and compress fonts.
    Using API for compressing PDF, you need to change local PDF file to online PDF file as for now the API can not supports local PDF file compression. If you have API code, please use the real API code instead of xxxx, or else there will be watermark on output. Here are some parameters for your reference:
    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.

Run compression from PHP code.

  • When you need to run the compression from PHP code, please refer to the following code template:
  • <?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/cloud-api/verypdf_web_raster.pdf
    &ColorImageRes=20&GrayImageRes=20&MonoImageRes=20&SubsetFonts&CompressFonts
    ');
    echo $returned_content;
    ?>

By this API and this method, we can compress PDF by cloud API easily. During the using, if you have any question, please contact us as soon as possible.

VN:F [1.9.20_1166]
Rating: 0.0/10 (0 votes cast)
VN:F [1.9.20_1166]
Rating: 0 (from 0 votes)

Related Posts

This entry was posted in VeryPDF Cloud API and tagged , . Bookmark the permalink.

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!