- Saved searches
- Use saved searches to filter your results more quickly
- License
- pxntus/txt2pdf
- Name already in use
- Sign In Required
- Launching GitHub Desktop
- Launching GitHub Desktop
- Launching Xcode
- Launching Visual Studio Code
- Latest commit
- Git stats
- Files
- README.md
- About
- Saved searches
- Use saved searches to filter your results more quickly
- License
- baruchel/txt2pdf
- Name already in use
- Sign In Required
- Launching GitHub Desktop
- Launching GitHub Desktop
- Launching Xcode
- Launching Visual Studio Code
- Latest commit
- Git stats
- Files
- README.md
- About
- How to convert a text file to PDF format on Linux
- Prerequisites
- For Debian, Ubuntu or Linux Mint:
- For Fedora, CentOS or RHEL:
- For Arch Linux:
- Convert a Text File to PDF Format
- Support Xmodulo
Saved searches
Use saved searches to filter your results more quickly
You signed in with another tab or window. Reload to refresh your session. You signed out in another tab or window. Reload to refresh your session. You switched accounts on another tab or window. Reload to refresh your session.
Convert one or more text files to a PDF document using LaTeX typesetting.
License
pxntus/txt2pdf
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Name already in use
A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
Sign In Required
Please sign in to use Codespaces.
Launching GitHub Desktop
If nothing happens, download GitHub Desktop and try again.
Launching GitHub Desktop
If nothing happens, download GitHub Desktop and try again.
Launching Xcode
If nothing happens, download Xcode and try again.
Launching Visual Studio Code
Your codespace will open once ready.
There was a problem preparing your codespace, please try again.
Latest commit
Git stats
Files
Failed to load latest commit information.
README.md
Convert one or more text files to a PDF document using LaTeX typesetting.
This tool was developed for typesetting novels and short story collections written in pure text files. The goal is to keep the text files as clean as possible with a minimum of structured formatting, i.e. a harsh subset of Markdown.
Most people writing fiction and literature use Word, Pages, Scrivener or some other WYSIWYG editor. However, there are many reasons to use a plain text editor, e.g. better text editing, less distraction of text formatting and productivity features such as full screen and zen modes (as found in Visual Studio Code and Sublime Text).
One drawback, though, is the difficulties in producing a good looking, formatted and typeset document (to be sent to publishers). This is the problem that txt2pdf tries to solve.
- Clone or download this project.
- Create an isolated Python environment using virtualenv or just use the system installation and make sure the required packages are installed using the requirement.txt file. On Windows:
py -3 -m pip install -r requirement.txt
python3 -m pip install -r requirement.txt
On Windows: When running the script for the first time (with real and valid inputs) MikTex will install multiple LaTeX packages. You should accept this.
Let’s say you have written The Great Novel. It consists of ten chapters in ten separate text files. All the files are located in the same directory among other useful resources for the writing project.
An example directory tree could look like this:
TheGreatNovel │ chapter01.txt │ chapter02.txt │ chapter03.txt │ chapter04.txt │ chapter05.txt │ chapter06.txt │ chapter07.txt │ chapter08.txt │ chapter09.txt │ chapter10.txt │ └───fragments │ │ . │ └───old │ │ . │ └───research │ │ . │ │ │ └───maps │ │ . │ └───build │ generate_book.bat │ the_great_novel.pdf │ └───env | │ . │ └───txt2pdf │ .
A recommendation is to create a directory (called build in the example above) with a batch or bash script that creates the PDF document. If you have a big writing project with lots of chapters or short stories (i.e. text files) the list of command arguments can be quite long. You don’t want to type it every time.
Besides, using a script makes it easy and fast to generate the PDF document and you want to be agile also when you write The Great Novel. Right?
The generate_book.bat could look something like this:
@echo off env\Scripts\python txt2pdf\txt2pdf.py ^ --title The Great Novel ^ --author John Doe ^ --output the_great_novel ^ chapter01.txt ^ chapter02.txt ^ chapter03.txt ^ chapter04.txt ^ chapter05.txt ^ chapter06.txt ^ chapter07.txt ^ chapter08.txt ^ chapter09.txt ^ chapter10.txt ^
The input text files to txt2pdf are plain text files. You shouldn’t need to worry about formatting. There are just a few «features» to remember.
The first line of the text file represent the chapter name (or the name of the short story). E.g. chapter01.txt in the example above could look like this:
Chapter one Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.
Minus characters in the text are converted to dashes when appropriate.
A very small subset of Markdown syntax is supported (i.e. only what I, the author of txt2pdf, so far have needed. ).
Emphasis, aka italics, are marked using underscores:
You don't know anything, dear. _I killed the captain!_, said the butler.
Quotes can be written like this to get a nice format in the output:
The next day a read the following in the newspaper: > Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore > et dolore magna aliqua. I couldn't believe my eyes.
Verses can be written with with four spaces. Line breaks will then be kept. E.g.:
Suddenly she started to recite a poem: Lorem ipsum dolor sit amet consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua I couldn't believe my ears.
Since LaTeX is used in the background for the actual typesetting, people familiar with LaTeX will recognize the typesetting of the output. I have used the document classes that I think look good. If someone wants to change the look of the PDF output template.tex is a good start.
About
Convert one or more text files to a PDF document using LaTeX typesetting.
Saved searches
Use saved searches to filter your results more quickly
You signed in with another tab or window. Reload to refresh your session. You signed out in another tab or window. Reload to refresh your session. You switched accounts on another tab or window. Reload to refresh your session.
Text to PDF converter with Unicode support
License
baruchel/txt2pdf
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Name already in use
A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
Sign In Required
Please sign in to use Codespaces.
Launching GitHub Desktop
If nothing happens, download GitHub Desktop and try again.
Launching GitHub Desktop
If nothing happens, download GitHub Desktop and try again.
Launching Xcode
If nothing happens, download Xcode and try again.
Launching Visual Studio Code
Your codespace will open once ready.
There was a problem preparing your codespace, please try again.
Latest commit
Git stats
Files
Failed to load latest commit information.
README.md
Text to PDF converter with Unicode support.
This is a Python 2 / 3 script using the 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.
python -m pip install -r requirements.txt
Type the following command for getting some help:
The easiest way to use the tool for creating an output.pdf document is:
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 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):
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:
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
- Hack
The Type 1 font «Courier10PitchBT-Roman» can be used by hacking the code.
No Open Type font work, which includes:
About
Text to PDF converter with Unicode support
How to convert a text file to PDF format on Linux
Question: I want to convert a plain text file into a PDF document. Is there an easy way to convert a text file to a PDF file from the command line on Linux?
When you have a bunch of text documents to maintain, there are advantages in converting them into PDF format. For example, PDF is good for printing because PDF documents have pre-defined layout. Besides, with PDF format, there is less risk hat the documents are accidentally modified.
To convert a text file to PDF format, you can follow two-step procedures.
Prerequisites
First, you need to install two prerequisite packages.
For Debian, Ubuntu or Linux Mint:
$ sudo apt-get install enscript ghostscript
For Fedora, CentOS or RHEL:
$ sudo yum install enscript ghostscript
For Arch Linux:
$ sudo pacman -S enscript ghostscript
Convert a Text File to PDF Format
Once all prerequisites are installed, follow these two steps to generate a PDF file from a text file.
First, convert a text file to Postscript format by using enscript command-line tool.
$ enscript -p output.ps input.txt
Finally convert the generated postscript file to a PDF file.
$ ps2pdf output.ps output.pdf
Support Xmodulo
This website is made possible by minimal ads and your gracious donation via PayPal or credit card
Please note that this article is published by Xmodulo.com under a Creative Commons Attribution-ShareAlike 3.0 Unported License. If you would like to use the whole or any part of this article, you need to cite this web page at Xmodulo.com as the original source.