Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/baruchel/txt2pdf
Text to PDF converter with Unicode support
https://github.com/baruchel/txt2pdf
Last synced: 3 months ago
JSON representation
Text to PDF converter with Unicode support
- Host: GitHub
- URL: https://github.com/baruchel/txt2pdf
- Owner: baruchel
- License: mit
- Created: 2014-10-19T19:44:17.000Z (about 10 years ago)
- Default Branch: master
- Last Pushed: 2023-06-09T22:37:06.000Z (over 1 year ago)
- Last Synced: 2024-06-28T07:38:25.700Z (5 months ago)
- Language: Python
- Size: 45.9 KB
- Stars: 73
- Watchers: 8
- Forks: 46
- Open Issues: 10
-
Metadata Files:
- Readme: README.md
- License: LICENSE.txt
Awesome Lists containing this project
README
txt2pdf
=======Text to PDF converter with Unicode support.
This is a Python 2 / 3 script using the [ReportLab](https://pypi.org/project/reportlab/) module for generating PDF
documents. It is intended to be used with monospace True Type fonts.
It can be hacked for being used with Type 1 Postscript fonts, but such
fonts contain less characters than TTF ones.Setup
-----python -m pip install -r requirements.txt
Usage
-----Type the following command for getting some help:
txt2pdf -h
The easiest way to use the tool for creating an _output.pdf_ document is:
txt2pdf document.txt
You can change the name of the resulting PDF file:
txt2pdf -o document.pdf document.txt
You can specify your own TTF font:
txt2pdf -f /usr/share/fonts/ubuntu/UbuntuMono-R.ttf -o document.pdf document.txt
Other options allow to set the margins, and to adjust typographical settings (horizontal space between consecutive characters or vertical space between lines). You may also include the name of the author of the document or its title in the properties of the PDF document.
### Character replacement And Translation
The `--character-replacement` flag takes the filename of a [json](https://www.json.org/) file that maps single characters into replacement strings (potentially single characters but could be several).
Example file, that replaces tabs with a multi-character string and essentially removes form-feeds (replaces with an empty string):
{
"\t": "->",
"\f": ""
}The key values can either be strings or numerics, where the numeric is the Unicode point in **decimal**. For example, for the form-feed character the numeric 12 could be used instead:
{
"\t": "->",
12: ""
}Fonts
-----The following fonts have been tested with success:
* Courier (by default)
* LiberationMono
* DejaVuSansMono
* UbuntuMono
* FreeMono
* DroidSansMono
* FiraMono
* InputMono (different versions)
* Envy Code
* Anonymous Pro
* APL385
* APLX Unicode
* SImPL
* Pragmata Pro
* HackThe Type 1 font "Courier10PitchBT-Roman" can be used by hacking the code.
No Open Type font work, which includes:
* Source Code Pro
* Inconsolata
* UMTypewriter