pastebin

Paste Search Dynamic
Recent pastes
pdf viewer
  1. var pdf = null;
  2.     PDFJS.getDocument('sample.pdf').then(function(pdfDoc) {
  3.       pdf = pdfDoc;
  4.       for (var i = 1; i <= pdf.numPages; i++) {
  5.         pdf.getPage(i).then(renderPage);
  6.       }
  7.     });
  8.     function renderPage(page) {
  9.       var canvas = document.createElement('canvas');
  10.       var ctx = canvas.getContext('2d');
  11.       var viewport = page.getViewport(1.0);
  12.       canvas.width = viewport.width;
  13.       canvas.height = viewport.height;
  14.       var renderContext = {
  15.         canvasContext: ctx,
  16.         viewport: viewport
  17.       };
  18.       page.render(renderContext).then(function() {
  19.         $('#pdf-container').append(canvas);
  20.       });
  21.     }
  22.  
  23.     // Handle add comment button
  24.     $('#add-comment').click(function() {
  25.       var comment = $('#comment').val();
  26.       var x = 100; // Change this to get the X coordinate of the comment
  27.       var y = 100; // Change this to get the Y coordinate of the comment
  28.       var pageNum = 1; // Change this to get the page number of the comment
  29.       $.ajax({
  30.         url: 'save-annotation.php',
  31.         method: 'POST',
  32.         data: {x: x, y: y, comment: comment, page: pageNum},
  33.         success: function() {
  34.           alert('Comment added!');
  35.         },
  36.         error: function() {
  37.           alert('Error adding comment.');
  38.         }
  39.       });
  40.     });
  41.  
Parsed in 0.030 seconds