Im trying to using pdfbox and compile with groovy but I dont know
this is my code I use
groovyc main.groovy
but not works please help me
this.class.classLoader.rootLoader.addURL(
new URL("/usr/share/groovy/lib/pdfbox-2.0.11.jar"))
import org.apache.pdfbox.util.Splitter
import org.apache.pdfbox.pdmodel.PDDocument
class Main {
static void main(String[] args){
File pdfFile = new File(args[0])
PDDocument doc = new PDDocument().load(pdfFile)
Splitter splitter = new Splitter()
def count=0
splitter.split(doc).eachWithIndex{v,i->
v.save(pdfFile.path[0..-5]+'_'+i.toString().padLeft(3,'0')+'.pdf')
v.close()
}
}
}
Change
import org.apache.pdfbox.util.Splitter
to
import org.apache.pdfbox.multipdf.Splitter
(see javadoc )
Also make sure to include the needed dependencies , ie fontbox and commons-log and possibly more.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.