Created
November 25, 2016 16:23
-
-
Save mh21/51eb315f38d4cb95bb657ec3e1d65b98 to your computer and use it in GitHub Desktop.
Convert PDF presentations to PowerPoint PPT
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash -e | |
D=$(mktemp -d) | |
mkdir -p "$D/o/Pictures" "$D/o/META-INF" | |
echo -n 'application/vnd.oasis.opendocument.presentation' > "$D/mimetype" | |
gs -sDEVICE=png16m -dSAFER -dBATCH -dNOPAUSE -dTextAlphaBits=4 -dGraphicsAlphaBits=4 -sOutputFile="$D/o/Pictures/%03d.png" -r254 "$1" | |
pushd "$D/o" | |
echo '<?xml version="1.0" encoding="UTF-8"?><manifest:manifest xmlns:manifest="urn:oasis:names:tc:opendocument:xmlns:manifest:1.0" manifest:version="1.2"><manifest:file-entry manifest:full-path="/" manifest:version="1.2" manifest:media-type="application/vnd.oasis.opendocument.presentation"/><manifest:file-entry manifest:full-path="content.xml" manifest:media-type="text/xml"/>' > "META-INF/manifest.xml" | |
for i in Pictures/*.png; do | |
echo "<manifest:file-entry manifest:full-path='$i' manifest:media-type='image/png'/>" >> "META-INF/manifest.xml" | |
done | |
echo '</manifest:manifest>' >> "META-INF/manifest.xml" | |
echo '<?xml version="1.0" encoding="UTF-8"?><office:document-content xmlns:office="urn:oasis:names:tc:opendocument:xmlns:office:1.0" xmlns:draw="urn:oasis:names:tc:opendocument:xmlns:drawing:1.0" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:svg="urn:oasis:names:tc:opendocument:xmlns:svg-compatible:1.0" office:version="1.2"><office:body><office:presentation>' > "content.xml" | |
for i in Pictures/*.png; do | |
echo "<draw:page><draw:frame svg:width='28cm' svg:height='21cm'><draw:image xlink:href='$i'></draw:image></draw:frame></draw:page>" >> "content.xml" | |
done | |
echo '</office:presentation></office:body></office:document-content>' >> "content.xml" | |
zip "../out.odp" -r . | |
soffice "-env:UserInstallation=file://$D" --headless --invisible --convert-to ppt --outdir "$D" "$D/out.odp" | |
popd | |
cp "$D/out.ppt" "${1%.pdf}.ppt" | |
rm -rf "$D" | |
echo "Complete: $1 -> ${1%.pdf}.ppt" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment