leaf_focus/pdf/text/component.py
def create(self, pdf_path: Path, text_path: Path) -> None:
        """Extract the text from a pdf to a text file."""

        if not pdf_path:
            raise ValueError("Must supply pdf file.")
        if not text_path:
            raise ValueError("Must supply text file.")
        if not pdf_path.exists():
            raise FileNotFoundError(f"Pdf file does not exist '{pdf_path}'.")

        if text_path.exists():
            self._logger.debug(f"Pdf text file already exists for '{pdf_path}'.")
            return

        if not text_path.parent.exists():
            text_path.parent.mkdir(exist_ok=True, parents=True)

        # uses -table instead of -layout because there are a few tables
        # the -table setting preserves the table structure better than -layout
        commands = [
            str(self._exe_file),
            "-table",
            "-enc",
            "UTF-8",
            "-eol",
            "dos",
            str(pdf_path),
            str(text_path),
        ]

        self._logger.info(f"Creating pdf text for '{pdf_path}'.")

        result = subprocess.run(commands, capture_output=True, check=True)

        if result.returncode != 0:
            self._logger.error(f"Could not create pdf text: {repr(result)}")
            raise ValueError(result)
Extract the text from a pdf to a text file.
Extract the text from a pdf to a text file.
Extract the text from a pdf to a text file .
def create(self, pdf_path: Path, text_path: Path) -> None:
        if not pdf_path:
            raise ValueError("Must supply pdf file.")
        if not text_path:
            raise ValueError("Must supply text file.")
        if not pdf_path.exists():
            raise FileNotFoundError(f"Pdf file does not exist '{pdf_path}'.")
        if text_path.exists():
            self._logger.debug(f"Pdf text file already exists for '{pdf_path}'.")
            return
        if not text_path.parent.exists():
            text_path.parent.mkdir(exist_ok=True, parents=True)
        commands = [
            str(self._exe_file),
            "-table",
            "-enc",
            "UTF-8",
            "-eol",
            "dos",
            str(pdf_path),
            str(text_path),
        ]
        self._logger.info(f"Creating pdf text for '{pdf_path}'.")
        result = subprocess.run(commands, capture_output=True, check=True)
        if result.returncode != 0:
            self._logger.error(f"Could not create pdf text: {repr(result)}")
            raise ValueError(result)
def create ( self , pdf_path : Path , text_path : Path ) -> None : if not pdf_path : raise ValueError ( "Must supply pdf file." ) if not text_path : raise ValueError ( "Must supply text file." ) if not pdf_path . exists ( ) : raise FileNotFoundError ( f"Pdf file does not exist '{pdf_path}'." ) if text_path . exists ( ) : self . _logger . debug ( f"Pdf text file already exists for '{pdf_path}'." ) return if not text_path . parent . exists ( ) : text_path . parent . mkdir ( exist_ok = True , parents = True ) commands = [ str ( self . _exe_file ) , "-table" , "-enc" , "UTF-8" , "-eol" , "dos" , str ( pdf_path ) , str ( text_path ) , ] self . _logger . info ( f"Creating pdf text for '{pdf_path}'." ) result = subprocess . run ( commands , capture_output = True , check = True ) if result . returncode != 0 : self . _logger . error ( f"Could not create pdf text: {repr(result)}" ) raise ValueError ( result )
Extract the text from a pdf to a text file.
Extract the text from a pdf to a text file .
"""Extract the text from a pdf to a text file.""" # uses -table instead of -layout because there are a few tables # the -table setting preserves the table structure better than -layout
self
pdf_path
Path
text_path
Path