1

I'm developing a web app using JSP/Javascript, it lets user upload a local fonts file, how to get the font Title from the font's file property in the JSP page, with Java or Javascript ?

enter image description here

See details from the attached picture, I want to get the value of the "Title" which is : A.C.M.E Explosive Bold

I want to show user the info before they actually hit the submit button and upload it. Yes, it needs to happen on the user side and looks like the following :

enter image description here

Frank
  • 30,590
  • 58
  • 161
  • 244
  • will this help .. http://technet.microsoft.com/en-us/library/ee176615.aspx :) not a java code but can be worked on . – Ashish Gupta Sep 19 '12 at 19:22
  • So, you have a HTML5 FileReader to get the font file the user wants to upload? Or what do you want to happen clientside (in JS)? – Bergi Sep 19 '12 at 19:28
  • @Ashish Gupta : Yes, that's what I want, but I need it in JSP/Javascript/Struts environment, how to do it ? – Frank Sep 19 '12 at 19:36
  • write a shell script . upload it in your server Read it through java code. Read the result http://stackoverflow.com/a/428989/1085285 Another one is :: http://stackoverflow.com/q/10810943/1085285 – Ashish Gupta Sep 19 '12 at 19:41
  • @Frank this can be done with HTML5. See my demo here: http://fontificate.samlecuyer.com/ – saml Sep 20 '12 at 17:37

2 Answers2

0

I wrote a library to do this. See an example here. The file you'll want to look at in particular is fontificate.js, as well as the index.html inline scripts. Calabash.js is another library I wrote for promises and can be for the most part ignored (as long as it's still included).

saml
  • 6,702
  • 1
  • 34
  • 30
  • Yes, but OP wants do perform this in the browser. – f_puras Sep 19 '12 at 19:56
  • OP got me curious enough to go home and write a library to do this. – saml Sep 19 '12 at 21:08
  • If you take a look at the loop that's pulling out each string and concatenating it with it's title, you can filter by nameID === 4. Then you can ignore basically everything else. – saml Sep 20 '12 at 20:17
  • Unfortunately, this app won't ever work in IE9 because it uses newer APIs that Microsoft hasn't implemented in their browsers. – saml Sep 20 '12 at 20:49
  • My app has to support IE8,9 and Firefox. – Frank Sep 21 '12 at 01:13
  • Works here with current Firefox, Chrome, and Opera. Safari and IE8 say "Sorry, your browser doesn't support Files" – f_puras Sep 21 '12 at 07:19
  • @saml : I found that for IE9, I can probably use something like this : http://stackoverflow.com/questions/12530488/how-to-get-all-the-attributes-of-a-file [Maybe detect which browser first then handle accordingly ? But I'm still having trouble getting the "Title" property from your code, any sample code ? Thanks ! ] – Frank Sep 21 '12 at 12:30
  • Yes, although it only works in Firefox, but there is nothing better than this. thanks ! – Frank Sep 24 '12 at 10:55
-1

I believe this is not possible with JSP or JavaScript. Security constraints do not allow you to access local files. HTML's <input type="file" also cannot be intercepted by your code, thus I see only one chance: A Java Applet could do the trick, provided the user has trusted it. Flash might work as well, but I don't know about that.

f_puras
  • 2,521
  • 4
  • 33
  • 38