Skip to content

Instantly share code, notes, and snippets.

@yuw
Created June 15, 2019 02:49
Show Gist options
  • Save yuw/506311df464ecc2030e238155d1bbaa5 to your computer and use it in GitHub Desktop.
Save yuw/506311df464ecc2030e238155d1bbaa5 to your computer and use it in GitHub Desktop.
Detect blank pages in PDF
#! /usr/bin/env ruby
require "open3"
out, status = Open3.capture2e("gs -o /dev/null -sDEVICE=bbox '#{ARGV[0]}'")
array = out.rstrip.split(/\r?\n/).map {|line| line.chomp }
count = 0
blankpage_list = []
array.each do |i|
if i.include?("0 0 0 0")
pageindex = count - 1
blankpage_list << array[pageindex]
end
count += 1
end
puts array[3]
puts "blank page = #{blankpage_list.length} pages"
p blankpage_list
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment