Skip to main content

Posts

Showing posts from January 3, 2013

Very useful HTML5 APIs

Element.classList The classList API provides the basic CSS controls our JavaScript libraries have been giving us for years: // Add a class to an element myElement. classList . add ( "newClass" ) ; // Remove a class to an element myElement. classList . remove ( "existingClass" ) ; // Check for existence myElement. classList . contains ( "oneClass" ) ; // Toggle a class myElement. classList . toggle ( "anotherClass" ) ; The epitome of a great API addition: simple and intelligent. ContextMenu API The new ContextMenu API is excellent:  instead of overriding the browser context menu, the new ContextMenu API allows you to simply add items to the browser's context menu: contextmenu = "mymenu" > type = "context" id = "mymenu" > label = "Refresh Post" onclick = "window.location.reload();" icon = "/images/refresh-icon.png" > label = ...

Read PDF and Word DOC Files Using PHP

Reading PDF Files To read PDF files, you will need to install the XPDF package , which includes "pdftotext." Once you have XPDF/pdftotext installed, you run the following PHP statement to get the PDF text: $content = shell_exec ( '/usr/local/bin/pdftotext ' . $filename . ' -' ) ; //dash at the end to output content Reading DOC Files Like the PDF example above, you'll need to download another package. This package is called Antiword . Here's the code to grab the Word DOC content: $content = shell_exec ( '/usr/local/bin/antiword ' . $filename ) ; The above code does NOT read DOCX files and does not (and purposely so) preserve formatting. There are other libraries that will preserve formatting but in our case, we just want to get at the text.