问题
Good day, I have read all questions and answers about "PDF to SVG", "PDF to PNG, PNG to SVG" and had no success in accomplishing my task.
I have a PDF that is about 10mb (blueprints from archiCAD) and after using pdf2svg to convert to SVG, the SVG is about 70mb. Conversion takes 14sec, but the web page load takes about 150sec because of the size of the SVG.
My question is - how can i convert PDF in PHP to SVG with appropriate size for web without quality loss and without gzipping it?
This code converts PDF to SVG that is 70MB:
$fileName = 'in.pdf';
$targetName = 'out.svg';
exec("pdf2svg ".escapeshellarg($fileName)." ".escapeshellarg($targetName));
This one converts PDF to 500kb SVG with HUGE quality loss, some path loss, text loss, etc.
exec("convert -density 200 ".escapeshellarg($fileName)." middle.png");
exec("inkscape middle.png --export-plain-svg=".escapeshellarg($targetName));
Ive tried imagemagick, autotrace, potrace, inkscape, pdf2svg. I tried the answer from "convert pdf to svg". Other questions (on SO) weren't even close to what I need.
I've read almost every link on Google and almost every topic accomplish my task, but they all start with a with small size PDF so it doesn't solve my problem.
回答1:
why you want absolutly in SVG? If you reduce the PDF with Ghostscript, the images will stay like they are, just change resolution.
I've convert PDF in smallers size with ghostscript. It's easiest and faster than with convert ( imagick).
I think you can find in http://www.ghostscript.com/doc/current/Use.htm some parts of the answer.
I use this for reduce PDF in "ebook" quality:
exec('gs -sDEVICE=pdfwrite -dCompatibilityLevel=1.4 -dPDFSETTINGS=/ebook -dNOPAUSE -dBATCH -sOutputFile='.$outfile.' '.$file.' ',$output, $return_var);
来源:https://stackoverflow.com/questions/38329534/how-to-convert-10mb-pdf-to-svg-quickly-with-appropriate-size-for-web