packages feed

pdftotext 0.1.0.0 → 0.1.0.1

raw patch · 3 files changed

+36/−28 lines, 3 filesPVP: major bump suggested

API removals or changes: PVP suggests a major version bump

API changes (from Hackage documentation)

+ Pdftotext.Internal: [pageDocumentPtr] :: Page -> ForeignPtr Poppler_Document
- Pdftotext.Internal: Page :: Int -> Int -> ForeignPtr Poppler_Page -> Page
+ Pdftotext.Internal: Page :: Int -> Int -> ForeignPtr Poppler_Document -> ForeignPtr Poppler_Page -> Page

Files

CHANGELOG.md view
@@ -1,5 +1,10 @@ # Revision history for pdftotext +## 0.1.0.1 -- 2020-12-01++* Require C++11 (solves [#3](https://todo.sr.ht/~geyaeb/haskell-pdftotext/3), using on MacOS)+* Prevent deletion of document pointer before its pages (solves [#4](https://todo.sr.ht/~geyaeb/haskell-pdftotext/4), segmentation faults)+ ## 0.1.0.0 -- 2020-06-18  * Added executable `pdftotext.hs`
pdftotext.cabal view
@@ -1,7 +1,7 @@ cabal-version:       >=1.10  name:                pdftotext-version:             0.1.0.0+version:             0.1.0.1 synopsis:            Extracts text from PDF using poppler description:         The @pdftotext@ package provides functions for extraction of plain text from PDF documents. It uses C++ library [Poppler](https://poppler.freedesktop.org/), which is required to be installed in the system. Output of Haskell @pdftotext@ library is identical to output of Poppler's tool @pdftotext@. homepage:            https://sr.ht/~geyaeb/haskell-pdftotext/@@ -29,7 +29,7 @@   hs-source-dirs:      src   ghc-options:         -Wall -Wincomplete-uni-patterns -Wincomplete-record-updates -Wcompat -Widentities -Wredundant-constraints -fhide-source-paths -Wmissing-export-lists -Wpartial-fields   default-language:    Haskell2010-  cc-options:          -Wall -fPIC+  cc-options:          -Wall -fPIC -std=c++11   c-sources:           cbits/poppler.cc                      , cbits/stdstring.cc   extra-libraries:     stdc++
src/Pdftotext/Internal.hs view
@@ -66,11 +66,14 @@     pageNumber :: Int,     -- | Total number of pages in original document.     pageOutOf :: Int,+    -- | Pointer to document which created this page.+    pageDocumentPtr :: ForeignPtr Poppler_Document,+    -- | Pointer to this page.     pagePtr :: ForeignPtr Poppler_Page   }  instance Show Page where-  show (Page n o _) = "Page " ++ show n ++ "/" ++ show o+  show (Page n o _ _) = "Page " ++ show n ++ "/" ++ show o  -- | Layout of text extracted from PDF. data Layout@@ -90,46 +93,46 @@ openFile :: FilePath -> IO (Maybe Document) openFile file =   withCString file \cfile -> do-    docptr <- ffiOpenPdf cfile-    if docptr == nullPtr+    ptr <- ffiOpenPdf cfile+    if ptr == nullPtr       then return Nothing-      else Just . Document <$> newForeignPtr ffiDocumentDelete docptr+      else Just . Document <$> newForeignPtr ffiDocumentDelete ptr  -- | Open PDF represented as bytestring. If document cannot be parsed as valid PDF, -- `Nothing` is returned. openByteStringIO :: ByteString -> IO (Maybe Document)-openByteStringIO (PS ptr _ len) =-  withForeignPtr ptr \d -> do-    docptr <- ffiOpenData d (fromIntegral len)+openByteStringIO (PS bsfptr _ len) =+  withForeignPtr bsfptr \bsptr -> do+    docptr <- ffiOpenData bsptr (fromIntegral len)     if docptr == nullPtr       then return Nothing       else Just . Document <$> newForeignPtr ffiDocumentDelete docptr  -- | Return all pages from document. pagesIO :: Document -> IO [Page]-pagesIO (Document doc) = do-  withForeignPtr doc \docptr -> do-    pageno <- ffiDocumentPages docptr+pagesIO (Document fptr) = do+  withForeignPtr fptr \ptr -> do+    pageno <- ffiDocumentPages ptr     forM [0 .. pageno - 1] \pno -> do-      p <- ffiDocumentOpenPage docptr pno >>= newForeignPtr ffiPageDelete-      return $ Page (fromIntegral pno + 1) (fromIntegral pageno) p+      p <- ffiDocumentOpenPage ptr pno >>= newForeignPtr ffiPageDelete+      return $ Page (fromIntegral pno + 1) (fromIntegral pageno) fptr p  -- | Return page number 'no' from PDF document, if the page exists. pageIO :: Int -> Document -> IO (Maybe Page)-pageIO no d@(Document docptr) = withForeignPtr docptr \ptr -> do-  pno <- pagesTotalIO d+pageIO no doc@(Document fptr) = withForeignPtr fptr \ptr -> do+  pno <- pagesTotalIO doc   if no > 0 && no <= pno-    then Just . Page no pno <$> (ffiDocumentOpenPage ptr (fromIntegral no - 1) >>= newForeignPtr ffiPageDelete)+    then Just . Page no pno fptr <$> (ffiDocumentOpenPage ptr (fromIntegral no - 1) >>= newForeignPtr ffiPageDelete)     else return Nothing  -- | Return number of pages contained in document. pagesTotalIO :: Document -> IO Int-pagesTotalIO (Document doc) =-  fromIntegral <$> withForeignPtr doc ffiDocumentPages+pagesTotalIO (Document fptr) =+  fromIntegral <$> withForeignPtr fptr ffiDocumentPages  -- | Extract text from a page with given 'Layout'. pageTextIO :: Layout -> Page -> IO T.Text-pageTextIO layout (Page _ _ ptr) = withForeignPtr ptr \p -> asText (ffiPageText p l)+pageTextIO layout (Page _ _ _ fptr) = withForeignPtr fptr \ptr -> asText (ffiPageText ptr l)   where     l =       case layout of@@ -141,14 +144,14 @@ -- -- @since 0.0.2.0 propertiesIO :: Document -> IO Properties-propertiesIO (Document docptr) = withForeignPtr docptr \doc -> do-  a <- asText $ ffiDocumentAuthor doc-  c <- asText $ ffiDocumentCreator doc-  k <- asText $ ffiDocumentKeywords doc-  m <- asText $ ffiDocumentMetadata doc-  p <- asText $ ffiDocumentProducer doc-  s <- asText $ ffiDocumentSubject doc-  t <- asText $ ffiDocumentTitle doc+propertiesIO (Document fptr) = withForeignPtr fptr \ptr -> do+  a <- asText $ ffiDocumentAuthor ptr+  c <- asText $ ffiDocumentCreator ptr+  k <- asText $ ffiDocumentKeywords ptr+  m <- asText $ ffiDocumentMetadata ptr+  p <- asText $ ffiDocumentProducer ptr+  s <- asText $ ffiDocumentSubject ptr+  t <- asText $ ffiDocumentTitle ptr   return $ Properties (f a) (f c) (f k) (f m) (f p) (f s) (f t)   where     f x =