Created
August 12, 2013 22:30
-
-
Save zippy1978/6215947 to your computer and use it in GitHub Desktop.
A simple Groovy script using Ghost4J to perform PDF document analyzing (page count, font report, ink coverage)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// A simple Groovy script using Ghost4J to perform PDF document analyzing (page count, font report, ink coverage) | |
// The script expects a single argument: a PDF filename or URL | |
@GrabResolver(name='ghost4j', root='http://repo.ghost4j.org/maven2/snapshots/') | |
@Grab(group='org.ghost4j', module='ghost4j', version='0.5.1-SNAPSHOT') | |
import org.ghost4j.analyzer.AnalysisItem | |
import org.ghost4j.analyzer.FontAnalyzer | |
import org.ghost4j.document.PDFDocument | |
import org.ghost4j.analyzer.InkAnalyzer | |
// Parse arguments | |
def filename | |
if (this.args.length < 1) { | |
println 'Error: no file name or URL provided' | |
System.exit(0) | |
} else { | |
filename = args[0] | |
} | |
// Open or download PDF | |
def file | |
if (filename.startsWith('http:')) { | |
file = new File('tmp.pdf') | |
file << new URL(filename).openStream() | |
} else { | |
file = new File(filename) | |
} | |
// Load document | |
def document = new PDFDocument() | |
document.load(file) | |
// Print page count | |
println "----------------- PAGE COUNT ----------------" | |
println document.getPageCount() | |
// Analyze fonts and print results | |
println "-------------------- FONTS ------------------" | |
def fontAnalyzer = new FontAnalyzer() | |
fontAnalyzer.analyze(document).each {it -> | |
println(it) | |
} | |
// Analyze ink coverage and print results | |
println "--------------- INK COVERAGE ----------------" | |
def inkAnalyzer = new InkAnalyzer() | |
inkAnalyzer.analyze(document).each {it -> | |
println(it) | |
} | |
// Delete temp.pdf | |
if (filename.startsWith('http:')) { | |
file.delete() | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment