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 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 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 by .
Know how VeryPDFworks.
- 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.
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:
/* gets the data from a 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);
$returned_content = get_data('http://online.verypdf.com/api/index.php?apikey=XXXXXXXXXXXXX&app=pdfcompressor&outfile=out.pdf
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.