Tuesday, November 10, 2009

Visual Studio Error Error

Came across a serious issue in the new Visual Studio Beta today when installing. Someone ought to notify Microsoft to prevent this rarely seen issue, maybe it can be included as a feature?



Monday, October 19, 2009

Dynamic JavaScript Text-To-Speech using Acrobat Reader

Adobe Acrobat includes a text-to-speech engine which you can access through the JavaScript functionality built into PDF. However as you can post data between the browser and embedded PDFs, it is possible to use an embedded PDF as a text-to-speech engine to read text aloud, dynamically in the browser. Try it below!


TTS Example





How does it work? A combination of  JavaScript in the browser and in an embedded PDF. To use this method of your site do the following:

First you need to embed the pdf :
<object id="PdfHost" name="PdfHost" type="application/pdf" width="0" height="0" data="http://sites.google.com/site/aplacetostorethings/tts.pdf">
</object>

The browser script below initialises the message handler and creates the bridge between the browser and acrobat:
  <script type="text/javascript">
    <!--
       
        function sayIt(msg)
        {
            var pdf = document.getElementById('PdfHost');
            if(pdf==null)
                init();
            pdf.postMessage(["speak",msg]);
        }
       
        function init(){
            var pdf = document.getElementById('PdfHost');
            if (!pdf.messageHandler)
                pdf.messageHandler = {};
            pdf.messageHandler.onMessage = onPdfMsg;
          
        }
        setTimeout("init()",1000);
    // -->
    </script>

The setTimeout is used to attempt to setup the message handler, which has to happen after the pdf has finished loading. Then you can just call it using script like:
javascript:sayIt("read this text");

If you are interested in the source of the PDF, I have posted the JavaScript it contains here: tts.js

For this page I used the origami framework to inject the script into valid PDF.

Saturday, July 4, 2009

Google Chrome and Data URIs

Google Chrome's data URIs appear to work with plug-ins like acrobat (which isn't the case in Firefox). This allows you to do silly things like below:

STALLOWNED

(Requires chrome, acrobat 7+ and speakers :)

Under the hood, this is a JavaScript URI, which has a small script which replaces the document body with the following:

<object width="1" height="1" data="data:application/pdf;base64,JVBERi0xLjEKMSAwIG9iago8PAoJL1BhZ2VzIDIgMCBSCgkvVHlwZSAvQ2F0YWxvZwoJL09wZW5BY3Rpb24gPDwKCQkvSlMgNSAwIFIKCQkvUyAvSmF2YVNjcmlwdAoJPj4KPj4KZW5kb2JqCjIgMCBvYmoKPDwKCS9UeXBlIC9QYWdlcwoJL0tpZHMgWyAzIDAgUiBdCgkvQ291bnQgMQo+PgplbmRvYmoKMyAwIG9iago8PAoJL1Jlc291cmNlcyA8PAoJCS9Gb250IDw8CgkJCS9GMSA0IDAgUgoJCT4+Cgk+PgoJL1R5cGUgL1BhZ2UKCS9NZWRpYUJveCBbIDAgMCA3OTUgODQyIF0KCS9QYXJlbnQgMiAwIFIKPj4KZW5kb2JqCjQgMCBvYmoKPDwKCS9OYW1lIC9GMQoJL1R5cGUgL0ZvbnQKCS9TdWJ0eXBlIC9UeXBlMQoJL0Jhc2VGb250IC9IZWx2ZXRpY2EKPj4KZW5kb2JqCjUgMCBvYmoKPDwKCS9MZW5ndGggNTAKCS9GaWx0ZXIgL0ZsYXRlRGVjb2RlCj4+c3RyZWFtCnjaKykp1ivILEnOsDWwLgGyC0NSK0o0lIpLEnMUcvLL81JTlDTBEkCBbA1NawCrqxDXCmVuZHN0cmVhbQplbmRvYmoKeHJlZgowIDYKMDAwMDAwMDAwMCA2NTUzNSBmCjAwMDAwMDAwMTAgMDAwMDAgbgowMDAwMDAwMTIwIDAwMDAwIG4KMDAwMDAwMDE4OSAwMDAwMCBuCjAwMDAwMDAzMjUgMDAwMDAgbgowMDAwMDAwNDE3IDAwMDAwIG4KdHJhaWxlcgo8PAoJL1Jvb3QgMSAwIFIKCS9TaXplIDYKPj4Kc3RhcnR4cmVmCjU0NwolJUVPRgo=" type="application/pdf">

The enocded blob above is a base64 encoded PDF, that in in turn contains JavaScript to call the acrobat text-to-speech API.

P.S. For anyone interested in acrobat hacking, I'd strongly recommend a look at the "Origami" framework, created by Guillaume Delugré & Fred Raynal. This ruby based tool provides an open-source tool to construct, manipulate and analyse PDF documents.

Saturday, April 25, 2009

Internationalized Domain Names

Internationalized Domain Names (IDNs) are converted into punycode in most browsers by default, although it depends somewhat on the TLD. (For example, firefox will show the punycode domain name for all TLDs except those specified here.) In the quest for the domain-name-to-rule-them-all, I have been searching for domains that are readable in both unicode and punycode. For example, http://ωaψward.gr/ converts to http://xn--award-beef.gr. Pretty much a waste of time, but there are a few interesting side-effects that I noticed.

To start with, I started playing around manually, using a simple conversion app I wrote in Java, using the IDN class. After a few minutes playing around it was fairly clear that it was never going to happen with this approach. Generating unicode URLs using two valid english words - i.e. xn--apple-banana - was a faster approach. It still involved far too much effort, but introducing a few filters helped to cull out urls that are obviously not words. Some of the more interesting ones were:
  • http://www.ωaψward.gr --> http://xn--award-beef.gr
  • кill.gr --> xn--ill-bed.gr
  • ႦႲႶႻႸႽ.org --> xn--endymion.org (endyion is SO a word)
  • 汤.cn --> xn--ftw (汤, means soup in chinese, and soup is clearly ftw)
Then there were a few weird ones which deserve special mention:
  • f̹ace̸̸bo̸ok.com--> xn--facebook-deface.com (facebook defaced, get it?)
  • ̱yahoo.cn --> xn--yahoo-end.cn ( Yahoo ended by homograph attack!)
As it turns out however, the man blocks you making up cool domain names, with bourgeoisneo-capitalist rules. The main restrictions are IDNA (RFC 3490) & NAMEPREP (RFC 3491) which prohibit a lot of the unicode goodness. All a bit TLDR but basically it means "Bad luck Ghengis Botherder, no MONGOLIAN VOWEL SEPARATOR for you".

I tried registering http://www.ωaψward.gr on greek registrars since it doesn't mix unicode from different languages, but I was thwarted, mainly by my complete lack of greek & verified by visa completely failing. (wtf is that shit anyway...srsly) If anyone more clueful than me can shed some light on unicode domain rules that would be cool (Yes Chris Weber, I am talking to you.)