Code Monkey home page Code Monkey logo

pdf-explorer's Introduction

Some code that parses a PDF file into objects. There's also some very preliminary WIP code to display the file structure on a web page.

What is this?

At the lowest level, a PDF file is a sequence of 8-bit bytes. Use hexdump or xxd or something to see it.

At the next lowest level, a PDF file is a set of objects, wrapped in some file structure (header and trailer). This is still too low-level to be practically useful for anything, but the code here only concerns itself with this level.

Specifically, there are 8 types of objects:

  • Boolean Objects
  • Numeric Objects
  • String Objects
  • Name Objects
  • Array Objects
  • Dictionary Objects
  • Stream Objects
  • Null Object

To read a PDF file, we need to be able to parse all these kinds of objects, and also, additionally:

  • Indirect Object definitions (like 12 0 obj โ€ฆ endobj)
  • Indirect object references (like 12 0 R)
  • File structure: Header, body, cross-reference table, trailer.

This project parses (most) PDF files, into the above structures. It does nothing further in terms of interpreting the objects in any useful way.

It is also (sort of, WIP) a "literate program" to some extent: read here.

Some notes:

  • It can now round-trip via JSON. That is, if you dump to JSON and read back, you will get the exact same bytes.

    • This is not as impressive as it sounds, because we could in principle just dump the sequence of bytes into JSON as an array of numbers. However, here we're doing slightly more than that.
  • It assumes the input is valid, e.g. does not check in dict for unique keys, does not check for stream length, etc. In fact, parses the file "forwards", rather than starting with the trailer first.

Try it out

Similar (better) projects

I haven't yet tried either of these, but they seem to be further along (IIUC they're written in Python and generate HTML):

There's also a Java app:

Others:

Old notes

Status currently:

  • As of 2022-05-01 14:20 (e54b45e): Works for 19426 out of 19492 PDF files on my laptop. So "fails" for 66 files. Looked at each of them. They are all malformed in some way or the other.

pdf-explorer's People

Contributors

shreevatsa avatar

Stargazers

 avatar  avatar

Watchers

 avatar

Forkers

mjsignup

pdf-explorer's Issues

Document everything

I just read Coping strategies for the serial project hoarder by Simon Willison (simonw), which recommends writing everything down, working issue-first (create an issue, talk to yourself, etc) and basically leave things in a sane state that you can walk away from at any point, so that there isn't any guilt. Sounds like a great state to aspire to!

The first step would be to document what already exists, from a POV of "if I don't do any more work on this project, whatever already exists should still make sense".

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.