ATuin

PDF trait - scala

May 13th, 2012
89
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Scala 0.88 KB | None | 0 0
  1. abstract class PDF (val fileName:String){
  2.   import SPDF._
  3.  
  4.   val document: ValDocument
  5.  
  6.   def open:PDF = new PDF(fileName) {
  7.     val document = documentPDF(fileName)
  8.   }
  9.  
  10.   lazy val documentInfo    = document              ∘ (_.getDocumentInformation)
  11.   lazy val documentCatalog = document              ∘ (_.getDocumentCatalog)
  12.   lazy val numberOfPages   = document              ∘ (_.getNumberOfPages)
  13.   lazy val title           = documentInfo.toOption ∘ (_.getTitle()) | "Unknow"
  14.   lazy val allPages        = documentCatalog       ∘ (_.getAllPages())
  15.  
  16.   def close:PDF = {
  17.     val d = document
  18.     new PDF(fileName) {
  19.       val document:ValDocument = d flatMap closePDF
  20.     }
  21.   }
  22.  
  23.   def getPage(o:PDOutlineItem):Int =
  24.     document.doOrElse((d) => getPage(o.findDestinationPage(d)))(-1)
  25.  
  26.   def getPage(p:PDPage):Int = allPages.toOption ∘ (_.indexOf(p)) | -1
  27. }
Advertisement
Add Comment
Please, Sign In to add comment