GithubHelp home page GithubHelp logo

pdf2pptx's Introduction

pdf2pptx

Convert your (Beamer) PDF slides to (Powerpoint) PPTX

So you don't like using Powerpoint and would rather use Latex/Beamer to make your slides, however, you have a fancy Surface and you want to use the pen during the presentation? Here is my solution.

This script gets a PDF file as input and generates a Powerpoint PPTX file while preserving the format of the original PDF. Theoretically all PDF files, regardless of the original generator, can be converted to PPTX slides with this (not tested though).

Simply explained, I convert all the slides to high-quality image files first, and then push them into a Powerpoint project as a slide.

How to run

  • Execute ./pdf2pptx.sh test.pdf to generate a test.pdf.pptx file (replace test.pdf with your filename).
  • By default the output powerpoint project is in the widescreen mode. If your slides are not for widescreen you can alternatively run ./pdf2pptx.sh test.pdf notwide to generate a 4:3 standard PPTX project.

Dependencies

  • You need convert from ImageMagick
  • zip and sed
  • (Optional) perl, python, or ruby if you use a symlink to pdf2pptx.sh

If you're using Linux you probably already have all the above.

If you're using OSX you need to install ImageMagick and make sure convert is accessible from your Terminal.

If you're using Windows you can use Cygwin, but if you don't have it already, it is not recommended! If you're using Windows 10, you can easily set up Ubuntu bash (More Info), install ImageMagick and then use the script natively. Another solution for Windows users is to access a linux box (such as your university servers) to take care of the task.

New issues with ImageMagick

ImageMagick no longer allows PDF to image conversion. If you get the following error on the test example:

Doing test.pdf
convert: not authorized `test.pdf' @ error/constitute.c/ReadImage/412.
convert: no images defined `./test.pdf.temp/slide.png' @ error/convert.c/ConvertImageCommand/3210.
Error with extraction

in /etc/ImageMagick-6/policy.xml or /etc/ImageMagick/policy.xml, change:

<policy domain="coder" rights="none" pattern="PDF" />

to

<policy domain="coder" rights="read" pattern="PDF" />

Now it should work. Note that modifying the policy file would require root privileges. If you do not have root access on your machine, you can alternatively compile and use an older version of ImageMagick.

Acknowledgement

Thanks to Melissa O'Neill for providing a Pdf2Keynote tool for mac which has motivated this small project!

pdf2pptx's People

Contributors

ashafaei avatar axkibe avatar davelab6 avatar ip-arch avatar janacht avatar kaorahi avatar kpj avatar tidota avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

pdf2pptx's Issues

Doesn't work in Ubuntu 18.04 Error with extraction

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

How to change output resolution

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.

Policy.xml problems ImageMagick-7

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.

Doesn't work on OSX, need to change sed flag

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

Conversion error even after policy.xml is changed as per README

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

Altering ImageMagick policy.xml when installed using Homebrew

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.

No such file or directory

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

Different Aspect Ratio

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

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.