Skip to main content

PDF anonymizer/synthesizer for Cradl

Project description

Image/PDF synthesizer for Cradl

Github Actions build status Python version PyPi version Dockerhub version License

Disclaimer

This code does not guarantee that images/PDFs will be successfully synthesized. Use at your own risk.

Installation

$ pip install lucidtech-synthetic

Make sure to have the following software installed on your system before using the CLI:

  • ghostscript

Basic Usage

Docker

We recommend disabling networking and setting /path/to/src_dir to read-only as shown below:

docker run --network none -v /path/to/src_dir:/root/src_dir:ro -v /path/to/dst_dir:/root/dst_dir -it lucidtechai/synthetic pdf /root/src_dir /root/dst_dir
docker run --network none -v /path/to/src_dir:/root/src_dir:ro -v /path/to/dst_dir:/root/dst_dir -it lucidtechai/synthetic image /root/src_dir /root/dst_dir /usr/share/fonts/truetype/dejavu/DejaVuSansMono-Bold.ttf 6-36

CLI

synthetic pdf /path/to/src_dir /path/to/dst_dir
synthetic image /path/to/src_dir /path/to/dst_dir /usr/share/fonts/ubuntu/Ubuntu-B.ttf 6-36

/path/to/src_dir is the input directory and should contain your image/PDFs and JSON ground truths /path/to/dst_dir is the output directory where synthesized image/PDFs and JSON ground truths will be written to

Here is an example of the directory layout for /path/to/src_dir:

/path/to/src_dir
├── a.pdf|jpeg
├── a.json
├── b.pdf|jpeg
└── b.json

The output directory will follow the same layout but with modified images/PDFs and JSON ground truths:

/path/to/dst_dir
├── a.pdf|jpeg
├── a.json
├── b.pdf|jpeg
└── b.json

Using a custom Synthesizer

The following examples shown are for custom PDF synthesizers, but it works similarly for image synthesizers

CLI

synthetic pdf /path/to/src_dir /path/to/dst_dir --synthesizer-class path.to.python.Class

Make sure that parent directory of path.to.python.Class is in your PYTHONPATH

Example using one of the example Synthesizers in examples directory

synthetic pdf /path/to/src_dir /path/to/dst_dir --synthesizer-class examples.exclude-words.synthesizer.ExcludeWordsSynthesizer

Docker

docker run --network none -v /path/to/synthesizer:/root/synthesizer -v /path/to/src_dir:/root/src_dir:ro -v /path/to/dst_dir:/root/dst_dir -it lucidtechai/synthetic pdf /root/src_dir /root/dst_dir --synthesizer-class mypythonfile.ExcludeWordsSynthesizer

Note that the python module must be mounted into the docker container to /root/synthesizer for it to work. In the above example we assume a directory structure of your custom synthesizer to be like below.

/path/to/synthesizer
└── mypythonfile.py

Example using one of the example Synthesizers in examples directory. The examples directory should already exist in the image so that we don't need to mount anything additional.

docker run --network none -v /path/to/src_dir:/root/src_dir:ro -v /path/to/dst_dir:/root/dst_dir -it lucidtechai/synthetic pdf /root/src_dir /root/dst_dir --synthesizer-class examples.exclude-words.synthesizer.ExcludeWordsSynthesizer

Help

All methods support the --help flag which will provide information on the purpose of the method, and what arguments could be added.

$ synthetic --help

Known Issues

Image Synthesizer

  • Synthesized text does not follow the rotation of the document in the image if document is rotated
  • Bounding boxes needed in ground truth

PDF Synthesizer

  • Does not synthesize images inside PDF
  • Replaced strings are sometimes not hexadecimal encoded even when expected to be
  • Text appearing as single characters with custom spacing in PDF will often yield poor results

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

lucidtech-synthetic-0.5.0.tar.gz (16.0 kB view details)

Uploaded Source

Built Distribution

lucidtech_synthetic-0.5.0-py2.py3-none-any.whl (18.7 kB view details)

Uploaded Python 2 Python 3

File details

Details for the file lucidtech-synthetic-0.5.0.tar.gz.

File metadata

  • Download URL: lucidtech-synthetic-0.5.0.tar.gz
  • Upload date:
  • Size: 16.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.11.3

File hashes

Hashes for lucidtech-synthetic-0.5.0.tar.gz
Algorithm Hash digest
SHA256 a7bc9be41ffe8f375a28a5ab2e2b4e330cbf66c653eb35f381e7afde1ed7f021
MD5 1d1e8eaa766e64cb370b434056b40e9c
BLAKE2b-256 4cd763d4f66d57dd3c87a6836f080083bc5ee7f40779e5a9639a5756cf39d812

See more details on using hashes here.

File details

Details for the file lucidtech_synthetic-0.5.0-py2.py3-none-any.whl.

File metadata

File hashes

Hashes for lucidtech_synthetic-0.5.0-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 8376d5b1b94f355cc13bcf730a879af2f4d6553b65df495e63fa10ab09840198
MD5 f0ab821016c829d2fad238d9b784de9b
BLAKE2b-256 9aaa3a9a8e2507f1b4b53b53188248bcf6f70e386df56751238f47d4aeee6757

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page