Posts

Showing posts with the label PDF

Make PDFs searchable

I searched for a good way to make scanned documents searchable. Most newer scanning software already has some OCR built-in, but what about all the old documents? Using pdfsandwich and Tesseract , we recover the text from each page of a PDF and put it behind each page as an invisible layer. That way, we can search the PDF with a normal PDF reader or upload it to Google translate to get a translated version. To get a text-only version, pdftotext can be used. First, install the missing packages (tested on Ubuntu 12.04): # we use tesseract-ocr-deu for German apt-get install tesseract-ocr tesseract-ocr-deu poppler-utils apt-get install exactimage imagemagick ghostscript Second, we download and install pdfsandwich: wget http://downloads.sourceforge.net/project/pdfsandwich/pdfsandwich%200.0.7/\ pdfsandwich_0.0.7_amd64.deb dpkg -i pdfsandwich_0.0.7_amd64.deb Finally, we run pdfsandwich and pdftotext on a PDF: pdfsandwich -resolution 240x240 -rgb -lang deu german_document.pdf # creates ge...

Create PDF invoices with HTML5 and PhantomJS

Image
Creating invoices in PDF is always a bit tricky: there are many libraries to create PDF documents with PHP, but most can't handle complex layouts and require a lot of memory and CPU time. Things like Unicode characters and line/page breaks are often difficult to program and the source of many bugs and memory problems. Using logos as vector graphics or embedding TrueType fonts is often required, but not possible with most libraries. The good thing is that all these features are included in HTML5. Since most companies offer their invoices also in HTML, it would be great to convert them directly to PDF. Tools like html2ps and ps2pdf can produce PDFs with 200+ pages without problems, but only support HTML4 and some very limited CSS. Also, the layout is never the same as in a web browser. So we need a real web browser to convert HTML pages to PDFs. From testing web applications, we know that PhantomJS is a headless WebKit browser that runs on the commandline and can automate things ...