Package: endi-split-pdf
Split a large pdf file into several pieces.LicenceThis is a free software (GPLv3), see LICENCE.txt for licencing info.What does it doProvide a PDF file with all the salary sheets (or other type). In each page, you
provide an ancode and a name (“name” of the employee and a specific key called
“ancode”).  This program splits the pdf into separated salary sheets.It allows the people in charge of the salary sheet distribution to generate a
file from their accounting software and to get an output with a structured
directory structure.enDI matches that directory structure to distribute the salary sheets through
its interface.By extension, it’s possible to configure splitting for several type of data.HowThe original file is named <filetype>_<year>_<month>.pdf (e.g :
salaire_2020_11.pdf).The filetype is used to fetch the appropriate parsing configuration.The generated pdfs are placed under a directory named
<filetype>/<year>/<month>/.Using the configuration the tool searches for an “ancode” and a “name”
into the pdf pages. It generates files in the form <ancode>_<name>.pdf
containing the pages with the associated keywords, into the appropriate
directory.InstallationDistro dependenciesInstall the pdftotext command line tool.Debian based distrosapt-get install poppler-utils virtualenvwrapperInstall from pypimkvirtualenv splitpdf
pip install endi-split-pdfInstall from sourceSetup a python virtual environmentmkvirtualenv splitpdf
pip install -r requirements.txt
pip install -eDevelopment modepip install -e .[dev]ConfigurationMain config fileDefaults to~/.endi_split_pdf_config.yamlSpecifiable by use -c <configfile>Format is yaml.Configure :FiletypesFor each filetype, a parsing strategy describing the datatype to extract,
the way they are extracted and the name of the file to generate. (Several
parser can be provided, here we have three parsers for ancode and two for
name)Examplesalaire:filename_template:{data1}_{data2}_{data3}.pdfdatatypes:data1:-type:regexregex:'[\s]{30,80}(?P<ancode>[A-Z]{4,12})\s+'from_line:11to_line:14strict:Trueregex_group_name:ancode-type:coordinatesline:12column:40prefix:""-type:coordinatesline:13column:40prefix:""data2:-type:regexregex:'\s+(M|Mme|Mlle)\s+(?P<name>[\w\s]+)(\n|$)'from_line:6to_line:9regex_group_name:namestrict:True-type:coordinatesline:8column:50data3:-type:coordinatesline:2column:60prefix:"Section:"Here we configured the parsing of files named salaire_<year>_<month>.pdfFor each page, we’ll extract three data and group all pages by matching
data1/data2/data3 3-uples. The pages will be grouped in a file named with thefilename_template.FindersFor each data you can cumulate several “finders” to achieve data retrieval.
Finders are used in the specified order.There are two types of finders.RegexDataFinderUse a regex to find the data in the page’s string representation (pdftotext
output)regexThe regex to use for matching the data (ancode or name) we’re looking for.strict (default to False)If True a result is returned if only one item matches the regexpfrom_line / to_line (optionnal)Specify a range of lines to restrict the amount of data we look at
The Finder will only look between from_line and to_line line numbers (starts
with 1).regex_group_name (optionnal)If the regexp uses groups, specify the group matching the dataCoordinateDataFinderUse coordinates to find the data in the page’s string representation (pdftotext
output)lineThe line where to look for the datacolumnWhere to start in the lineprefix (optionnal)A prefix after which we should find the dataLoggingThis program supports advanced logging configuration with the following options.verbosity:DEBUGAvailable options are DEBUG/INFO/WARNING/ERROR/CRITICALSyslog logginguse_syslog:trueMail logginglog_to_mail:truemail:host:localhostfrom:admin@host.frto:contact@example.netsubject:'[%(hostname)s]Logofthepdfsplitter'That program is smart enough to use syslog if the config specifies it.It logs to mail if the config containslog_to_mail: TrueExamplesA full run:endi-split-pdf-run -c myconfig.yaml playground/salaires_2013_07.pdfTest that the file is parseable on the 5 first pages:endi-split-pdf-run  -c myconfig.yaml playground/salaires_2013_07.pdf -r 5Use-vfor debug messages.Use-hto get a complete overview of options.Known problemsfor payrollscannot handle some PDF files, especially if there is no outline and the
charset is ‘binary’.
Check this with:file -i $filename.pdfKnown problemsWhen the logs returns messages like :CRITICAL  - No page of output!If the end user generates his files with Sage “Édition pilotée”, the problem may
be that the end user used “print to PDF” export instead of “Save to PDF”.