I have tried to use fpdf,fpdi, tcpdf, htlm2pdf to create pdfs from image files. I can get them all to work but the problem is I cant get them to compress the file with pdf compression. If I have a 5mb image and use any of the above to create the pdf I get a 5mb pdf file. If I create the image using using adobe I can get the pdf down to about 700kb with no noticeable reduction in the image clarity. I have tried the convertapi API and this also gives me a compressed pdf file which is what I want but it can only do single pages. I am also needing to be able to convert multiple images into a single multipage pdf. Anyone other ideas would be highly appreciated.
0
votes
1 Answers
0
votes
If you want reduce the size of pdf files, the best way is with Ghostscript:
exec('gs -sDEVICE=pdfwrite -dCompatibilityLevel=1.4 -dPDFSETTINGS=/ebook -dNOPAUSE -dBATCH -sOutputFile='.$output_file.' '.$file.' ',$output, $return_var);
If you want each page in differents files:
exec('convert -density 300 -trim "'.$file.'" -resize 1000 -quality 85 -colorspace RGB -background white "'.$destination.'" &', $output, $return_var);
Be careful with the & at the end of the $destination, it will name your file "mypdf.pdf" with 5 pages in "mypdf-0.pdf, mypdf-1.pdf..." for each page.