Skip to content

Instantly share code, notes, and snippets.

@smasty
Created September 28, 2012 15:15
Show Gist options
  • Save smasty/3800452 to your computer and use it in GitHub Desktop.
Save smasty/3800452 to your computer and use it in GitHub Desktop.
Converts unprintable PDFs exported to SVG by Evince to PNG images.
<?php
$data = file_get_contents($argv[1]);
$offset = isset($argv[2]) ? $argv[2] : 0;
if(preg_match_all('~data:image\/png;base64,([^"]+)"~i', $data, $matches)){
foreach($matches[1] as $k=>$i){
$id = $k+1+$offset;
echo "Processing page $id...";
$image = imagecreatefromstring(base64_decode($i));
imagepng($image, "pages/$id.png");
imagedestroy($image);
echo "Done\n";
}
} else{
echo "No pages found.\n";
exit(1);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment