ATuin

Untitled

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