Download the PHP package yetidevworks/yetipdf without Composer

On this page you can find all versions of the php package yetidevworks/yetipdf. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.

FAQ

After the download, you have to make one include require_once('vendor/autoload.php');. After that you have to import the classes with use statements.

Example:
If you use only one package a project is not needed. But if you use more then one package, without a project it is not possible to import the classes with use statements.

In general, it is recommended to use always a project to download your libraries. In an application normally there is more than one library needed.
Some PHP packages are not free to download and because of that hosted in private repositories. In this case some credentials are needed to access such packages. Please use the auth.json textarea to insert credentials, if a package is coming from a private repository. You can look here for more information.

  • Some hosting areas are not accessible by a terminal or SSH. Then it is not possible to use Composer.
  • To use Composer is sometimes complicated. Especially for beginners.
  • Composer needs much resources. Sometimes they are not available on a simple webspace.
  • If you are using private repositories you don't need to share your credentials. You can set up everything on our site and then you provide a simple download link to your team member.
  • Simplify your Composer build process. Use our own command line tool to download the vendor folder as binary. This makes your build process faster and you don't need to expose your credentials for private repositories.
Please rate this library. Is it a good library?

Informations about the package yetipdf

YetiPDF

Fast PDF text extraction in pure PHP, with no binaries and no dependencies. It runs about as quick as the C++ tool everybody else shells out to.

I wrote YetiPDF because I wanted PDFs to show up in YetiSearch results, and nothing in PHP did the job. One library needed 779MB to read a book. Another gave up on one PDF in eight. The popular answer is to install poppler and call pdftotext, which is great until you're on shared hosting with exec turned off. So I started over, with one goal: get the words out of a PDF, quickly, without falling over.

That's all it does. It won't render pages or pull out images. If you want to index PDFs for search, or hand their contents to an LLM, this is for you.

How fast?

Here are six real documents, one at a time, on PHP 8.4 with no JIT. pdftotext is poppler's command line tool, written in C++.

Document Pages YetiPDF pdftotext PrinsFrank smalot
PostgreSQL 16 manual 3,057 1.73s 2.22s 8.13s 41.06s
NIST SP 800-53 492 0.63s 0.83s 2.91s 51.57s
IRS Publication 17 142 0.36s 0.41s 1.82s 5.64s
The Memoir Class manual 625 0.44s 1.01s failed 6.24s
RFC 9110 194 0.17s 0.26s 0.68s 15.91s
Pro Git 501 0.11s 0.29s 0.88s 0.68s

Yes, that's PHP beating a C++ binary. The PostgreSQL manual is just over a million words, and YetiPDF reads all of it in under two seconds.

It isn't magic. PHP's zlib and regex engines are C underneath, and YetiPDF hands them nearly all of the heavy lifting. It also skips work that a text extractor has no use for. Every line, fill and colour change on a page gets stepped over before PHP ever sees it, and images are never decompressed at all.

If you can turn on PHP's JIT, do. The PostgreSQL manual drops to 1.28s with it.

Memory matters just as much if you're running on a 256MB host:

Document YetiPDF pdftotext PrinsFrank smalot
PostgreSQL 16 manual 39MB 72MB 48MB 430MB
NIST SP 800-53 18MB 71MB 71MB 193MB
IRS Publication 17 20MB 29MB 82MB 193MB
Pro Git 26MB 17MB 27MB 779MB

Those figures are for pulling the whole document into one string. Read it a page at a time, as in the example below, and the PostgreSQL manual peaks at 25MB.

How accurate?

Fast is no use if the text is wrong. And "wrong" for search has a specific meaning: a word that comes out glued to its neighbours can't be found.

I tested against 218 PDFs. Twenty are ordinary documents: research papers, tax forms, government standards, software manuals, and the Universal Declaration of Human Rights in Japanese, Chinese, Korean and Russian. The other 198 come from the pdf.js test collection, and those exist because they're awkward. pdftotext is the reference, and the score is how many of its words each library also found. A document that fails scores zero.

YetiPDF PrinsFrank 3.6 smalot 2.12
Documents read 218 of 218 191 211
Words recovered 99.8% 88.7% 93.9%
Documents scoring 95% or better 196 113 120
Ordinary documents scoring 95% or better 19 of 20 14 13
Time for all 218 5.6s 22.5s 147.2s

Two things about that table. pdftotext is a reference and not the truth, so when YetiPDF and pdftotext disagree and YetiPDF is the one that's right, it still loses points. The one ordinary document under 95% is a NIST standard where pdftotext turns the small-caps heading into "dvanced ncryption tandard". And most of the files that score badly are ones nothing can read, because the PDF never says which character each glyph stands for.

I also ran all 1,009 PDFs in the combined corpus, including the ones with no text. Nothing crashed and nothing hung. Nine encrypted PDFs needed passwords; the other 1,000 were read. The full run took 15 seconds, including starting a separate PHP process for each PDF.

Install

You need PHP 8.3 or newer and the zlib extension, which you almost certainly have. That's it.

Use it

Pages come back one at a time, so memory stays flat however long the document is. There are a few other things you can ask for:

And some options, all with sensible defaults:

There's a command line tool as well:

It doesn't give up

Real PDFs are a mess. Their internal index is often wrong, lengths are miscounted, and compressed data gets cut off. Fonts are worse.

YetiPDF treats all of that as normal. If the index is broken, it scans the file and builds a new one. If a compressed block is cut short, it keeps what it could read. A font with a mangled character table loses the characters that were mangled, and the rest of the page comes through fine.

Only two things throw an exception, and both happen when you open the file:

After that, nothing throws. A page that can't be read comes back empty and leaves a note in warnings().

PDFs that are "protected" against copying or printing but open without a password read normally. That covers the old RC4 scheme as well as AES-128 and AES-256, though the AES ones need the openssl extension.

And it doesn't fall over

Some PDFs are built to hurt whatever opens them. A few kilobytes can unpack into gigabytes, or ask for the same drawing a billion times over. PHP can't catch running out of memory, so one bad upload takes the whole worker down with it.

YetiPDF puts a ceiling on everything it unpacks or builds, and the ceiling moves with however much memory PHP has left. Whatever goes over is cut off or skipped. You still get the rest of the document, and warnings() says what was left out.

Ordinary PDFs don't come near those ceilings. I ran all 1,009 in the test corpus under a 64MB memory_limit and got the same text, word for word, as with 2GB to play with.

One caveat. The ceilings are about memory. A file that sets out to waste your time can still be slow, so give the job a time limit if strangers can upload to it.

Words come out as words

A PDF doesn't store sentences. It stores instructions like "draw these three letters here, now move a bit, now draw two more". Often there are no spaces at all, and the gaps between words are just gaps.

So YetiPDF works out where each piece of text lands on the page and rebuilds the words from that. It's the reason a justified LaTeX paper comes out as readable sentences and not as besuperiorinqualitywhilebeingmoreparallelizable. And it does a few more things along the way:

What it doesn't do yet

I'd rather you knew now.

Run the benchmarks yourself

Don't take my word for any of this. The scripts are in the repo:

You'll need pdftotext installed, since it's the reference. If you find a PDF that YetiPDF reads badly, diff.php shows exactly which words went missing, and I'd love to see it in an issue.

The numbers above came from an Apple Silicon Mac. The single-document timings are each tool run alone, best of three (smalot got one run, for obvious reasons). The 218-file totals add up the per-file extraction times, with six files running at once. YetiPDF's figures were last refreshed on PHP 8.4.25, after the memory and right-to-left work; the other tools' figures are from the original benchmark run.

Tests

License

MIT. The bundled glyph list in data/glyphlist.php and the CJK character tables in data/cid/ are Adobe's, under the BSD 3-Clause license reproduced in data/glyphlist.php and data/cid/LICENSE. The Hebrew and Arabic letter forms in data/presentationforms.php come from the Unicode Character Database, under the Unicode License.

Enjoy!

— Andy


All versions of yetipdf with dependencies

PHP Build Version
Package Version
Requires php Version ^8.3
ext-zlib Version *
Composer command for our command line client (download client) This client runs in each environment. You don't need a specific PHP version etc. The first 20 API calls are free. Standard composer command

The package yetidevworks/yetipdf contains the following files

Loading the files please wait ...