Emacs PDF View: Replace current page with file using PDFtk

| emacs

I needed to replace a page in a PDF with another PDF. This was a bit of an annoying process on my iPad involving copying and pasting pages in Noteful and then re-exporting them as a PDF, but it was easy to do in Emacs thanks to pdf-tools and PDFtk.

;;;###autoload
(defun sacha-pdf-view-replace-current-page-with-file (file)
  "Replace the current page in PDF View with FILE.
Requires pdftk."
  (interactive "FFile to insert: ")
  (let ((temp-file (concat (make-temp-name "pdf-view") ".pdf")))
    (call-process
     "pdftk"
     nil nil nil
     (concat "A=" (expand-file-name (buffer-file-name)))
     (concat "B=" (expand-file-name file))
     "cat"
     (format "A%d-%d"
             1
             (1- (pdf-view-current-page)))
     "B"
     (format "A%d-end"
             (1+ (pdf-view-current-page)))
     "output"
     temp-file)
    (rename-file temp-file (buffer-file-name) t)))
This is part of my Emacs configuration.
View Org source for this post