Is this possible to create video from pdf file?

here is script to convert pdf to video:

exec("convert -geometry 1600x1600 -density 200x200 -quality 100 -resize 800x $pdf_path $temp_images");
exec("ffmpeg -loop 1 -f image2 -framerate 0.5 -b 1800 -i $temp_images_wildcard -c:v libx264 -preset slow -tune stillimage -r 5 -t 22 -y $frame_target 2>&1",$output);

Assuming your PDF files are in your working directory, to create a movie file from a set of PDF files you can execute:

exec("mogrify -verbose -density 500 -resize 800 -format png ./*.pdf")
exec("convert -delay 600 *.png movie.mp4")

This requires Imagemagick and Ghostscript to be installed. Works on Linux/Mac OS X/Microsoft Windows. Not vectorial.


If you want to generate some PDF files to test the commands, here is a python script that generates PDF files:

import pandas as pd  
import numpy as np
from matplotlib import pyplot as plt

for i in range(10):
    np.random.seed(i)
    dates = pd.date_range('1/1/2000', periods=50)
    print('dates: {0}'.format(dates))
    df = pd.DataFrame(np.random.randn(len(dates), 1), index=dates.astype(str), columns=['A'])

    print('df: {0}'.format(df))
    plt.figure(figsize=(60,15))
    df.plot(y='A', use_index=True)
    plt.xticks(rotation=70)
    plt.savefig('plot_{0}.pdf'.format(i), dpi=300, bbox_inches='tight')

FYI:

  • Imagemagick Convert PDF to JPEG: FailedToExecuteCommand `"gswin32c.exe" / PDFDelegateFailed --> that's the error message you get if Ghostscript is not installed.
  • Convert every pdf in the current directory to png --> convert doesn't support batch conversion, unlike mogrify.
  • ffmpeg requires the images to have some very specific naming convention, unlike convert which simply takes the lexicographical order.
  • Using Imagemagick to convert images to the video: background of the video is black, whereas the background of the pictures are white
  • How can I run mogrify over the 3 million JPG files? -> mogrify can only process one file at the time, but one can go around with xargs.