ashafaei / pdf2pptx Goto Github PK
View Code? Open in Web Editor NEWConvert your (Beamer) PDF slides to (Powerpoint) PPTX
License: MIT License
Convert your (Beamer) PDF slides to (Powerpoint) PPTX
License: MIT License
In pdf2pptx.sh I changed resolution from 1024 to 2048.
Initially I got a memory error:
convert-im6.q16: cache resources exhausted `../pres.pdf' @ error/cache.c/OpenPixelCache/4095.
...
So I changed the memory allocated in /etc/ImageMagick-6/policy.xml
Now it works, but the output presentation seems to look the same pixel-wise.
I changed the resolution to 4096 and still, it looks no clearer.
Is there something else I need to consider, perhaps with assembling the ppt file, where resolution might be lost?
I'm using WSL2.
Appreciate any help.
I am trying to follow the fix for the error (as named on the repo's homepage).
oliver$ ~/pdf2pptx/pdf2pptx.sh foo.pdf notwide
Doing foo.pdf
Removing foo.pdf.temp
convert: unable to load module '/usr/local/Cellar/imagemagick/7.0.10-29/lib/ImageMagick/modules-Q16HDRI/coders/pdf.la': file not found @ error/module.c/OpenModule/1287.
convert: no decode delegate for this image format `PDF' @ error/constitute.c/ReadImage/562.
convert: no images defined `foo.pdf.temp/slide.png' @ error/convert.c/ConvertImageCommand/3285.
Error with extraction
As can be seen, on Mac OSX my ImageMagick is/was installed using Homebrew. Trying to find the policy.xml
file there appear to be two:
oliver$ find /usr/local/Cellar/imagemagick/7.0.10-29/ -name "policy.xml"
/usr/local/Cellar/imagemagick/7.0.10-29//etc/ImageMagick-7/policy.xml
/usr/local/Cellar/imagemagick/7.0.10-29//share/doc/ImageMagick-7/www/source/policy.xml
The contents of the two are largely the same (as can be seen from doing a git diff
):
oliver$ git diff --no-index /usr/local/Cellar/imagemagick/7.0.10-29//share/doc/ImageMagick-7/www/source/policy.xml /usr/local/Cellar/imagemagick/7.0.10-29//etc/ImageMagick-7/policy.xml
diff --git a/usr/local/Cellar/imagemagick/7.0.10-29//share/doc/ImageMagick-7/www/source/policy.xml b/usr/local/Cellar/imagemagick/7.0.10-29//etc/ImageMagick-7/policy.xml
index d497934..8083d3d 100644
--- a/usr/local/Cellar/imagemagick/7.0.10-29//share/doc/ImageMagick-7/www/source/policy.xml
+++ b/usr/local/Cellar/imagemagick/7.0.10-29//etc/ImageMagick-7/policy.xml
@@ -25,10 +25,6 @@
<policy domain="coder" rights="none" pattern="HTTP" />
- Lets prevent users from executing any image filters:
-
- <policy domain="filter" rights="none" pattern="*" />
-
The /repository file system is restricted to read only. We use a glob
expression to match all paths that start with /repository:
@@ -65,6 +61,7 @@
<!-- <policy domain="resource" name="map" value="4GiB"/> -->
<!-- <policy domain="resource" name="width" value="10KP"/> -->
<!-- <policy domain="resource" name="height" value="10KP"/> -->
+ <!-- <policy domain="resource" name="list-length" value="128"/> -->
<!-- <policy domain="resource" name="area" value="100MP"/> -->
<!-- <policy domain="resource" name="disk" value="16EiB"/> -->
<!-- <policy domain="resource" name="file" value="768"/> -->
@@ -72,6 +69,7 @@
<!-- <policy domain="resource" name="throttle" value="0"/> -->
<!-- <policy domain="resource" name="time" value="3600"/> -->
<!-- <policy domain="coder" rights="none" pattern="MVG" /> -->
+ <!-- <policy domain="module" rights="none" pattern="{PS,PDF,XPS}" /> -->
<!-- <policy domain="delegate" rights="none" pattern="HTTPS" /> -->
<!-- <policy domain="path" rights="none" pattern="@*" /> -->
<!-- <policy domain="cache" name="memory-map" value="anonymous"/> -->
so taking the contents of /usr/local/Cellar/imagemagick/7.0.10-29//etc/ImageMagick-7/policy.xml
it reads
...
<policymap>
<!-- <policy domain="system" name="shred" value="2"/> -->
<!-- <policy domain="system" name="precision" value="6"/> -->
<!-- <policy domain="system" name="memory-map" value="anonymous"/> -->
<!-- <policy domain="system" name="max-memory-request" value="256MiB"/> -->
<!-- <policy domain="resource" name="temporary-path" value="/tmp"/> -->
<!-- <policy domain="resource" name="memory" value="2GiB"/> -->
<!-- <policy domain="resource" name="map" value="4GiB"/> -->
<!-- <policy domain="resource" name="width" value="10KP"/> -->
<!-- <policy domain="resource" name="height" value="10KP"/> -->
<!-- <policy domain="resource" name="list-length" value="128"/> -->
<!-- <policy domain="resource" name="area" value="100MP"/> -->
<!-- <policy domain="resource" name="disk" value="16EiB"/> -->
<!-- <policy domain="resource" name="file" value="768"/> -->
<!-- <policy domain="resource" name="thread" value="4"/> -->
<!-- <policy domain="resource" name="throttle" value="0"/> -->
<!-- <policy domain="resource" name="time" value="3600"/> -->
<!-- <policy domain="coder" rights="none" pattern="MVG" /> -->
<!-- <policy domain="module" rights="none" pattern="{PS,PDF,XPS}" /> -->
<!-- <policy domain="delegate" rights="none" pattern="HTTPS" /> -->
<!-- <policy domain="path" rights="none" pattern="@*" /> -->
<!-- <policy domain="cache" name="memory-map" value="anonymous"/> -->
<!-- <policy domain="cache" name="synchronize" value="True"/> -->
<!-- <policy domain="cache" name="shared-secret" value="passphrase" stealth="true"/> -->
</policymap>
Are you able to advise what to change to resolve the error? I have tried altering the coder
policy to have rights=read
, and some similar bits of tinkering, but thus far without success.
Thanks for this great tool :)
I was wondering about other options for resizing. My pdf is in 16:10 aspect ratio, and using powerpoint I can convert the slides to this dimension but there is a loss in quality.
Would you be able to explain what this code snippet does?
if [ "$makeWide" = true ]; then
pat='<p:sldSz cx=\"9144000\" cy=\"6858000\" type=\"screen4x3\"\/>'
wscreen='<p:sldSz cy=\"6858000\" cx=\"12192000\"\/>'
call_sed "s/${pat}/${wscreen}/g" ../presentation.xml
fi
popd
I've tried to edit the policy XML as described in the README,
However it seems the xml file is different with ImageMagick 7.
There are a number of examples commented out, none matching the line to change as per the readme.
I copied in the desired line, but am still returning the error.
The error is present on any .pdf I try to convert, including the test.pdf included.
Thank you very much for developing a useful script.
I am trying to use this script, but unfortunately, it does not work well.
It seems that the directories are not generated properly.
$ ./pdf2pptx.sh test.pdf
Doing test.pdf
Extraction succ!
cp: cannot stat '/home/???/tmp/template': No such file or directory
mkdir: cannot create directory 'test.pdf.pptx.base/ppt/media': No such file or directory
cp: target 'test.pdf.pptx.base/ppt/media/' is not a directory
./pdf2pptx.sh: line 99: pushd: test.pdf.pptx.base/ppt/media/: No such file or directory
Processing 3
cp: cannot stat '../slides/slide1.xml': No such file or directory
./pdf2pptx.sh: line 95: ../slides/_rels/slide-3.xml.rels: No such file or directory
cat: ../slides/_rels/slide1.xml.rels: No such file or directory
sed: can't read ../_rels/presentation.xml.rels: No such file or directory
sed: can't read ../../[Content_Types].xml: No such file or directory
sed: can't read ../presentation.xml: No such file or directory
Processing 2
cp: cannot stat '../slides/slide1.xml': No such file or directory
./pdf2pptx.sh: line 95: ../slides/_rels/slide-2.xml.rels: No such file or directory
cat: ../slides/_rels/slide1.xml.rels: No such file or directory
sed: can't read ../_rels/presentation.xml.rels: No such file or directory
sed: can't read ../../[Content_Types].xml: No such file or directory
sed: can't read ../presentation.xml: No such file or directory
Processing 1
cp: cannot stat '../slides/slide1.xml': No such file or directory
./pdf2pptx.sh: line 95: ../slides/_rels/slide-1.xml.rels: No such file or directory
cat: ../slides/_rels/slide1.xml.rels: No such file or directory
sed: can't read ../_rels/presentation.xml.rels: No such file or directory
sed: can't read ../../[Content_Types].xml: No such file or directory
sed: can't read ../presentation.xml: No such file or directory
Processing 0
cp: cannot stat '../slides/slide1.xml': No such file or directory
./pdf2pptx.sh: line 95: ../slides/_rels/slide-0.xml.rels: No such file or directory
cat: ../slides/_rels/slide1.xml.rels: No such file or directory
sed: can't read ../_rels/presentation.xml.rels: No such file or directory
sed: can't read ../../[Content_Types].xml: No such file or directory
sed: can't read ../presentation.xml: No such file or directory
sed: can't read ../presentation.xml: No such file or directory
./pdf2pptx.sh: line 112: popd: directory stack empty
./pdf2pptx.sh: line 114: pushd: test.pdf.pptx.base: No such file or directory
./pdf2pptx.sh: line 117: popd: directory stack empty
In this case, how should the shellscript be modified?
PS. Referring this document, I realized I should modify <p:sldSz>
on ppt/presentation.xml
.
PS 2. Actually seemed not enough....
I got a bunch of errors on OSX saying "invalid command code..."
Fixed by switching -i
to -i ''
based on this stackoverflow post: http://stackoverflow.com/questions/7573368/in-place-edits-with-sed-on-os-x
Thanks for posting this great tool!
diff --git a/pdf2pptx.sh b/pdf2pptx.sh
index 75202f9..d65570e 100755
--- a/pdf2pptx.sh
+++ b/pdf2pptx.sh
@@ -52,19 +52,19 @@ function add_slide {
id=$((id+8))
entry='<Relationship Id=\"rId'$id'\" Type=\"http:\/\/schemas\.openxmlformats\.org\/officeDocu
rep="${pat}${entry}"
- sed -i "s/${pat}/${rep}/g" ../_rels/presentation.xml.rels
+ sed -i '' "s/${pat}/${rep}/g" ../_rels/presentation.xml.rels
pat='slide1\.xml\" ContentType=\"application\/vnd\.openxmlformats-officedocument\.presentatio
entry='<Override PartName=\"\/ppt\/slides\/slide-'$1'\.xml\" ContentType=\"application\/vnd\.
rep="${pat}${entry}"
- sed -i "s/${pat}/${rep}/g" ../../\[Content_Types\].xml
+ sed -i '' "s/${pat}/${rep}/g" ../../\[Content_Types\].xml
sid=$1
sid=$((sid+256))
pat='<p:sldIdLst>'
entry='<p:sldId id=\"'$sid'\" r:id=\"rId'$id'\"\/>'
rep="${pat}${entry}"
- sed -i "s/${pat}/${rep}/g" ../presentation.xml
+ sed -i '' "s/${pat}/${rep}/g" ../presentation.xml
}
function make_slide {
@@ -84,7 +84,7 @@ done
if [ "$makeWide" = true ]; then
pat='<p:sldSz cx=\"9144000\" cy=\"6858000\" type=\"screen4x3\"\/>'
wscreen='<p:sldSz cy=\"6858000\" cx=\"12192000\"\/>'
- sed -i "s/${pat}/${wscreen}/g" ../presentation.xml
+ sed -i '' "s/${pat}/${wscreen}/g" ../presentation.xml
fi
popd
Getting an Issue in Ubuntu 18.04 when trying test.pdf
Doing test.pdf
Removing test.pdf.temp
convert-im6.q16: not authorized `test.pdf' @ error/constitute.c/ReadImage/412.
convert-im6.q16: no images defined `./test.pdf.temp/slide.png' @ error/convert.c/ConvertImageCommand/3258.
Error with extraction
the shebang should use /usr/bin/env
Hi,
I have changed the policy.xml as suggested in your README. I get the following error message
pdf2pptx: line 33: 25392 Aborted (core dumped) convert -density $density
$colorspace -resize "x$ {resolution}" $1 ./$tempname/slide.png
Error with extraction
How can I workaround this issue?
JFYI, the following is the output of imagemagick version query:
$ convert --version
Version: ImageMagick 6.9.7-4 Q16 x86_64 20170114 http://www.imagemagick.org
Copyright: © 1999-2017 ImageMagick Studio LLC
License: http://www.imagemagick.org/script/license.php
Features: Cipher DPC Modules OpenMP
Delegates (built-in): bzlib djvu fftw fontconfig freetype jbig jng jpeg lcms lqr ltdl lzma openexr pangocairo png tiff wmf x xml zlib
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.