Giter VIP home page Giter VIP logo

txt2pdf's Introduction

txt2pdf

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.

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 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
  • Hack

The Type 1 font "Courier10PitchBT-Roman" can be used by hacking the code.

No Open Type font work, which includes:

  • Source Code Pro
  • Inconsolata
  • UMTypewriter

txt2pdf's People

Contributors

clach04 avatar baruchel avatar fdevibe avatar jdmonin avatar yilinjuang avatar srollyson avatar jschwender avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.