Coder Social home page Coder Social logo

pdf2html's Introduction

pdf2html

Converts PDF e-books to HTML. Relies on the PDF actually having text (not images).

It's a wrapper for pdftohtml (from poppler-utils) that tries to restore paragraph structure by looking at text positioning and font information. It requires Python 2.

The HTML produced differs from the one you'd get from pdftohtml in these ways:

  • Paragraphs are preserved; line breaks inside paragraphs are lost.
  • Multiple adjacent spaces are left as spaces, not converted to a run of  
  • Page boundaries are discarded, not rendered as <hr>
  • The HTML produced is modern XHTML, not ancient HTML 3 with an explicit dark-grey bgcolor on the <BODY> (what's up with that???).

Usage

Usage: pdf2html input.pdf [output.html]

Options:

-h, --help show this help message and exit --version print version and exit --debug print verbose diagnostics --keep keep temporary files --title=TITLE document title --subtitle=SUBTITLE document subtitle --header-pos=HEADER_POS suppress text above this point (header) --footer-pos=FOOTER_POS suppress text below this point (footer) --leading=LEADING override autodetected intra-paragraph leading --indent=INDENT override autodetected indent --left-margin=LEFT_MARGIN override autodetected left margin --horiz-leeway=HORIZ_LEEWAY override autodetected horizontal leeway --skip-initial-pages=SKIP_INITIAL_PAGES skip the first N pages of output --skip-generator skip <meta name="generator" ...> --encoding=ENCODING character set for the HTML

Configuration

Put a .pdf2htmlrc in the same directory as the source PDF file. Every section, denoted [pattern] can apply options to files matching the pattern, e.g. :

[hello.pdf]
header_pos = 166
[*.pdf]
footer_pos = -1

All options you can specify on the command line can be specified in the config file (with the obvious exceptions of --version and --help).

Currently the most useful options you can specify this way are header and footer positions if you want to suppres header/footer text from the output. The position is specified in points, with 0 at the top of the page, increasing downwards. All text above the header pos as well as all text below the footer pos is discarded. Specify -1 (which is the default) to disable. To find out the right values, use --keep and take a look at text coordinates in the intermediate .xml file.

Bugs

  • it's not easy to use; overriding the heuristics when they go wrong requires a deep knowledge of the internals
  • doesn't handle superscript well
  • doesn't handle small caps
  • loses information such as fonts and colours
  • there are no tests
  • it doesn't support Python 3

pdf2html's People

Contributors

clach04 avatar mgedmin 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.