Mark Stephens Mark Stephens has been working with Java and PDF since 1999 and has diversified into HTML5, SVG and JavaFX. He also enjoys speaking at conferences and has been a Speaker at user groups, Business of Software, Seybold and JavaOne conferences. He has a very dry sense of humor and an MA in Medieval History for which he has not yet found a practical use.

PDF to HTML5 conversion – innerText in Firefox

39 sec read

One of the ‘issues’ with writing HTML5 is using commands which work across all browsers. I came across a good example of this while debugging an issue this morning…

In a previous release I added this code snippet

if(actualWidth>20 && actualWidth>rawWidth && rawWidth!=actualWidth & el.innerText.search(' ') > -1){

It actually turns out that this causes issues in Firefox because Firefox does not support innerText and fails – anything in the Javascript after it meets this (which in this case was all the canvas drawing code) fails. The solution is to use textContent instead.

if(actualWidth>20 && actualWidth>rawWidth && rawWidth!=actualWidth & el.textContent.search(' ') > -1){

and happily textContent also works on other browsers. But it does highlight that you need to be careful when writing HTML5 for cross-platform support.

Luckily there is a really good site which lists browser compatibility on all HTML5/canvas/Javascript features at http://caniuse.com/ which is now on my bookmarks. Do you have any recommendations for cross-browser support?

Mark Stephens Mark Stephens has been working with Java and PDF since 1999 and has diversified into HTML5, SVG and JavaFX. He also enjoys speaking at conferences and has been a Speaker at user groups, Business of Software, Seybold and JavaOne conferences. He has a very dry sense of humor and an MA in Medieval History for which he has not yet found a practical use.

Converting your PDF files to HTML5 with BuildVu 

Recently we announced our updated product range for 2018 and are rebranding some existing products, like JPDF2HTML5 which has been renamed to BuildVu. It...
Georgia Ingham
3 min read

Favourite resources from our HTML development team

As the web progresses and grows, so do the technologies that come along with it. Trying to keep on top of everything you need...
Ovidijus Okinskas
1 min read

How HTML5 Javadocs in Java 9 will make your…

Here at IDRsolutions we are very excited about Java 9 and have written a series of articles explaining some of the main features. In...
Rob
1 min read

Leave a Reply

Your email address will not be published. Required fields are marked *