Code Monkey home page Code Monkey logo

touchpdf's Introduction

TouchPDF

TouchPDF is a simple web PDF viewer for jQuery. It is based on the pdf.js library and support mobile gestures for swiping pages and zooming.

Features

  • Use finger to swipe to next or previous page
  • Pinch to zoom in and out
  • Follow links to document sections or external URLs
  • Add colorful tabs for quick access to bookmarked pages
  • Loads directly in your DOM, without iFrame

Supported browsers

Firefox, Chrome, Opera, IE >= 9, Safari, Android Browser

Demo

Check out the online demo at: http://touchpdf.net/demo/index.htm

Getting started

###Get the jQuery plugin To get a local copy of the plugin, clone it using git:

$ git clone git:// github.com/loicminghetti/touchpdf.git touchpdf
$ cd touchpdf

Note: you need to start a local web server as some browsers don't allow opening PDF files for a file:// url.

###Usage Add the following to your document's <head>

<meta name="viewport" content="initial-scale=1.0, user-scalable=no" />
<script type="text/javascript" src="jquery.min.js"></script>
<script type="text/javascript" src="pdf.compatibility.js"></script>
<script type="text/javascript" src="pdf.js"></script>
<script type="text/javascript" src="jquery.touchSwipe.js"></script>
<script type="text/javascript" src="jquery.panzoom.js"></script>
<script type="text/javascript" src="jquery.mousewheel.js"></script>
<script type="text/javascript" src="jquery.touchPDF.js"></script>
<link href="jquery.touchPDF.css" rel="stylesheet" media="screen" /> 

Add an empty div in your document that will contain the PDF viewer

<div id="myPDF"></div>

Load a PDF file by adding the following script at the end of your document

<script type="text/javascript">
  $(function() {
    $("#myPDF").pdf( { source: "yourfile.pdf" } );
  });
</script>

You ca also add bookmarks tabs to your PDF display:

$(function() {      
  $("#myPDF").pdf( {
    source: "demo.pdf",
    tabs: [
      {title: "Tab 1", page: 2, color: "orange"},
      {title: "Tab 2", page: 3, color: "green"},
      {title: "Tab 3", page: 5, color: "blue"},
    ]
 });
});

###Viewer options

Option Type Default Description
source string " " Path of PDF file to display.
title string "TouchPDF" Title of the PDF to be displayed in the toolbar.
tabs array [ ] Array of tabs to display on the side. See below for syntax.
tabsColor string "beige" Default background color for all tabs. Available colors are "green", "yellow", "orange", "brown", "blue", "white", "black" and you can define your own colors with CSS.
disableZoom boolean false Disable zooming of PDF document. By default, PDF can be zoomed using scroll, two fingers pinch, +/- keys, and toolbar buttons.
disableSwipe boolean false Disable swipe to next/prev page of PDF document. By default, PDF can be swiped using one finger.
disableLinks boolean false Disable all internal and external links on PDF document..
disableKeys boolean false Disable the arrow keys for next/previous page and +/- for zooming (if zooming is enabled).
redrawOnWindowResize boolean true Force resize of PDF viewer on window resize.
pdfScale float 1 Defines the ratio between your PDF page size and the tabs size.
quality float 2 Set quality ratio for loaded PDF pages. Set at 2 for sharp display when user zooms up to 200%.
showToolbar boolean true Show a toolbar on top of the document with title, page number and buttons for next/prev pages and zooming.
loaded function null A handler triggered when PDF document is loaded (before display of first page).
changed function null A handler triggered each time a new page is displayed.
loadingHTML string "Loading PDF" Text or HTML displayed on white page shown before document is loaded.
loadingHeight int 841 Height in px of white page shown before document is loaded (default is A4 height).
loadingWidth int 595 Width in px of white page shown before document is loaded (default is A4 width).

###Tab attributes

Each tab must be defined using a json object with the following attributes:

Attribute Type Default Description
title string Mandatory Text to display on the tab. Text of less than 3 characters will be displayed horizontaly, longer text will be displayed verticaly.
page int Mandatory PDF document page number to link to. Page numbering starts at 1.
color string As defined in viewer Set a different color to the tab. See above for available colors.
offset int 0 Pill up tabs with a small offset so that the user knows there are hidden tabs behind. Starts at 0.
top int undefined Align tab from the top of the PDF document, by a given number of pixels. By default, tabs are positioned one after the other.
bottom int undefined Align tab from the bottom of the PDF document, by a given number of pixels.
height int undefined Set a specific height to the tab. By default, tab height will depend on the number of characters in the title.

Credit

This plugin heavily relies on the following great open source work:

Getting help

If you need help you can contact me

Enjoy and feel free to contribute!

touchpdf's People

Contributors

loicminghetti avatar

Stargazers

Frogsuite IRD avatar I Putu Agestya Pramana avatar aldi setia pambudi avatar  avatar ilemon18 avatar Rizky Kurniawan avatar capitaine-cro avatar Vincent H Guyo avatar  avatar  avatar Jonhen avatar  avatar PMADLP avatar 翔少 avatar  avatar Domenico Sgarbossa avatar Adam Starbuck avatar Deakin Tsang avatar 金灿 avatar 诸葛思清 avatar  avatar  avatar Fei YuNan avatar Shah Zaib avatar  avatar Mio avatar  avatar geokorolev avatar 好好先森灬 avatar aben avatar crixusshen avatar xiaopohai85707 avatar pravid avatar  avatar  avatar JL avatar Fred huu avatar yangqiwei avatar  avatar gary.liu avatar  avatar crax avatar wcnjeusr avatar  avatar Benji Fischman avatar  avatar marktrue avatar  avatar Evan Wieland avatar  avatar Dirk H. Wolthuis avatar Anmol Raghuvanshi avatar Maxime avatar Sebastian Rothe avatar Manny Aparaschivei avatar  avatar haha avatar cloudroc avatar Manuel avatar ALEXANDRE CASSIMIRO ANDREANI avatar

Watchers

Bogus curry avatar  avatar pravid avatar gary.liu avatar James D. Montecillo avatar  avatar

touchpdf's Issues

TouchPDf

Hi,

After a lot of search, i found this plugin which meets my need.Sooo many thanks for that. But i am facing difficult to move to the next page when the pdf is zoomed.

My query is: I am using this plugin for IPAD and when i zoomed the pdf's page and trying to swipe it to the next page but not happening. so please help me how to achieve this.

I want to move to the next page by swiping when the page is already zoomed.

Please help asap. very urgent requirement.

Thanks in advance,.

Allow HTML notations for tabs color

Instead of using CSS, allow HTML notations for the tabs color and text color, eg.

{title: "Section x", page: 6, background-color: "#990000", text-color: "#999900"}

If you leave the color-attribute as it is, this won't affect existing use cases.

Fit screen view of the PDF

Hi,
this is actually not an issue.
I was trying to make the pdf fit the entire screen.
I am not able to make it working.
In PDF.JS there is an option called "Page-Fit" which scales the entire view to fit the screen.
Can you please give any pointer as to how it can be done in your application.
Thanks

Make it responsive - 100% of the myPdf div width?

I want to make this responsive so it is 100% of the #myPdf div. And I don´t use any tabs at all.
So I check the #myPdf divs width so I can set that on .pdf-outerdiv, $viewer, $drag etc and all is fine.
But I can't get the canvas to work as it should?
It is only showing half of the pdf.
I have tried to set
var mypdfwidth=$("#myPDF").width();
canvas.width=mypdfwidth
and then changed this in many different ways but I simple don´t understand how it calculate the canvas!?
$(".pdf-canvas").css("transform", "scale("+(1/options.quality)+")").css("transform-origin", "top left");
I have even tried to set to the mypdfwidth.
I have tested a lot of things but I can´t get it to work.

What should the loadingHeight and loadingWidth in default be? Should it be as in the demo, 595 wide? and 841 in heigh? Or do I need to change that?
So any help really appreciated, thanks.

pdf not sharp

I would like to use touchpdf for my company, but MichaelBosello is right, the pdf's are not really sharp. Is it possible to fix this problem?

How Can i add custom features?

Hello,
It's great plugin what i am doing is showing pdf file in overlay screen is there any way of adding scrolling view of pdf?

Load worker once

Is it possible to load the worker once?
I have a lot PDFs to display and there seems to be a lot of traffic caused by workers.

在手机上使用

例如:安卓手机 有些pdf中带有图片的显示不出来 求大神解决!!!
wenti

Modify the page style

How to modify the size of the button button on the previous page of the page because the button is small on the phone and not easy to click

Select-able text

I need the text layer of a PDF to be selectable. I've only just started using pdf.js but I note there's text_layer_builder.js and ui_utils.js available. How can I incorporate those with touchpdf?

I'm fine with turning off swiping and zooming (requiring users to use the buttons on the fool bar).

js error

I am getting the folllowing error
Uncaught Error: No PDFJS.workerSrc specified
at error (pdf.js:236)
at WorkerTransport (pdf.js:2522)
at Object.getDocument (pdf.js:1888)
at load (jquery.touchPDF.js:507)
at new TouchPDF (jquery.touchPDF.js:203)
at HTMLDivElement. (jquery.touchPDF.js:152)
at Function.each (jquery-2.2.3.min.js:2)
at n.fn.init.each (jquery-2.2.3.min.js:2)
at n.fn.init.init (jquery.touchPDF.js:146)
at n.fn.init.$.fn.pdf (jquery.touchPDF.js:122)

Next and Previous buttons are not working on IPAD

Hi,

How to enable next and previous buttons on Ipad. Even Zoom + & - keys also not working. But my concern is i want the next and previous buttons should work on IPAD.

Please reply at the earliest.

Thank You.

Viewer not refreshed

Hi,
First of all thanks for your contribution.
I have an issue:
In a web page after selecting a pdf with a button, the pdf renders ok, but then If I try to change the file selecting another pdf file, the viewer shows the prevous pdf in its current page. It seems that the viewer is caching, because in the second selection the "loaded" event is not thrown. Any ideas?
Thanksin advance

Stuck on "PDF Loading"

I have embedded this in a site I'm building. I've applied the most basic implementation without tabs etc.

The site is running wordpress which is already embedding jquery so the only change I've made really to the example code is to remove the script link to googleapis.com hosted copy.

Anything obvious I'm doing wrong here? You can see the test at http://www.anderson-sheppard.co.uk/preview/pdf-test/ (you need to login with preview123)

I want to use it instead of iframe and wants to show the pdf which is on server, does it supports byte array?

Hi,

i have resolved the button issue. I have a requirement to use this control but i am not aware whether it supports the things which i am looking for, please do reply for the same. here is what i really need to know

  1. In our project, we are getting pdf's from the server and for that we used iframe. now does this plugin supports this without using iframe ?
  2. Does this plugin supports taking byte array and display as pdf?

if yes pl guide me how to do it.

Need your earlier response and thanks for the support.

react way | es6

Hi Sir,

i've been working recently with reactjs and redux, i've a requirement to work on pdf using react and redux, pdf view should work in all devices.. can we do it swipe gestures etc in react way?

at least give an idea..

Double Tap on a page when zoomed in can be reset back?

Hi

Double Tap on a page when zoomed in can be reset back? If so please help me to get it. please provide a snippet. What is the event and how to reset to original. Please get back to this as soon as possible .

Thanks.

Zoom in Android it does not work

I implement the touchpdf in my ionic project and works fine, but since 2 months ago, in android devices, stop the zoom in/out and I don`t now what happend.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.