ATuin

PDFSplitter in scala

May 24th, 2012
126
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Scala 0.87 KB | None | 0 0
  1. package com.logikujo.literoj.testBookTree
  2.  
  3. import com.logikujo.spdf.Implicits._
  4. import com.logikujo.spdf.pdfoperator._
  5. import PDFOperator._
  6.  
  7. import com.logikujo.utils.Treeable._
  8.  
  9. import scalaz._
  10. import Scalaz._
  11.  
  12. object TestBookTree {
  13.   def getBookmarkTree = pdfGetDocument >>= pdfBookmarksTree
  14.  
  15.   def getSubPDF(n:Int) = getBookmarkTree >>= ((t) =>
  16.     state((pdf:PDF) =>
  17.       (pdf, ({
  18.         val l = (t.toOption >>= identity).
  19.           orZero.levels(n).toList.map(_.get).flatten ∘ ((d) =>
  20.             SubPDF(d.getTitle, pdf.getPage(d),1))
  21.         SubPDF.orderSubPDFList(1)(pdf.numberOfPages)(l).reverse
  22.         }))))
  23.  
  24.   def saveSubPDF = (l:List[SubPDF]) => state((pdf:PDF) =>
  25.     (pdf, l ∘ (_.write(pdf))))
  26.  
  27.   def main(args:Array[String]) {
  28.     val l = (getSubPDF(args(0).toInt) >>= saveSubPDF >>= pdfClose) ! PDF("testPDF.pdf")
  29.     println(l)
  30.   }
  31. }
Advertisement
Add Comment
Please, Sign In to add comment