{- |
Copyright  : Will Thompson, Iñaki García Etxebarria and Jonas Platte
License    : LGPL-2.1
Maintainer : Iñaki García Etxebarria (garetxe@gmail.com)
-}

module GI.Poppler.Objects.Document
    ( 

-- * Exported types
    Document(..)                            ,
    DocumentK                               ,
    toDocument                              ,
    noDocument                              ,


 -- * Methods
-- ** documentFindDest
    documentFindDest                        ,


-- ** documentGetAttachments
    documentGetAttachments                  ,


-- ** documentGetAuthor
    documentGetAuthor                       ,


-- ** documentGetCreationDate
    documentGetCreationDate                 ,


-- ** documentGetCreator
    documentGetCreator                      ,


-- ** documentGetFormField
    documentGetFormField                    ,


-- ** documentGetId
    documentGetId                           ,


-- ** documentGetKeywords
    documentGetKeywords                     ,


-- ** documentGetMetadata
    documentGetMetadata                     ,


-- ** documentGetModificationDate
    documentGetModificationDate             ,


-- ** documentGetNAttachments
    documentGetNAttachments                 ,


-- ** documentGetNPages
    documentGetNPages                       ,


-- ** documentGetPage
    documentGetPage                         ,


-- ** documentGetPageByLabel
    documentGetPageByLabel                  ,


-- ** documentGetPageLayout
    documentGetPageLayout                   ,


-- ** documentGetPageMode
    documentGetPageMode                     ,


-- ** documentGetPdfVersion
    documentGetPdfVersion                   ,


-- ** documentGetPdfVersionString
    documentGetPdfVersionString             ,


-- ** documentGetPermissions
    documentGetPermissions                  ,


-- ** documentGetProducer
    documentGetProducer                     ,


-- ** documentGetSubject
    documentGetSubject                      ,


-- ** documentGetTitle
    documentGetTitle                        ,


-- ** documentHasAttachments
    documentHasAttachments                  ,


-- ** documentIsLinearized
    documentIsLinearized                    ,


-- ** documentNewFromData
    documentNewFromData                     ,


-- ** documentNewFromFile
    documentNewFromFile                     ,


-- ** documentNewFromGfile
    documentNewFromGfile                    ,


-- ** documentNewFromStream
    documentNewFromStream                   ,


-- ** documentSave
    documentSave                            ,


-- ** documentSaveACopy
    documentSaveACopy                       ,




 -- * Properties
-- ** Author
    DocumentAuthorPropertyInfo              ,
    getDocumentAuthor                       ,


-- ** CreationDate
    DocumentCreationDatePropertyInfo        ,
    getDocumentCreationDate                 ,


-- ** Creator
    DocumentCreatorPropertyInfo             ,
    getDocumentCreator                      ,


-- ** Format
    DocumentFormatPropertyInfo              ,
    getDocumentFormat                       ,


-- ** FormatMajor
    DocumentFormatMajorPropertyInfo         ,
    getDocumentFormatMajor                  ,


-- ** FormatMinor
    DocumentFormatMinorPropertyInfo         ,
    getDocumentFormatMinor                  ,


-- ** Keywords
    DocumentKeywordsPropertyInfo            ,
    getDocumentKeywords                     ,


-- ** Linearized
    DocumentLinearizedPropertyInfo          ,
    getDocumentLinearized                   ,


-- ** Metadata
    DocumentMetadataPropertyInfo            ,
    getDocumentMetadata                     ,


-- ** ModDate
    DocumentModDatePropertyInfo             ,
    getDocumentModDate                      ,


-- ** PageLayout
    DocumentPageLayoutPropertyInfo          ,
    getDocumentPageLayout                   ,


-- ** PageMode
    DocumentPageModePropertyInfo            ,
    getDocumentPageMode                     ,


-- ** Permissions
    DocumentPermissionsPropertyInfo         ,
    getDocumentPermissions                  ,


-- ** Producer
    DocumentProducerPropertyInfo            ,
    getDocumentProducer                     ,


-- ** Subject
    DocumentSubjectPropertyInfo             ,
    getDocumentSubject                      ,


-- ** Title
    DocumentTitlePropertyInfo               ,
    getDocumentTitle                        ,


-- ** ViewerPreferences
    DocumentViewerPreferencesPropertyInfo   ,
    getDocumentViewerPreferences            ,




    ) where

import Prelude ()
import Data.GI.Base.ShortPrelude

import qualified Data.Text as T
import qualified Data.ByteString.Char8 as B
import qualified Data.Map as Map

import GI.Poppler.Types
import GI.Poppler.Callbacks
import qualified GI.GObject as GObject
import qualified GI.Gio as Gio

newtype Document = Document (ForeignPtr Document)
foreign import ccall "poppler_document_get_type"
    c_poppler_document_get_type :: IO GType

type instance ParentTypes Document = DocumentParentTypes
type DocumentParentTypes = '[GObject.Object]

instance GObject Document where
    gobjectIsInitiallyUnowned _ = False
    gobjectType _ = c_poppler_document_get_type
    

class GObject o => DocumentK o
instance (GObject o, IsDescendantOf Document o) => DocumentK o

toDocument :: DocumentK o => o -> IO Document
toDocument = unsafeCastTo Document

noDocument :: Maybe Document
noDocument = Nothing

-- VVV Prop "author"
   -- Type: TBasicType TUTF8
   -- Flags: [PropertyReadable]

getDocumentAuthor :: (MonadIO m, DocumentK o) => o -> m T.Text
getDocumentAuthor obj = liftIO $ getObjectPropertyString obj "author"

data DocumentAuthorPropertyInfo
instance AttrInfo DocumentAuthorPropertyInfo where
    type AttrAllowedOps DocumentAuthorPropertyInfo = '[ 'AttrGet]
    type AttrSetTypeConstraint DocumentAuthorPropertyInfo = (~) ()
    type AttrBaseTypeConstraint DocumentAuthorPropertyInfo = DocumentK
    type AttrGetType DocumentAuthorPropertyInfo = T.Text
    type AttrLabel DocumentAuthorPropertyInfo = "Document::author"
    attrGet _ = getDocumentAuthor
    attrSet _ = undefined
    attrConstruct _ = undefined

-- VVV Prop "creation-date"
   -- Type: TBasicType TInt32
   -- Flags: [PropertyReadable]

getDocumentCreationDate :: (MonadIO m, DocumentK o) => o -> m Int32
getDocumentCreationDate obj = liftIO $ getObjectPropertyCInt obj "creation-date"

data DocumentCreationDatePropertyInfo
instance AttrInfo DocumentCreationDatePropertyInfo where
    type AttrAllowedOps DocumentCreationDatePropertyInfo = '[ 'AttrGet]
    type AttrSetTypeConstraint DocumentCreationDatePropertyInfo = (~) ()
    type AttrBaseTypeConstraint DocumentCreationDatePropertyInfo = DocumentK
    type AttrGetType DocumentCreationDatePropertyInfo = Int32
    type AttrLabel DocumentCreationDatePropertyInfo = "Document::creation-date"
    attrGet _ = getDocumentCreationDate
    attrSet _ = undefined
    attrConstruct _ = undefined

-- VVV Prop "creator"
   -- Type: TBasicType TUTF8
   -- Flags: [PropertyReadable]

getDocumentCreator :: (MonadIO m, DocumentK o) => o -> m T.Text
getDocumentCreator obj = liftIO $ getObjectPropertyString obj "creator"

data DocumentCreatorPropertyInfo
instance AttrInfo DocumentCreatorPropertyInfo where
    type AttrAllowedOps DocumentCreatorPropertyInfo = '[ 'AttrGet]
    type AttrSetTypeConstraint DocumentCreatorPropertyInfo = (~) ()
    type AttrBaseTypeConstraint DocumentCreatorPropertyInfo = DocumentK
    type AttrGetType DocumentCreatorPropertyInfo = T.Text
    type AttrLabel DocumentCreatorPropertyInfo = "Document::creator"
    attrGet _ = getDocumentCreator
    attrSet _ = undefined
    attrConstruct _ = undefined

-- VVV Prop "format"
   -- Type: TBasicType TUTF8
   -- Flags: [PropertyReadable]

getDocumentFormat :: (MonadIO m, DocumentK o) => o -> m T.Text
getDocumentFormat obj = liftIO $ getObjectPropertyString obj "format"

data DocumentFormatPropertyInfo
instance AttrInfo DocumentFormatPropertyInfo where
    type AttrAllowedOps DocumentFormatPropertyInfo = '[ 'AttrGet]
    type AttrSetTypeConstraint DocumentFormatPropertyInfo = (~) ()
    type AttrBaseTypeConstraint DocumentFormatPropertyInfo = DocumentK
    type AttrGetType DocumentFormatPropertyInfo = T.Text
    type AttrLabel DocumentFormatPropertyInfo = "Document::format"
    attrGet _ = getDocumentFormat
    attrSet _ = undefined
    attrConstruct _ = undefined

-- VVV Prop "format-major"
   -- Type: TBasicType TUInt32
   -- Flags: [PropertyReadable]

getDocumentFormatMajor :: (MonadIO m, DocumentK o) => o -> m Word32
getDocumentFormatMajor obj = liftIO $ getObjectPropertyCUInt obj "format-major"

data DocumentFormatMajorPropertyInfo
instance AttrInfo DocumentFormatMajorPropertyInfo where
    type AttrAllowedOps DocumentFormatMajorPropertyInfo = '[ 'AttrGet]
    type AttrSetTypeConstraint DocumentFormatMajorPropertyInfo = (~) ()
    type AttrBaseTypeConstraint DocumentFormatMajorPropertyInfo = DocumentK
    type AttrGetType DocumentFormatMajorPropertyInfo = Word32
    type AttrLabel DocumentFormatMajorPropertyInfo = "Document::format-major"
    attrGet _ = getDocumentFormatMajor
    attrSet _ = undefined
    attrConstruct _ = undefined

-- VVV Prop "format-minor"
   -- Type: TBasicType TUInt32
   -- Flags: [PropertyReadable]

getDocumentFormatMinor :: (MonadIO m, DocumentK o) => o -> m Word32
getDocumentFormatMinor obj = liftIO $ getObjectPropertyCUInt obj "format-minor"

data DocumentFormatMinorPropertyInfo
instance AttrInfo DocumentFormatMinorPropertyInfo where
    type AttrAllowedOps DocumentFormatMinorPropertyInfo = '[ 'AttrGet]
    type AttrSetTypeConstraint DocumentFormatMinorPropertyInfo = (~) ()
    type AttrBaseTypeConstraint DocumentFormatMinorPropertyInfo = DocumentK
    type AttrGetType DocumentFormatMinorPropertyInfo = Word32
    type AttrLabel DocumentFormatMinorPropertyInfo = "Document::format-minor"
    attrGet _ = getDocumentFormatMinor
    attrSet _ = undefined
    attrConstruct _ = undefined

-- VVV Prop "keywords"
   -- Type: TBasicType TUTF8
   -- Flags: [PropertyReadable]

getDocumentKeywords :: (MonadIO m, DocumentK o) => o -> m T.Text
getDocumentKeywords obj = liftIO $ getObjectPropertyString obj "keywords"

data DocumentKeywordsPropertyInfo
instance AttrInfo DocumentKeywordsPropertyInfo where
    type AttrAllowedOps DocumentKeywordsPropertyInfo = '[ 'AttrGet]
    type AttrSetTypeConstraint DocumentKeywordsPropertyInfo = (~) ()
    type AttrBaseTypeConstraint DocumentKeywordsPropertyInfo = DocumentK
    type AttrGetType DocumentKeywordsPropertyInfo = T.Text
    type AttrLabel DocumentKeywordsPropertyInfo = "Document::keywords"
    attrGet _ = getDocumentKeywords
    attrSet _ = undefined
    attrConstruct _ = undefined

-- VVV Prop "linearized"
   -- Type: TBasicType TBoolean
   -- Flags: [PropertyReadable]

getDocumentLinearized :: (MonadIO m, DocumentK o) => o -> m Bool
getDocumentLinearized obj = liftIO $ getObjectPropertyBool obj "linearized"

data DocumentLinearizedPropertyInfo
instance AttrInfo DocumentLinearizedPropertyInfo where
    type AttrAllowedOps DocumentLinearizedPropertyInfo = '[ 'AttrGet]
    type AttrSetTypeConstraint DocumentLinearizedPropertyInfo = (~) ()
    type AttrBaseTypeConstraint DocumentLinearizedPropertyInfo = DocumentK
    type AttrGetType DocumentLinearizedPropertyInfo = Bool
    type AttrLabel DocumentLinearizedPropertyInfo = "Document::linearized"
    attrGet _ = getDocumentLinearized
    attrSet _ = undefined
    attrConstruct _ = undefined

-- VVV Prop "metadata"
   -- Type: TBasicType TUTF8
   -- Flags: [PropertyReadable]

getDocumentMetadata :: (MonadIO m, DocumentK o) => o -> m T.Text
getDocumentMetadata obj = liftIO $ getObjectPropertyString obj "metadata"

data DocumentMetadataPropertyInfo
instance AttrInfo DocumentMetadataPropertyInfo where
    type AttrAllowedOps DocumentMetadataPropertyInfo = '[ 'AttrGet]
    type AttrSetTypeConstraint DocumentMetadataPropertyInfo = (~) ()
    type AttrBaseTypeConstraint DocumentMetadataPropertyInfo = DocumentK
    type AttrGetType DocumentMetadataPropertyInfo = T.Text
    type AttrLabel DocumentMetadataPropertyInfo = "Document::metadata"
    attrGet _ = getDocumentMetadata
    attrSet _ = undefined
    attrConstruct _ = undefined

-- VVV Prop "mod-date"
   -- Type: TBasicType TInt32
   -- Flags: [PropertyReadable]

getDocumentModDate :: (MonadIO m, DocumentK o) => o -> m Int32
getDocumentModDate obj = liftIO $ getObjectPropertyCInt obj "mod-date"

data DocumentModDatePropertyInfo
instance AttrInfo DocumentModDatePropertyInfo where
    type AttrAllowedOps DocumentModDatePropertyInfo = '[ 'AttrGet]
    type AttrSetTypeConstraint DocumentModDatePropertyInfo = (~) ()
    type AttrBaseTypeConstraint DocumentModDatePropertyInfo = DocumentK
    type AttrGetType DocumentModDatePropertyInfo = Int32
    type AttrLabel DocumentModDatePropertyInfo = "Document::mod-date"
    attrGet _ = getDocumentModDate
    attrSet _ = undefined
    attrConstruct _ = undefined

-- VVV Prop "page-layout"
   -- Type: TInterface "Poppler" "PageLayout"
   -- Flags: [PropertyReadable]

getDocumentPageLayout :: (MonadIO m, DocumentK o) => o -> m PageLayout
getDocumentPageLayout obj = liftIO $ getObjectPropertyEnum obj "page-layout"

data DocumentPageLayoutPropertyInfo
instance AttrInfo DocumentPageLayoutPropertyInfo where
    type AttrAllowedOps DocumentPageLayoutPropertyInfo = '[ 'AttrGet]
    type AttrSetTypeConstraint DocumentPageLayoutPropertyInfo = (~) ()
    type AttrBaseTypeConstraint DocumentPageLayoutPropertyInfo = DocumentK
    type AttrGetType DocumentPageLayoutPropertyInfo = PageLayout
    type AttrLabel DocumentPageLayoutPropertyInfo = "Document::page-layout"
    attrGet _ = getDocumentPageLayout
    attrSet _ = undefined
    attrConstruct _ = undefined

-- VVV Prop "page-mode"
   -- Type: TInterface "Poppler" "PageMode"
   -- Flags: [PropertyReadable]

getDocumentPageMode :: (MonadIO m, DocumentK o) => o -> m PageMode
getDocumentPageMode obj = liftIO $ getObjectPropertyEnum obj "page-mode"

data DocumentPageModePropertyInfo
instance AttrInfo DocumentPageModePropertyInfo where
    type AttrAllowedOps DocumentPageModePropertyInfo = '[ 'AttrGet]
    type AttrSetTypeConstraint DocumentPageModePropertyInfo = (~) ()
    type AttrBaseTypeConstraint DocumentPageModePropertyInfo = DocumentK
    type AttrGetType DocumentPageModePropertyInfo = PageMode
    type AttrLabel DocumentPageModePropertyInfo = "Document::page-mode"
    attrGet _ = getDocumentPageMode
    attrSet _ = undefined
    attrConstruct _ = undefined

-- VVV Prop "permissions"
   -- Type: TInterface "Poppler" "Permissions"
   -- Flags: [PropertyReadable]

getDocumentPermissions :: (MonadIO m, DocumentK o) => o -> m [Permissions]
getDocumentPermissions obj = liftIO $ getObjectPropertyFlags obj "permissions"

data DocumentPermissionsPropertyInfo
instance AttrInfo DocumentPermissionsPropertyInfo where
    type AttrAllowedOps DocumentPermissionsPropertyInfo = '[ 'AttrGet]
    type AttrSetTypeConstraint DocumentPermissionsPropertyInfo = (~) ()
    type AttrBaseTypeConstraint DocumentPermissionsPropertyInfo = DocumentK
    type AttrGetType DocumentPermissionsPropertyInfo = [Permissions]
    type AttrLabel DocumentPermissionsPropertyInfo = "Document::permissions"
    attrGet _ = getDocumentPermissions
    attrSet _ = undefined
    attrConstruct _ = undefined

-- VVV Prop "producer"
   -- Type: TBasicType TUTF8
   -- Flags: [PropertyReadable]

getDocumentProducer :: (MonadIO m, DocumentK o) => o -> m T.Text
getDocumentProducer obj = liftIO $ getObjectPropertyString obj "producer"

data DocumentProducerPropertyInfo
instance AttrInfo DocumentProducerPropertyInfo where
    type AttrAllowedOps DocumentProducerPropertyInfo = '[ 'AttrGet]
    type AttrSetTypeConstraint DocumentProducerPropertyInfo = (~) ()
    type AttrBaseTypeConstraint DocumentProducerPropertyInfo = DocumentK
    type AttrGetType DocumentProducerPropertyInfo = T.Text
    type AttrLabel DocumentProducerPropertyInfo = "Document::producer"
    attrGet _ = getDocumentProducer
    attrSet _ = undefined
    attrConstruct _ = undefined

-- VVV Prop "subject"
   -- Type: TBasicType TUTF8
   -- Flags: [PropertyReadable]

getDocumentSubject :: (MonadIO m, DocumentK o) => o -> m T.Text
getDocumentSubject obj = liftIO $ getObjectPropertyString obj "subject"

data DocumentSubjectPropertyInfo
instance AttrInfo DocumentSubjectPropertyInfo where
    type AttrAllowedOps DocumentSubjectPropertyInfo = '[ 'AttrGet]
    type AttrSetTypeConstraint DocumentSubjectPropertyInfo = (~) ()
    type AttrBaseTypeConstraint DocumentSubjectPropertyInfo = DocumentK
    type AttrGetType DocumentSubjectPropertyInfo = T.Text
    type AttrLabel DocumentSubjectPropertyInfo = "Document::subject"
    attrGet _ = getDocumentSubject
    attrSet _ = undefined
    attrConstruct _ = undefined

-- VVV Prop "title"
   -- Type: TBasicType TUTF8
   -- Flags: [PropertyReadable]

getDocumentTitle :: (MonadIO m, DocumentK o) => o -> m T.Text
getDocumentTitle obj = liftIO $ getObjectPropertyString obj "title"

data DocumentTitlePropertyInfo
instance AttrInfo DocumentTitlePropertyInfo where
    type AttrAllowedOps DocumentTitlePropertyInfo = '[ 'AttrGet]
    type AttrSetTypeConstraint DocumentTitlePropertyInfo = (~) ()
    type AttrBaseTypeConstraint DocumentTitlePropertyInfo = DocumentK
    type AttrGetType DocumentTitlePropertyInfo = T.Text
    type AttrLabel DocumentTitlePropertyInfo = "Document::title"
    attrGet _ = getDocumentTitle
    attrSet _ = undefined
    attrConstruct _ = undefined

-- VVV Prop "viewer-preferences"
   -- Type: TInterface "Poppler" "ViewerPreferences"
   -- Flags: [PropertyReadable]

getDocumentViewerPreferences :: (MonadIO m, DocumentK o) => o -> m [ViewerPreferences]
getDocumentViewerPreferences obj = liftIO $ getObjectPropertyFlags obj "viewer-preferences"

data DocumentViewerPreferencesPropertyInfo
instance AttrInfo DocumentViewerPreferencesPropertyInfo where
    type AttrAllowedOps DocumentViewerPreferencesPropertyInfo = '[ 'AttrGet]
    type AttrSetTypeConstraint DocumentViewerPreferencesPropertyInfo = (~) ()
    type AttrBaseTypeConstraint DocumentViewerPreferencesPropertyInfo = DocumentK
    type AttrGetType DocumentViewerPreferencesPropertyInfo = [ViewerPreferences]
    type AttrLabel DocumentViewerPreferencesPropertyInfo = "Document::viewer-preferences"
    attrGet _ = getDocumentViewerPreferences
    attrSet _ = undefined
    attrConstruct _ = undefined

type instance AttributeList Document = DocumentAttributeList
type DocumentAttributeList = ('[ '("author", DocumentAuthorPropertyInfo), '("creation-date", DocumentCreationDatePropertyInfo), '("creator", DocumentCreatorPropertyInfo), '("format", DocumentFormatPropertyInfo), '("format-major", DocumentFormatMajorPropertyInfo), '("format-minor", DocumentFormatMinorPropertyInfo), '("keywords", DocumentKeywordsPropertyInfo), '("linearized", DocumentLinearizedPropertyInfo), '("metadata", DocumentMetadataPropertyInfo), '("mod-date", DocumentModDatePropertyInfo), '("page-layout", DocumentPageLayoutPropertyInfo), '("page-mode", DocumentPageModePropertyInfo), '("permissions", DocumentPermissionsPropertyInfo), '("producer", DocumentProducerPropertyInfo), '("subject", DocumentSubjectPropertyInfo), '("title", DocumentTitlePropertyInfo), '("viewer-preferences", DocumentViewerPreferencesPropertyInfo)] :: [(Symbol, *)])

type instance SignalList Document = DocumentSignalList
type DocumentSignalList = ('[ '("notify", GObject.ObjectNotifySignalInfo), '("notify::[property]", GObjectNotifySignalInfo)] :: [(Symbol, *)])

-- method Document::new_from_data
-- method type : Constructor
-- Args : [Arg {argName = "data", argType = TBasicType TUTF8, direction = DirectionIn, mayBeNull = False, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, transfer = TransferNothing},Arg {argName = "length", argType = TBasicType TInt32, direction = DirectionIn, mayBeNull = False, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, transfer = TransferNothing},Arg {argName = "password", argType = TBasicType TUTF8, direction = DirectionIn, mayBeNull = True, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, transfer = TransferNothing}]
-- Lengths : []
-- hInArgs : [Arg {argName = "data", argType = TBasicType TUTF8, direction = DirectionIn, mayBeNull = False, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, transfer = TransferNothing},Arg {argName = "length", argType = TBasicType TInt32, direction = DirectionIn, mayBeNull = False, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, transfer = TransferNothing},Arg {argName = "password", argType = TBasicType TUTF8, direction = DirectionIn, mayBeNull = True, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, transfer = TransferNothing}]
-- returnType : TInterface "Poppler" "Document"
-- throws : True
-- Skip return : False

foreign import ccall "poppler_document_new_from_data" poppler_document_new_from_data :: 
    CString ->                              -- data : TBasicType TUTF8
    Int32 ->                                -- length : TBasicType TInt32
    CString ->                              -- password : TBasicType TUTF8
    Ptr (Ptr GError) ->                     -- error
    IO (Ptr Document)


documentNewFromData ::
    (MonadIO m) =>
    T.Text ->                               -- data
    Int32 ->                                -- length
    Maybe (T.Text) ->                       -- password
    m Document
documentNewFromData data_ length_ password = liftIO $ do
    data_' <- textToCString data_
    maybePassword <- case password of
        Nothing -> return nullPtr
        Just jPassword -> do
            jPassword' <- textToCString jPassword
            return jPassword'
    onException (do
        result <- propagateGError $ poppler_document_new_from_data data_' length_ maybePassword
        checkUnexpectedReturnNULL "poppler_document_new_from_data" result
        result' <- (wrapObject Document) result
        freeMem data_'
        freeMem maybePassword
        return result'
     ) (do
        freeMem data_'
        freeMem maybePassword
     )

-- method Document::new_from_file
-- method type : Constructor
-- Args : [Arg {argName = "uri", argType = TBasicType TUTF8, direction = DirectionIn, mayBeNull = False, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, transfer = TransferNothing},Arg {argName = "password", argType = TBasicType TUTF8, direction = DirectionIn, mayBeNull = True, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, transfer = TransferNothing}]
-- Lengths : []
-- hInArgs : [Arg {argName = "uri", argType = TBasicType TUTF8, direction = DirectionIn, mayBeNull = False, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, transfer = TransferNothing},Arg {argName = "password", argType = TBasicType TUTF8, direction = DirectionIn, mayBeNull = True, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, transfer = TransferNothing}]
-- returnType : TInterface "Poppler" "Document"
-- throws : True
-- Skip return : False

foreign import ccall "poppler_document_new_from_file" poppler_document_new_from_file :: 
    CString ->                              -- uri : TBasicType TUTF8
    CString ->                              -- password : TBasicType TUTF8
    Ptr (Ptr GError) ->                     -- error
    IO (Ptr Document)


documentNewFromFile ::
    (MonadIO m) =>
    T.Text ->                               -- uri
    Maybe (T.Text) ->                       -- password
    m Document
documentNewFromFile uri password = liftIO $ do
    uri' <- textToCString uri
    maybePassword <- case password of
        Nothing -> return nullPtr
        Just jPassword -> do
            jPassword' <- textToCString jPassword
            return jPassword'
    onException (do
        result <- propagateGError $ poppler_document_new_from_file uri' maybePassword
        checkUnexpectedReturnNULL "poppler_document_new_from_file" result
        result' <- (wrapObject Document) result
        freeMem uri'
        freeMem maybePassword
        return result'
     ) (do
        freeMem uri'
        freeMem maybePassword
     )

-- method Document::new_from_gfile
-- method type : Constructor
-- Args : [Arg {argName = "file", argType = TInterface "Gio" "File", direction = DirectionIn, mayBeNull = False, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, transfer = TransferNothing},Arg {argName = "password", argType = TBasicType TUTF8, direction = DirectionIn, mayBeNull = True, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, transfer = TransferNothing},Arg {argName = "cancellable", argType = TInterface "Gio" "Cancellable", direction = DirectionIn, mayBeNull = True, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, transfer = TransferNothing}]
-- Lengths : []
-- hInArgs : [Arg {argName = "file", argType = TInterface "Gio" "File", direction = DirectionIn, mayBeNull = False, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, transfer = TransferNothing},Arg {argName = "password", argType = TBasicType TUTF8, direction = DirectionIn, mayBeNull = True, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, transfer = TransferNothing},Arg {argName = "cancellable", argType = TInterface "Gio" "Cancellable", direction = DirectionIn, mayBeNull = True, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, transfer = TransferNothing}]
-- returnType : TInterface "Poppler" "Document"
-- throws : True
-- Skip return : False

foreign import ccall "poppler_document_new_from_gfile" poppler_document_new_from_gfile :: 
    Ptr Gio.File ->                         -- file : TInterface "Gio" "File"
    CString ->                              -- password : TBasicType TUTF8
    Ptr Gio.Cancellable ->                  -- cancellable : TInterface "Gio" "Cancellable"
    Ptr (Ptr GError) ->                     -- error
    IO (Ptr Document)


documentNewFromGfile ::
    (MonadIO m, Gio.FileK a, Gio.CancellableK b) =>
    a ->                                    -- file
    Maybe (T.Text) ->                       -- password
    Maybe (b) ->                            -- cancellable
    m Document
documentNewFromGfile file password cancellable = liftIO $ do
    let file' = unsafeManagedPtrCastPtr file
    maybePassword <- case password of
        Nothing -> return nullPtr
        Just jPassword -> do
            jPassword' <- textToCString jPassword
            return jPassword'
    maybeCancellable <- case cancellable of
        Nothing -> return nullPtr
        Just jCancellable -> do
            let jCancellable' = unsafeManagedPtrCastPtr jCancellable
            return jCancellable'
    onException (do
        result <- propagateGError $ poppler_document_new_from_gfile file' maybePassword maybeCancellable
        checkUnexpectedReturnNULL "poppler_document_new_from_gfile" result
        result' <- (wrapObject Document) result
        touchManagedPtr file
        whenJust cancellable touchManagedPtr
        freeMem maybePassword
        return result'
     ) (do
        freeMem maybePassword
     )

-- method Document::new_from_stream
-- method type : Constructor
-- Args : [Arg {argName = "stream", argType = TInterface "Gio" "InputStream", direction = DirectionIn, mayBeNull = False, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, transfer = TransferNothing},Arg {argName = "length", argType = TBasicType TInt64, direction = DirectionIn, mayBeNull = False, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, transfer = TransferNothing},Arg {argName = "password", argType = TBasicType TUTF8, direction = DirectionIn, mayBeNull = True, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, transfer = TransferNothing},Arg {argName = "cancellable", argType = TInterface "Gio" "Cancellable", direction = DirectionIn, mayBeNull = True, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, transfer = TransferNothing}]
-- Lengths : []
-- hInArgs : [Arg {argName = "stream", argType = TInterface "Gio" "InputStream", direction = DirectionIn, mayBeNull = False, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, transfer = TransferNothing},Arg {argName = "length", argType = TBasicType TInt64, direction = DirectionIn, mayBeNull = False, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, transfer = TransferNothing},Arg {argName = "password", argType = TBasicType TUTF8, direction = DirectionIn, mayBeNull = True, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, transfer = TransferNothing},Arg {argName = "cancellable", argType = TInterface "Gio" "Cancellable", direction = DirectionIn, mayBeNull = True, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, transfer = TransferNothing}]
-- returnType : TInterface "Poppler" "Document"
-- throws : True
-- Skip return : False

foreign import ccall "poppler_document_new_from_stream" poppler_document_new_from_stream :: 
    Ptr Gio.InputStream ->                  -- stream : TInterface "Gio" "InputStream"
    Int64 ->                                -- length : TBasicType TInt64
    CString ->                              -- password : TBasicType TUTF8
    Ptr Gio.Cancellable ->                  -- cancellable : TInterface "Gio" "Cancellable"
    Ptr (Ptr GError) ->                     -- error
    IO (Ptr Document)


documentNewFromStream ::
    (MonadIO m, Gio.InputStreamK a, Gio.CancellableK b) =>
    a ->                                    -- stream
    Int64 ->                                -- length
    Maybe (T.Text) ->                       -- password
    Maybe (b) ->                            -- cancellable
    m Document
documentNewFromStream stream length_ password cancellable = liftIO $ do
    let stream' = unsafeManagedPtrCastPtr stream
    maybePassword <- case password of
        Nothing -> return nullPtr
        Just jPassword -> do
            jPassword' <- textToCString jPassword
            return jPassword'
    maybeCancellable <- case cancellable of
        Nothing -> return nullPtr
        Just jCancellable -> do
            let jCancellable' = unsafeManagedPtrCastPtr jCancellable
            return jCancellable'
    onException (do
        result <- propagateGError $ poppler_document_new_from_stream stream' length_ maybePassword maybeCancellable
        checkUnexpectedReturnNULL "poppler_document_new_from_stream" result
        result' <- (wrapObject Document) result
        touchManagedPtr stream
        whenJust cancellable touchManagedPtr
        freeMem maybePassword
        return result'
     ) (do
        freeMem maybePassword
     )

-- method Document::find_dest
-- method type : OrdinaryMethod
-- Args : [Arg {argName = "_obj", argType = TInterface "Poppler" "Document", direction = DirectionIn, mayBeNull = False, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, transfer = TransferNothing},Arg {argName = "link_name", argType = TBasicType TUTF8, direction = DirectionIn, mayBeNull = False, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, transfer = TransferNothing}]
-- Lengths : []
-- hInArgs : [Arg {argName = "_obj", argType = TInterface "Poppler" "Document", direction = DirectionIn, mayBeNull = False, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, transfer = TransferNothing},Arg {argName = "link_name", argType = TBasicType TUTF8, direction = DirectionIn, mayBeNull = False, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, transfer = TransferNothing}]
-- returnType : TInterface "Poppler" "Dest"
-- throws : False
-- Skip return : False

foreign import ccall "poppler_document_find_dest" poppler_document_find_dest :: 
    Ptr Document ->                         -- _obj : TInterface "Poppler" "Document"
    CString ->                              -- link_name : TBasicType TUTF8
    IO (Ptr Dest)


documentFindDest ::
    (MonadIO m, DocumentK a) =>
    a ->                                    -- _obj
    T.Text ->                               -- link_name
    m Dest
documentFindDest _obj link_name = liftIO $ do
    let _obj' = unsafeManagedPtrCastPtr _obj
    link_name' <- textToCString link_name
    result <- poppler_document_find_dest _obj' link_name'
    checkUnexpectedReturnNULL "poppler_document_find_dest" result
    result' <- (wrapBoxed Dest) result
    touchManagedPtr _obj
    freeMem link_name'
    return result'

-- method Document::get_attachments
-- method type : OrdinaryMethod
-- Args : [Arg {argName = "_obj", argType = TInterface "Poppler" "Document", direction = DirectionIn, mayBeNull = False, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, transfer = TransferNothing}]
-- Lengths : []
-- hInArgs : [Arg {argName = "_obj", argType = TInterface "Poppler" "Document", direction = DirectionIn, mayBeNull = False, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, transfer = TransferNothing}]
-- returnType : TGList (TInterface "Poppler" "Attachment")
-- throws : False
-- Skip return : False

foreign import ccall "poppler_document_get_attachments" poppler_document_get_attachments :: 
    Ptr Document ->                         -- _obj : TInterface "Poppler" "Document"
    IO (Ptr (GList (Ptr Attachment)))


documentGetAttachments ::
    (MonadIO m, DocumentK a) =>
    a ->                                    -- _obj
    m [Attachment]
documentGetAttachments _obj = liftIO $ do
    let _obj' = unsafeManagedPtrCastPtr _obj
    result <- poppler_document_get_attachments _obj'
    checkUnexpectedReturnNULL "poppler_document_get_attachments" result
    result' <- unpackGList result
    result'' <- mapM (wrapObject Attachment) result'
    g_list_free result
    touchManagedPtr _obj
    return result''

-- method Document::get_author
-- method type : OrdinaryMethod
-- Args : [Arg {argName = "_obj", argType = TInterface "Poppler" "Document", direction = DirectionIn, mayBeNull = False, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, transfer = TransferNothing}]
-- Lengths : []
-- hInArgs : [Arg {argName = "_obj", argType = TInterface "Poppler" "Document", direction = DirectionIn, mayBeNull = False, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, transfer = TransferNothing}]
-- returnType : TBasicType TUTF8
-- throws : False
-- Skip return : False

foreign import ccall "poppler_document_get_author" poppler_document_get_author :: 
    Ptr Document ->                         -- _obj : TInterface "Poppler" "Document"
    IO CString


documentGetAuthor ::
    (MonadIO m, DocumentK a) =>
    a ->                                    -- _obj
    m T.Text
documentGetAuthor _obj = liftIO $ do
    let _obj' = unsafeManagedPtrCastPtr _obj
    result <- poppler_document_get_author _obj'
    checkUnexpectedReturnNULL "poppler_document_get_author" result
    result' <- cstringToText result
    freeMem result
    touchManagedPtr _obj
    return result'

-- method Document::get_creation_date
-- method type : OrdinaryMethod
-- Args : [Arg {argName = "_obj", argType = TInterface "Poppler" "Document", direction = DirectionIn, mayBeNull = False, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, transfer = TransferNothing}]
-- Lengths : []
-- hInArgs : [Arg {argName = "_obj", argType = TInterface "Poppler" "Document", direction = DirectionIn, mayBeNull = False, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, transfer = TransferNothing}]
-- returnType : TBasicType TInt64
-- throws : False
-- Skip return : False

foreign import ccall "poppler_document_get_creation_date" poppler_document_get_creation_date :: 
    Ptr Document ->                         -- _obj : TInterface "Poppler" "Document"
    IO Int64


documentGetCreationDate ::
    (MonadIO m, DocumentK a) =>
    a ->                                    -- _obj
    m Int64
documentGetCreationDate _obj = liftIO $ do
    let _obj' = unsafeManagedPtrCastPtr _obj
    result <- poppler_document_get_creation_date _obj'
    touchManagedPtr _obj
    return result

-- method Document::get_creator
-- method type : OrdinaryMethod
-- Args : [Arg {argName = "_obj", argType = TInterface "Poppler" "Document", direction = DirectionIn, mayBeNull = False, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, transfer = TransferNothing}]
-- Lengths : []
-- hInArgs : [Arg {argName = "_obj", argType = TInterface "Poppler" "Document", direction = DirectionIn, mayBeNull = False, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, transfer = TransferNothing}]
-- returnType : TBasicType TUTF8
-- throws : False
-- Skip return : False

foreign import ccall "poppler_document_get_creator" poppler_document_get_creator :: 
    Ptr Document ->                         -- _obj : TInterface "Poppler" "Document"
    IO CString


documentGetCreator ::
    (MonadIO m, DocumentK a) =>
    a ->                                    -- _obj
    m T.Text
documentGetCreator _obj = liftIO $ do
    let _obj' = unsafeManagedPtrCastPtr _obj
    result <- poppler_document_get_creator _obj'
    checkUnexpectedReturnNULL "poppler_document_get_creator" result
    result' <- cstringToText result
    freeMem result
    touchManagedPtr _obj
    return result'

-- method Document::get_form_field
-- method type : OrdinaryMethod
-- Args : [Arg {argName = "_obj", argType = TInterface "Poppler" "Document", direction = DirectionIn, mayBeNull = False, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, transfer = TransferNothing},Arg {argName = "id", argType = TBasicType TInt32, direction = DirectionIn, mayBeNull = False, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, transfer = TransferNothing}]
-- Lengths : []
-- hInArgs : [Arg {argName = "_obj", argType = TInterface "Poppler" "Document", direction = DirectionIn, mayBeNull = False, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, transfer = TransferNothing},Arg {argName = "id", argType = TBasicType TInt32, direction = DirectionIn, mayBeNull = False, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, transfer = TransferNothing}]
-- returnType : TInterface "Poppler" "FormField"
-- throws : False
-- Skip return : False

foreign import ccall "poppler_document_get_form_field" poppler_document_get_form_field :: 
    Ptr Document ->                         -- _obj : TInterface "Poppler" "Document"
    Int32 ->                                -- id : TBasicType TInt32
    IO (Ptr FormField)


documentGetFormField ::
    (MonadIO m, DocumentK a) =>
    a ->                                    -- _obj
    Int32 ->                                -- id
    m FormField
documentGetFormField _obj id = liftIO $ do
    let _obj' = unsafeManagedPtrCastPtr _obj
    result <- poppler_document_get_form_field _obj' id
    checkUnexpectedReturnNULL "poppler_document_get_form_field" result
    result' <- (wrapObject FormField) result
    touchManagedPtr _obj
    return result'

-- method Document::get_id
-- method type : OrdinaryMethod
-- Args : [Arg {argName = "_obj", argType = TInterface "Poppler" "Document", direction = DirectionIn, mayBeNull = False, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, transfer = TransferNothing},Arg {argName = "permanent_id", argType = TBasicType TUTF8, direction = DirectionOut, mayBeNull = False, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, transfer = TransferEverything},Arg {argName = "update_id", argType = TBasicType TUTF8, direction = DirectionOut, mayBeNull = False, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, transfer = TransferEverything}]
-- Lengths : []
-- hInArgs : [Arg {argName = "_obj", argType = TInterface "Poppler" "Document", direction = DirectionIn, mayBeNull = False, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, transfer = TransferNothing}]
-- returnType : TBasicType TBoolean
-- throws : False
-- Skip return : False

foreign import ccall "poppler_document_get_id" poppler_document_get_id :: 
    Ptr Document ->                         -- _obj : TInterface "Poppler" "Document"
    Ptr CString ->                          -- permanent_id : TBasicType TUTF8
    Ptr CString ->                          -- update_id : TBasicType TUTF8
    IO CInt


documentGetId ::
    (MonadIO m, DocumentK a) =>
    a ->                                    -- _obj
    m (Bool,T.Text,T.Text)
documentGetId _obj = liftIO $ do
    let _obj' = unsafeManagedPtrCastPtr _obj
    permanent_id <- allocMem :: IO (Ptr CString)
    update_id <- allocMem :: IO (Ptr CString)
    result <- poppler_document_get_id _obj' permanent_id update_id
    let result' = (/= 0) result
    permanent_id' <- peek permanent_id
    permanent_id'' <- cstringToText permanent_id'
    freeMem permanent_id'
    update_id' <- peek update_id
    update_id'' <- cstringToText update_id'
    freeMem update_id'
    touchManagedPtr _obj
    freeMem permanent_id
    freeMem update_id
    return (result', permanent_id'', update_id'')

-- method Document::get_keywords
-- method type : OrdinaryMethod
-- Args : [Arg {argName = "_obj", argType = TInterface "Poppler" "Document", direction = DirectionIn, mayBeNull = False, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, transfer = TransferNothing}]
-- Lengths : []
-- hInArgs : [Arg {argName = "_obj", argType = TInterface "Poppler" "Document", direction = DirectionIn, mayBeNull = False, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, transfer = TransferNothing}]
-- returnType : TBasicType TUTF8
-- throws : False
-- Skip return : False

foreign import ccall "poppler_document_get_keywords" poppler_document_get_keywords :: 
    Ptr Document ->                         -- _obj : TInterface "Poppler" "Document"
    IO CString


documentGetKeywords ::
    (MonadIO m, DocumentK a) =>
    a ->                                    -- _obj
    m T.Text
documentGetKeywords _obj = liftIO $ do
    let _obj' = unsafeManagedPtrCastPtr _obj
    result <- poppler_document_get_keywords _obj'
    checkUnexpectedReturnNULL "poppler_document_get_keywords" result
    result' <- cstringToText result
    freeMem result
    touchManagedPtr _obj
    return result'

-- method Document::get_metadata
-- method type : OrdinaryMethod
-- Args : [Arg {argName = "_obj", argType = TInterface "Poppler" "Document", direction = DirectionIn, mayBeNull = False, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, transfer = TransferNothing}]
-- Lengths : []
-- hInArgs : [Arg {argName = "_obj", argType = TInterface "Poppler" "Document", direction = DirectionIn, mayBeNull = False, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, transfer = TransferNothing}]
-- returnType : TBasicType TUTF8
-- throws : False
-- Skip return : False

foreign import ccall "poppler_document_get_metadata" poppler_document_get_metadata :: 
    Ptr Document ->                         -- _obj : TInterface "Poppler" "Document"
    IO CString


documentGetMetadata ::
    (MonadIO m, DocumentK a) =>
    a ->                                    -- _obj
    m T.Text
documentGetMetadata _obj = liftIO $ do
    let _obj' = unsafeManagedPtrCastPtr _obj
    result <- poppler_document_get_metadata _obj'
    checkUnexpectedReturnNULL "poppler_document_get_metadata" result
    result' <- cstringToText result
    freeMem result
    touchManagedPtr _obj
    return result'

-- method Document::get_modification_date
-- method type : OrdinaryMethod
-- Args : [Arg {argName = "_obj", argType = TInterface "Poppler" "Document", direction = DirectionIn, mayBeNull = False, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, transfer = TransferNothing}]
-- Lengths : []
-- hInArgs : [Arg {argName = "_obj", argType = TInterface "Poppler" "Document", direction = DirectionIn, mayBeNull = False, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, transfer = TransferNothing}]
-- returnType : TBasicType TInt64
-- throws : False
-- Skip return : False

foreign import ccall "poppler_document_get_modification_date" poppler_document_get_modification_date :: 
    Ptr Document ->                         -- _obj : TInterface "Poppler" "Document"
    IO Int64


documentGetModificationDate ::
    (MonadIO m, DocumentK a) =>
    a ->                                    -- _obj
    m Int64
documentGetModificationDate _obj = liftIO $ do
    let _obj' = unsafeManagedPtrCastPtr _obj
    result <- poppler_document_get_modification_date _obj'
    touchManagedPtr _obj
    return result

-- method Document::get_n_attachments
-- method type : OrdinaryMethod
-- Args : [Arg {argName = "_obj", argType = TInterface "Poppler" "Document", direction = DirectionIn, mayBeNull = False, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, transfer = TransferNothing}]
-- Lengths : []
-- hInArgs : [Arg {argName = "_obj", argType = TInterface "Poppler" "Document", direction = DirectionIn, mayBeNull = False, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, transfer = TransferNothing}]
-- returnType : TBasicType TUInt32
-- throws : False
-- Skip return : False

foreign import ccall "poppler_document_get_n_attachments" poppler_document_get_n_attachments :: 
    Ptr Document ->                         -- _obj : TInterface "Poppler" "Document"
    IO Word32


documentGetNAttachments ::
    (MonadIO m, DocumentK a) =>
    a ->                                    -- _obj
    m Word32
documentGetNAttachments _obj = liftIO $ do
    let _obj' = unsafeManagedPtrCastPtr _obj
    result <- poppler_document_get_n_attachments _obj'
    touchManagedPtr _obj
    return result

-- method Document::get_n_pages
-- method type : OrdinaryMethod
-- Args : [Arg {argName = "_obj", argType = TInterface "Poppler" "Document", direction = DirectionIn, mayBeNull = False, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, transfer = TransferNothing}]
-- Lengths : []
-- hInArgs : [Arg {argName = "_obj", argType = TInterface "Poppler" "Document", direction = DirectionIn, mayBeNull = False, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, transfer = TransferNothing}]
-- returnType : TBasicType TInt32
-- throws : False
-- Skip return : False

foreign import ccall "poppler_document_get_n_pages" poppler_document_get_n_pages :: 
    Ptr Document ->                         -- _obj : TInterface "Poppler" "Document"
    IO Int32


documentGetNPages ::
    (MonadIO m, DocumentK a) =>
    a ->                                    -- _obj
    m Int32
documentGetNPages _obj = liftIO $ do
    let _obj' = unsafeManagedPtrCastPtr _obj
    result <- poppler_document_get_n_pages _obj'
    touchManagedPtr _obj
    return result

-- method Document::get_page
-- method type : OrdinaryMethod
-- Args : [Arg {argName = "_obj", argType = TInterface "Poppler" "Document", direction = DirectionIn, mayBeNull = False, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, transfer = TransferNothing},Arg {argName = "index", argType = TBasicType TInt32, direction = DirectionIn, mayBeNull = False, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, transfer = TransferNothing}]
-- Lengths : []
-- hInArgs : [Arg {argName = "_obj", argType = TInterface "Poppler" "Document", direction = DirectionIn, mayBeNull = False, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, transfer = TransferNothing},Arg {argName = "index", argType = TBasicType TInt32, direction = DirectionIn, mayBeNull = False, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, transfer = TransferNothing}]
-- returnType : TInterface "Poppler" "Page"
-- throws : False
-- Skip return : False

foreign import ccall "poppler_document_get_page" poppler_document_get_page :: 
    Ptr Document ->                         -- _obj : TInterface "Poppler" "Document"
    Int32 ->                                -- index : TBasicType TInt32
    IO (Ptr Page)


documentGetPage ::
    (MonadIO m, DocumentK a) =>
    a ->                                    -- _obj
    Int32 ->                                -- index
    m Page
documentGetPage _obj index = liftIO $ do
    let _obj' = unsafeManagedPtrCastPtr _obj
    result <- poppler_document_get_page _obj' index
    checkUnexpectedReturnNULL "poppler_document_get_page" result
    result' <- (wrapObject Page) result
    touchManagedPtr _obj
    return result'

-- method Document::get_page_by_label
-- method type : OrdinaryMethod
-- Args : [Arg {argName = "_obj", argType = TInterface "Poppler" "Document", direction = DirectionIn, mayBeNull = False, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, transfer = TransferNothing},Arg {argName = "label", argType = TBasicType TUTF8, direction = DirectionIn, mayBeNull = False, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, transfer = TransferNothing}]
-- Lengths : []
-- hInArgs : [Arg {argName = "_obj", argType = TInterface "Poppler" "Document", direction = DirectionIn, mayBeNull = False, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, transfer = TransferNothing},Arg {argName = "label", argType = TBasicType TUTF8, direction = DirectionIn, mayBeNull = False, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, transfer = TransferNothing}]
-- returnType : TInterface "Poppler" "Page"
-- throws : False
-- Skip return : False

foreign import ccall "poppler_document_get_page_by_label" poppler_document_get_page_by_label :: 
    Ptr Document ->                         -- _obj : TInterface "Poppler" "Document"
    CString ->                              -- label : TBasicType TUTF8
    IO (Ptr Page)


documentGetPageByLabel ::
    (MonadIO m, DocumentK a) =>
    a ->                                    -- _obj
    T.Text ->                               -- label
    m Page
documentGetPageByLabel _obj label = liftIO $ do
    let _obj' = unsafeManagedPtrCastPtr _obj
    label' <- textToCString label
    result <- poppler_document_get_page_by_label _obj' label'
    checkUnexpectedReturnNULL "poppler_document_get_page_by_label" result
    result' <- (wrapObject Page) result
    touchManagedPtr _obj
    freeMem label'
    return result'

-- method Document::get_page_layout
-- method type : OrdinaryMethod
-- Args : [Arg {argName = "_obj", argType = TInterface "Poppler" "Document", direction = DirectionIn, mayBeNull = False, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, transfer = TransferNothing}]
-- Lengths : []
-- hInArgs : [Arg {argName = "_obj", argType = TInterface "Poppler" "Document", direction = DirectionIn, mayBeNull = False, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, transfer = TransferNothing}]
-- returnType : TInterface "Poppler" "PageLayout"
-- throws : False
-- Skip return : False

foreign import ccall "poppler_document_get_page_layout" poppler_document_get_page_layout :: 
    Ptr Document ->                         -- _obj : TInterface "Poppler" "Document"
    IO CUInt


documentGetPageLayout ::
    (MonadIO m, DocumentK a) =>
    a ->                                    -- _obj
    m PageLayout
documentGetPageLayout _obj = liftIO $ do
    let _obj' = unsafeManagedPtrCastPtr _obj
    result <- poppler_document_get_page_layout _obj'
    let result' = (toEnum . fromIntegral) result
    touchManagedPtr _obj
    return result'

-- method Document::get_page_mode
-- method type : OrdinaryMethod
-- Args : [Arg {argName = "_obj", argType = TInterface "Poppler" "Document", direction = DirectionIn, mayBeNull = False, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, transfer = TransferNothing}]
-- Lengths : []
-- hInArgs : [Arg {argName = "_obj", argType = TInterface "Poppler" "Document", direction = DirectionIn, mayBeNull = False, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, transfer = TransferNothing}]
-- returnType : TInterface "Poppler" "PageMode"
-- throws : False
-- Skip return : False

foreign import ccall "poppler_document_get_page_mode" poppler_document_get_page_mode :: 
    Ptr Document ->                         -- _obj : TInterface "Poppler" "Document"
    IO CUInt


documentGetPageMode ::
    (MonadIO m, DocumentK a) =>
    a ->                                    -- _obj
    m PageMode
documentGetPageMode _obj = liftIO $ do
    let _obj' = unsafeManagedPtrCastPtr _obj
    result <- poppler_document_get_page_mode _obj'
    let result' = (toEnum . fromIntegral) result
    touchManagedPtr _obj
    return result'

-- method Document::get_pdf_version
-- method type : OrdinaryMethod
-- Args : [Arg {argName = "_obj", argType = TInterface "Poppler" "Document", direction = DirectionIn, mayBeNull = False, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, transfer = TransferNothing},Arg {argName = "major_version", argType = TBasicType TUInt32, direction = DirectionOut, mayBeNull = False, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, transfer = TransferEverything},Arg {argName = "minor_version", argType = TBasicType TUInt32, direction = DirectionOut, mayBeNull = False, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, transfer = TransferEverything}]
-- Lengths : []
-- hInArgs : [Arg {argName = "_obj", argType = TInterface "Poppler" "Document", direction = DirectionIn, mayBeNull = False, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, transfer = TransferNothing}]
-- returnType : TBasicType TVoid
-- throws : False
-- Skip return : False

foreign import ccall "poppler_document_get_pdf_version" poppler_document_get_pdf_version :: 
    Ptr Document ->                         -- _obj : TInterface "Poppler" "Document"
    Ptr Word32 ->                           -- major_version : TBasicType TUInt32
    Ptr Word32 ->                           -- minor_version : TBasicType TUInt32
    IO ()


documentGetPdfVersion ::
    (MonadIO m, DocumentK a) =>
    a ->                                    -- _obj
    m (Word32,Word32)
documentGetPdfVersion _obj = liftIO $ do
    let _obj' = unsafeManagedPtrCastPtr _obj
    major_version <- allocMem :: IO (Ptr Word32)
    minor_version <- allocMem :: IO (Ptr Word32)
    poppler_document_get_pdf_version _obj' major_version minor_version
    major_version' <- peek major_version
    minor_version' <- peek minor_version
    touchManagedPtr _obj
    freeMem major_version
    freeMem minor_version
    return (major_version', minor_version')

-- method Document::get_pdf_version_string
-- method type : OrdinaryMethod
-- Args : [Arg {argName = "_obj", argType = TInterface "Poppler" "Document", direction = DirectionIn, mayBeNull = False, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, transfer = TransferNothing}]
-- Lengths : []
-- hInArgs : [Arg {argName = "_obj", argType = TInterface "Poppler" "Document", direction = DirectionIn, mayBeNull = False, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, transfer = TransferNothing}]
-- returnType : TBasicType TUTF8
-- throws : False
-- Skip return : False

foreign import ccall "poppler_document_get_pdf_version_string" poppler_document_get_pdf_version_string :: 
    Ptr Document ->                         -- _obj : TInterface "Poppler" "Document"
    IO CString


documentGetPdfVersionString ::
    (MonadIO m, DocumentK a) =>
    a ->                                    -- _obj
    m T.Text
documentGetPdfVersionString _obj = liftIO $ do
    let _obj' = unsafeManagedPtrCastPtr _obj
    result <- poppler_document_get_pdf_version_string _obj'
    checkUnexpectedReturnNULL "poppler_document_get_pdf_version_string" result
    result' <- cstringToText result
    freeMem result
    touchManagedPtr _obj
    return result'

-- method Document::get_permissions
-- method type : OrdinaryMethod
-- Args : [Arg {argName = "_obj", argType = TInterface "Poppler" "Document", direction = DirectionIn, mayBeNull = False, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, transfer = TransferNothing}]
-- Lengths : []
-- hInArgs : [Arg {argName = "_obj", argType = TInterface "Poppler" "Document", direction = DirectionIn, mayBeNull = False, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, transfer = TransferNothing}]
-- returnType : TInterface "Poppler" "Permissions"
-- throws : False
-- Skip return : False

foreign import ccall "poppler_document_get_permissions" poppler_document_get_permissions :: 
    Ptr Document ->                         -- _obj : TInterface "Poppler" "Document"
    IO CUInt


documentGetPermissions ::
    (MonadIO m, DocumentK a) =>
    a ->                                    -- _obj
    m [Permissions]
documentGetPermissions _obj = liftIO $ do
    let _obj' = unsafeManagedPtrCastPtr _obj
    result <- poppler_document_get_permissions _obj'
    let result' = wordToGFlags result
    touchManagedPtr _obj
    return result'

-- method Document::get_producer
-- method type : OrdinaryMethod
-- Args : [Arg {argName = "_obj", argType = TInterface "Poppler" "Document", direction = DirectionIn, mayBeNull = False, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, transfer = TransferNothing}]
-- Lengths : []
-- hInArgs : [Arg {argName = "_obj", argType = TInterface "Poppler" "Document", direction = DirectionIn, mayBeNull = False, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, transfer = TransferNothing}]
-- returnType : TBasicType TUTF8
-- throws : False
-- Skip return : False

foreign import ccall "poppler_document_get_producer" poppler_document_get_producer :: 
    Ptr Document ->                         -- _obj : TInterface "Poppler" "Document"
    IO CString


documentGetProducer ::
    (MonadIO m, DocumentK a) =>
    a ->                                    -- _obj
    m T.Text
documentGetProducer _obj = liftIO $ do
    let _obj' = unsafeManagedPtrCastPtr _obj
    result <- poppler_document_get_producer _obj'
    checkUnexpectedReturnNULL "poppler_document_get_producer" result
    result' <- cstringToText result
    freeMem result
    touchManagedPtr _obj
    return result'

-- method Document::get_subject
-- method type : OrdinaryMethod
-- Args : [Arg {argName = "_obj", argType = TInterface "Poppler" "Document", direction = DirectionIn, mayBeNull = False, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, transfer = TransferNothing}]
-- Lengths : []
-- hInArgs : [Arg {argName = "_obj", argType = TInterface "Poppler" "Document", direction = DirectionIn, mayBeNull = False, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, transfer = TransferNothing}]
-- returnType : TBasicType TUTF8
-- throws : False
-- Skip return : False

foreign import ccall "poppler_document_get_subject" poppler_document_get_subject :: 
    Ptr Document ->                         -- _obj : TInterface "Poppler" "Document"
    IO CString


documentGetSubject ::
    (MonadIO m, DocumentK a) =>
    a ->                                    -- _obj
    m T.Text
documentGetSubject _obj = liftIO $ do
    let _obj' = unsafeManagedPtrCastPtr _obj
    result <- poppler_document_get_subject _obj'
    checkUnexpectedReturnNULL "poppler_document_get_subject" result
    result' <- cstringToText result
    freeMem result
    touchManagedPtr _obj
    return result'

-- method Document::get_title
-- method type : OrdinaryMethod
-- Args : [Arg {argName = "_obj", argType = TInterface "Poppler" "Document", direction = DirectionIn, mayBeNull = False, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, transfer = TransferNothing}]
-- Lengths : []
-- hInArgs : [Arg {argName = "_obj", argType = TInterface "Poppler" "Document", direction = DirectionIn, mayBeNull = False, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, transfer = TransferNothing}]
-- returnType : TBasicType TUTF8
-- throws : False
-- Skip return : False

foreign import ccall "poppler_document_get_title" poppler_document_get_title :: 
    Ptr Document ->                         -- _obj : TInterface "Poppler" "Document"
    IO CString


documentGetTitle ::
    (MonadIO m, DocumentK a) =>
    a ->                                    -- _obj
    m T.Text
documentGetTitle _obj = liftIO $ do
    let _obj' = unsafeManagedPtrCastPtr _obj
    result <- poppler_document_get_title _obj'
    checkUnexpectedReturnNULL "poppler_document_get_title" result
    result' <- cstringToText result
    freeMem result
    touchManagedPtr _obj
    return result'

-- method Document::has_attachments
-- method type : OrdinaryMethod
-- Args : [Arg {argName = "_obj", argType = TInterface "Poppler" "Document", direction = DirectionIn, mayBeNull = False, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, transfer = TransferNothing}]
-- Lengths : []
-- hInArgs : [Arg {argName = "_obj", argType = TInterface "Poppler" "Document", direction = DirectionIn, mayBeNull = False, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, transfer = TransferNothing}]
-- returnType : TBasicType TBoolean
-- throws : False
-- Skip return : False

foreign import ccall "poppler_document_has_attachments" poppler_document_has_attachments :: 
    Ptr Document ->                         -- _obj : TInterface "Poppler" "Document"
    IO CInt


documentHasAttachments ::
    (MonadIO m, DocumentK a) =>
    a ->                                    -- _obj
    m Bool
documentHasAttachments _obj = liftIO $ do
    let _obj' = unsafeManagedPtrCastPtr _obj
    result <- poppler_document_has_attachments _obj'
    let result' = (/= 0) result
    touchManagedPtr _obj
    return result'

-- method Document::is_linearized
-- method type : OrdinaryMethod
-- Args : [Arg {argName = "_obj", argType = TInterface "Poppler" "Document", direction = DirectionIn, mayBeNull = False, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, transfer = TransferNothing}]
-- Lengths : []
-- hInArgs : [Arg {argName = "_obj", argType = TInterface "Poppler" "Document", direction = DirectionIn, mayBeNull = False, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, transfer = TransferNothing}]
-- returnType : TBasicType TBoolean
-- throws : False
-- Skip return : False

foreign import ccall "poppler_document_is_linearized" poppler_document_is_linearized :: 
    Ptr Document ->                         -- _obj : TInterface "Poppler" "Document"
    IO CInt


documentIsLinearized ::
    (MonadIO m, DocumentK a) =>
    a ->                                    -- _obj
    m Bool
documentIsLinearized _obj = liftIO $ do
    let _obj' = unsafeManagedPtrCastPtr _obj
    result <- poppler_document_is_linearized _obj'
    let result' = (/= 0) result
    touchManagedPtr _obj
    return result'

-- method Document::save
-- method type : OrdinaryMethod
-- Args : [Arg {argName = "_obj", argType = TInterface "Poppler" "Document", direction = DirectionIn, mayBeNull = False, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, transfer = TransferNothing},Arg {argName = "uri", argType = TBasicType TUTF8, direction = DirectionIn, mayBeNull = False, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, transfer = TransferNothing}]
-- Lengths : []
-- hInArgs : [Arg {argName = "_obj", argType = TInterface "Poppler" "Document", direction = DirectionIn, mayBeNull = False, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, transfer = TransferNothing},Arg {argName = "uri", argType = TBasicType TUTF8, direction = DirectionIn, mayBeNull = False, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, transfer = TransferNothing}]
-- returnType : TBasicType TBoolean
-- throws : True
-- Skip return : False

foreign import ccall "poppler_document_save" poppler_document_save :: 
    Ptr Document ->                         -- _obj : TInterface "Poppler" "Document"
    CString ->                              -- uri : TBasicType TUTF8
    Ptr (Ptr GError) ->                     -- error
    IO CInt


documentSave ::
    (MonadIO m, DocumentK a) =>
    a ->                                    -- _obj
    T.Text ->                               -- uri
    m ()
documentSave _obj uri = liftIO $ do
    let _obj' = unsafeManagedPtrCastPtr _obj
    uri' <- textToCString uri
    onException (do
        _ <- propagateGError $ poppler_document_save _obj' uri'
        touchManagedPtr _obj
        freeMem uri'
        return ()
     ) (do
        freeMem uri'
     )

-- method Document::save_a_copy
-- method type : OrdinaryMethod
-- Args : [Arg {argName = "_obj", argType = TInterface "Poppler" "Document", direction = DirectionIn, mayBeNull = False, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, transfer = TransferNothing},Arg {argName = "uri", argType = TBasicType TUTF8, direction = DirectionIn, mayBeNull = False, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, transfer = TransferNothing}]
-- Lengths : []
-- hInArgs : [Arg {argName = "_obj", argType = TInterface "Poppler" "Document", direction = DirectionIn, mayBeNull = False, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, transfer = TransferNothing},Arg {argName = "uri", argType = TBasicType TUTF8, direction = DirectionIn, mayBeNull = False, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, transfer = TransferNothing}]
-- returnType : TBasicType TBoolean
-- throws : True
-- Skip return : False

foreign import ccall "poppler_document_save_a_copy" poppler_document_save_a_copy :: 
    Ptr Document ->                         -- _obj : TInterface "Poppler" "Document"
    CString ->                              -- uri : TBasicType TUTF8
    Ptr (Ptr GError) ->                     -- error
    IO CInt


documentSaveACopy ::
    (MonadIO m, DocumentK a) =>
    a ->                                    -- _obj
    T.Text ->                               -- uri
    m ()
documentSaveACopy _obj uri = liftIO $ do
    let _obj' = unsafeManagedPtrCastPtr _obj
    uri' <- textToCString uri
    onException (do
        _ <- propagateGError $ poppler_document_save_a_copy _obj' uri'
        touchManagedPtr _obj
        freeMem uri'
        return ()
     ) (do
        freeMem uri'
     )