minimum viable PDF

python
R
Author

George Girton

Published

August 15, 2022

Sadness

I had been using the ‘join.py’ script for years. It was free, included in the macOS, and so simple!

I call join.py with a shell script, and it would join various pdf documents all into one pdf!

Just a jolly bin/bash:

#!/bin/bash

“/System/Library/Automator/Combine PDF Pages.action/Contents/Resources/join.py” -o pdf/final.pdf part1.pdf part2.pdf part3.pdf

and Bob’s your uncle. Figuratively speaking.

What could be more ‘minimum viable python’ than a 1-line call to a python script file?

what I think happened

I think this was a python 2 script, and when I added python 3.10 to my path, when python 3 became the default python in the system, the join.py script did not work anymore. There were some funny-looking ‘print’ statement errors, and I think that is one thing changed from python 2 to 3.

One way to solve it would be to remove python 3.10 from the system path. But … what else would stop working?

how i solved it

Since I already was using R’s image-magick package to generate thumbnails for these pdfs, then calling the shell script from R

I just found an R package to combine the pbfs,and that was qdpf

so it was all

`{R} library(qpdf)
    qpdf::pdf_combine(output= "FinalOutput.pdf", 
        input = c("first1.pdf", "second2.pdf"))

and problem solved.

#install.packages("magick")
#install.packages("qpdf")
library(pdftools)
library(magick)
library(qpdf)

reports_in_folder <- "rpt"

producethumbnailfrompdf <- 
function (pdfname, thumbname, infolder = reports_in_folder,       outfolder = "images", horizontalscale=564) {
  infile <- paste0(infolder,'/',pdfname)
  outfile <-paste0(outfolder,'/',thumbname) 
  pdf.page <- image_read_pdf(infile,density=72)  
                              # it is always 72
  image_write(image_scale(pdf.page[1],horizontalscale), outfile)
  }

producethumbnailfrompdf("SCBZL06.pdf","market-comparison.png")

  qpdf::pdf_combine(output= "FinalOutput.pdf", 
        input = c("first1.pdf", "second2.pdf"))
        

— all photos Copyright © 2022-2024 George D Girton all rights reserved