add pdf.js and refactor for jpg mode.