-- Hoogle documentation, generated by Haddock
-- See Hoogle, http://www.haskell.org/hoogle/


-- | A collection of tools for processing PDF files.
--   
--   Mid level tools for processing PDF files.
--   
--   Level of abstraction: document, catalog, page
@package pdf-toolbox-document
@version 0.0.7.1


-- | Various types
module Pdf.Toolbox.Document.Types

-- | Rectangle
data Rectangle a
Rectangle :: a -> a -> a -> a -> Rectangle a

-- | Create rectangle form an array of 4 numbers
rectangleFromArray :: Monad m => Array -> PdfE m (Rectangle Double)
instance GHC.Show.Show a => GHC.Show.Show (Pdf.Toolbox.Document.Types.Rectangle a)


-- | Utilities for internal use
module Pdf.Toolbox.Document.Internal.Util

-- | Check that the dictionary has the specified "Type" filed
ensureType :: Monad m => Name -> Dict -> PdfE m ()

-- | Get dictionary type, name at key "Type"
dictionaryType :: Monad m => Dict -> PdfE m Name


-- | Internal type declarations
module Pdf.Toolbox.Document.Internal.Types

-- | PDF document
--   
--   It is a trailer under the hood
data Document
Document :: XRef -> Dict -> Document

-- | Document catalog
data Catalog
Catalog :: Ref -> Dict -> Catalog

-- | Page tree
data PageTree
PageTreeNode :: PageNode -> PageTree
PageTreeLeaf :: Page -> PageTree

-- | Page tree node, contains pages or other nodes
data PageNode
PageNode :: Ref -> Dict -> PageNode

-- | Pdf document page
data Page
Page :: Ref -> Dict -> Page

-- | Information dictionary
data Info
Info :: Ref -> Dict -> Info

-- | Font dictionary
data FontDict
FontDict :: Dict -> FontDict
instance GHC.Show.Show Pdf.Toolbox.Document.Internal.Types.FontDict
instance GHC.Show.Show Pdf.Toolbox.Document.Internal.Types.Info
instance GHC.Show.Show Pdf.Toolbox.Document.Internal.Types.PageTree
instance GHC.Show.Show Pdf.Toolbox.Document.Internal.Types.Page
instance GHC.Show.Show Pdf.Toolbox.Document.Internal.Types.PageNode
instance GHC.Show.Show Pdf.Toolbox.Document.Internal.Types.Catalog
instance GHC.Show.Show Pdf.Toolbox.Document.Internal.Types.Document


-- | Basic support for encrypted PDF documents
module Pdf.Toolbox.Document.Encryption

-- | Decrypt input stream
type Decryptor = Ref -> DecryptorScope -> IS -> IO IS

-- | The default user password
defaultUserPassword :: ByteString

-- | Standard decryptor. RC4
mkStandardDecryptor :: Monad m => Dict -> Dict -> ByteString -> PdfE m (Maybe Decryptor)

-- | Decrypt object with the decryptor
decryptObject :: (IS -> IO IS) -> Object a -> IO (Object a)

-- | Encryption handler may specify different encryption keys for strings
--   and streams
data DecryptorScope
DecryptString :: DecryptorScope
DecryptStream :: DecryptorScope
instance GHC.Show.Show Pdf.Toolbox.Document.Encryption.Algorithm


-- | Interface to the underlying PDF file
module Pdf.Toolbox.Document.Monad

-- | Interface to the underlying PDF file
class Monad m => MonadPdf m

-- | find object by it's reference
lookupObject :: MonadPdf m => Ref -> PdfE m (Object Int64)

-- | decoded stream content
--   
--   Note: the <a>IS</a> returned is valid only until the next
--   <a>lookupObject</a> or any other operation, that requares seek
streamContent :: MonadPdf m => Ref -> Stream Int64 -> PdfE m (Stream IS)

-- | Current decryptor
getDecryptor :: MonadPdf m => PdfE m (Maybe Decryptor)

-- | Get random access input stream for direct access to the PDF file
getRIS :: MonadPdf m => PdfE m RIS

-- | Get all stream filters
getStreamFilters :: MonadPdf m => PdfE m [StreamFilter]

-- | Recursively load indirect object
deref :: (MonadPdf m, Show a) => Object a -> PdfE m (Object ())


-- | Font dictionary
module Pdf.Toolbox.Document.FontDict

-- | Font dictionary
data FontDict

-- | Font subtypes
data FontSubtype
FontType0 :: FontSubtype
FontType1 :: FontSubtype
FontMMType1 :: FontSubtype
FontType3 :: FontSubtype
FontTrueType :: FontSubtype

-- | Get font subtype
fontDictSubtype :: Monad m => FontDict -> PdfE m FontSubtype

-- | Load font info for the font
fontDictLoadInfo :: (MonadPdf m, MonadIO m) => FontDict -> PdfE m FontInfo
instance GHC.Classes.Eq Pdf.Toolbox.Document.FontDict.FontSubtype
instance GHC.Show.Show Pdf.Toolbox.Document.FontDict.FontSubtype


-- | Document info dictionary
module Pdf.Toolbox.Document.Info

-- | Document title
infoTitle :: MonadPdf m => Info -> PdfE m (Maybe Str)


-- | Page tree node
module Pdf.Toolbox.Document.PageNode

-- | Page tree node, contains pages or other nodes
data PageNode

-- | Page tree
data PageTree
PageTreeNode :: PageNode -> PageTree
PageTreeLeaf :: Page -> PageTree

-- | Total number of child leaf nodes, including deep children
pageNodeNKids :: MonadPdf m => PageNode -> PdfE m Int

-- | Parent page node
pageNodeParent :: MonadPdf m => PageNode -> PdfE m (Maybe PageNode)

-- | Referencies to all kids
pageNodeKids :: MonadPdf m => PageNode -> PdfE m [Ref]

-- | Load page tree node by reference
loadPageNode :: MonadPdf m => Ref -> PdfE m PageTree

-- | Find page by it's number
--   
--   Note: it is not efficient for PDF files with a lot of pages, because
--   it performs traversal through the page tree each time. Use
--   <a>pageNodeNKids</a>, <a>pageNodeKids</a> and <a>loadPageNode</a> for
--   efficient traversal.
pageNodePageByNum :: MonadPdf m => PageNode -> Int -> PdfE m Page


-- | PDF document page
module Pdf.Toolbox.Document.Page

-- | Pdf document page
data Page

-- | Page's parent node
pageParentNode :: MonadPdf m => Page -> PdfE m PageNode

-- | List of references to page's content streams
pageContents :: MonadPdf m => Page -> PdfE m [Ref]

-- | Media box, inheritable
pageMediaBox :: MonadPdf m => Page -> PdfE m (Rectangle Double)

-- | Font dictionaries for the page
pageFontDicts :: MonadPdf m => Page -> PdfE m [(Name, FontDict)]

-- | Extract text from the page
--   
--   It tries to add spaces between chars if they don't present as actual
--   characters in content stream.
pageExtractText :: (MonadPdf m, MonadIO m) => Page -> PdfE m Text
data XObject
XObject :: ByteString -> GlyphDecoder -> XObject
pageXObjects :: (MonadPdf m, MonadIO m) => Page -> PdfE m [(Name, XObject)]


-- | Basic implementation of pdf monad
module Pdf.Toolbox.Document.Pdf

-- | Convenient type alias
type Pdf m = PdfE (Pdf' m)

-- | Basic implementation of pdf monad
data Pdf' m a

-- | Execute PDF action with <a>RIS</a>
runPdf :: MonadIO m => RIS -> [StreamFilter] -> Pdf m a -> m (Either PdfError a)

-- | Execute PDF action with <a>Handle</a>
runPdfWithHandle :: MonadIO m => Handle -> [StreamFilter] -> Pdf m a -> m (Either PdfError a)

-- | Get PDF document
document :: MonadIO m => Pdf m Document

-- | Remove all objects from cache
flushObjectCache :: Monad m => Pdf m ()

-- | Perform action without adding objects to cache. Note: the existent
--   cache is not flushed, and is used within the action
withoutObjectCache :: Monad m => Pdf m () -> Pdf m ()

-- | All stream filters implemented by the toolbox
--   
--   Right now it contains only FlateDecode filter
knownFilters :: [StreamFilter]

-- | Whether the PDF document it encrypted
isEncrypted :: MonadIO m => Pdf m Bool

-- | Set the password to be user for decryption
--   
--   Returns False when the password is wrong
setUserPassword :: MonadIO m => ByteString -> Pdf m Bool

-- | The default user password
defaultUserPassword :: ByteString

-- | Decrypt PDF object using user password is set
decrypt :: MonadIO m => Ref -> Object a -> Pdf m (Object a)

-- | Monads in which <a>IO</a> computations may be embedded. Any monad
--   built by applying a sequence of monad transformers to the <a>IO</a>
--   monad will be an instance of this class.
--   
--   Instances should satisfy the following laws, which state that
--   <a>liftIO</a> is a transformer of monads:
--   
--   <ul>
--   <li><pre><a>liftIO</a> . <a>return</a> = <a>return</a></pre></li>
--   <li><pre><a>liftIO</a> (m &gt;&gt;= f) = <a>liftIO</a> m &gt;&gt;=
--   (<a>liftIO</a> . f)</pre></li>
--   </ul>
class Monad m => MonadIO (m :: * -> *)

-- | Lift a computation from the <a>IO</a> monad.
liftIO :: MonadIO m => IO a -> m a
instance Control.Monad.Trans.Class.MonadTrans Pdf.Toolbox.Document.Pdf.Pdf'
instance Control.Monad.IO.Class.MonadIO m => Control.Monad.IO.Class.MonadIO (Pdf.Toolbox.Document.Pdf.Pdf' m)
instance GHC.Base.Monad m => GHC.Base.Applicative (Pdf.Toolbox.Document.Pdf.Pdf' m)
instance GHC.Base.Functor m => GHC.Base.Functor (Pdf.Toolbox.Document.Pdf.Pdf' m)
instance GHC.Base.Monad m => GHC.Base.Monad (Pdf.Toolbox.Document.Pdf.Pdf' m)
instance Control.Monad.IO.Class.MonadIO m => Pdf.Toolbox.Document.Monad.MonadPdf (Pdf.Toolbox.Document.Pdf.Pdf' m)


-- | PDF document
module Pdf.Toolbox.Document.Document

-- | PDF document
--   
--   It is a trailer under the hood
data Document

-- | Get the document catalog
documentCatalog :: MonadPdf m => Document -> PdfE m Catalog

-- | Document encryption dictionary
documentEncryption :: MonadPdf m => Document -> PdfE m (Maybe Dict)

-- | Infornation dictionary for the document
documentInfo :: MonadPdf m => Document -> PdfE m (Maybe Info)


-- | Document datalog
module Pdf.Toolbox.Document.Catalog

-- | Document catalog
data Catalog

-- | Get root node of page tree
catalogPageNode :: MonadPdf m => Catalog -> PdfE m PageNode


-- | Mid level utils for processing PDF file
--   
--   Basic example how to get number of pages in document
--   
--   <pre>
--   withBinaryFile "input.pdf" ReadMode $ handle -&gt;
--     <a>runPdfWithHandle</a> handle <a>knownFilters</a> $ do
--       pdf &lt;- <a>document</a>
--       catalog &lt;- <a>documentCatalog</a> pdf
--       rootNode &lt;- <a>catalogPageNode</a> catalog
--       cout &lt;- <a>pageNodeNKids</a> rootNode
--       liftIO $ print count
--   </pre>
module Pdf.Toolbox.Document
