How to load PDF pages asynchronously? - javascript

I'm looking for a pdf viewer that can load a pdf asynchronously. This is a big need in our site since the PDF documents have at least 50 pages.
I've already looked into pdf.js by mozilla but I can't seem to make it work (I think the examples are broken)
Any help would greatly be appreciated! Thanks!
UPDATED:
Got it working but my solution was messy. I integrated the web/viewer codebase of the pdf.js repo in my site. So whenever I need to view a pdf, I just used an iframe with a source #{pdf_viewer_path}?file=#{file_path}.
Is there a better solution than this?
NOTE: The above method does not work in a production setting. There are some js errors showing up when displaying the page. The only way I got it to work is to not precompile the js files of pdf.js.

This is an experimental solution. I just compiled the mozilla pdf.js library and integrated it with a rails engine. You can use the gem I made here: https://github.com/normancapule/pdfjs-rails-engine.

Related

How to validate html page and fix it with javascript

I recently ran into the problem related to html document validation. It seems to me that Chrome is pretty clever and can fix most of the mistakes.
In my case I receive raw html file with mistakes and I need to load it on Sumsung TV powered by Tizen 2.4. Unfortunately it doesn't provide the same features as Chrome so I need to fix documents by myself.
What do you think about html validation with help of javascript (My app is written in js).
Download html page and save it
1.2. Download all the related files (css,js,images) and fix links
fix all the problems (use some library, or may be there are some
good validators, but it is better to do offline)
Open document
You can use a linter; a quick search on Github showed up some JavaScript-powered HTML-linters:
htmllint: for HTML5
Bootling: for Bootstrap

Combine CKEditor into 1 file

Thought I would open this question to the javascript community. Does anyone know if its possible to combine CKEditor into 1 file? I want to try and integrate it in one of my desktop applications which uses a web viewer - I can execute one flat file in my web viewer internally in my application otherwise I'll have to reference to the CDN which I'm hoping to avoid. I want to develop an app that does not require external web service.
Performance should not be an issue as the file would be in my application running locally - I would include all the licenses/readme etc etc.
Is there a tool out there that can help me to achieve this, and has anyone done it or is not possible due to the architecture - the way CKEditor has been written?
Thanks
CKEditor loads some JS files on demand (i.e. dialog definitions). There are also several skin CSS files, sprites with icons and separate langfiles. I hardly think there's any reasonable way to combine all these resources into a working JS bundle without architectural changes.

Performance:-How to reduce precompiled js file size in angularjs and rails

I am working on a website which is based on angularjs and rails in the backend.
The site is currently in production/live
The issue which I am having is that after the assets have been precompiled with the help of rake assets:precompile,The overall js file size goes above 1Mb.Hence it takes time for the site to load.
This is a major issue and since the site is fully ajax based,I cannot implement page caching.
Also have tried gzip on my nginx server but this is not helping.
This is hampering the performance of the site and would welcome any sort of help or suggestions if possible.
Thanks
I don't know about RoR or the rake assets you mentioned but here is a few leads and how I proceed (Lately, I've been starting to use Grunt) :
Concat your js files into 1 js file. It's easier to process one request rather than many little ones.
Minify your js files and make sure to use minified lib version.
Try to adopt a smart approach to load your libraries and your own files. For instance, if you only need graphics in your admin dashboard, make sure not to load d3.js on your front page. I know the Jquery ecosystem is full of useful plugins but I've seen way too many developers taking shortcuts and claiming they need Jquery when others viable alternatives exist.
Serving file using gzip is a good idea. This should reduces the size of your files significantly.
Also, Could you provide a link to your website ?

generating PDFs from html+javascript cakePHP 2.x

I am trying to generate pdf files in a cakePHP app, but so far get only html to be included in a file. The problem is that the main content of the page (calendar) is produced by the javascript which is completely ignored when generating a PDF. What is the best solution in this case?
I really appreciate your help.
If you use something like wkhtmltopdf it should work as it contains the actual rendering code used in chrome.
There is a plugin ready made that works out the box (after installing wkhtmltopdf)

Combined JS File Using YUICompressor Causing Errors

I'm combining multiple js files using YUI Compressor. The command works successfully and outputs a combined file properly.
When I point my page to it, however, it doesn't seem to be read properly and I get this error in the Javascript error console.
YAHOO is not defined
I've tried using the --nomunge and --preserve-semi options but still get the same error.
Any ideas?
are you sure you're including the yahoo YUI js file before your script?
the variable YAHOO is defined within yui.js, so that script needs to exist and be loaded before you attempt to run any javascript that uses it.
Dave,
Hard to know what the problem is without a link to the compressed file.
You may also want to post those links to the dedicated YUI Compressor discussion forum on YUILibrary.com:
http://yuilibrary.com/forum/viewforum.php?f=94
Compressor's developers are there, as well as an interested community of fellow implementers.
-Eric
Did you try to jslint your code?
It may help you detect JS errors
It can usually be integrated in your IDE(I use Textmate), and warn you when you save your js file.
A poor man option is to use the online one at: http://www.jslint.com
Another option is to use a softer compression tool like jsmin to debug the problem. One is hosted here
You compress your files. Run your app, and usually your JS debugger will show you the problem.

Categories