var pdf = null;
PDFJS.getDocument('sample.pdf').then(function(pdfDoc) {
pdf = pdfDoc;
for (var i = 1; i <= pdf.numPages; i++) {
pdf.getPage(i).then(renderPage);
}
});
function renderPage(page) {
var canvas = document.createElement('canvas');
var ctx = canvas.getContext('2d');
var viewport = page.getViewport(1.0);
canvas.width = viewport.width;
canvas.height = viewport.height;
var renderContext = {
canvasContext: ctx,
viewport: viewport
};
page.render(renderContext).then(function() {
$('#pdf-container').append(canvas);
});
}
// Handle add comment button
$('#add-comment').click(function() {
var comment = $('#comment').val();
var x = 100; // Change this to get the X coordinate of the comment
var y = 100; // Change this to get the Y coordinate of the comment
var pageNum = 1; // Change this to get the page number of the comment
$.ajax({
url: 'save-annotation.php',
method: 'POST',
data: {x: x, y: y, comment: comment, page: pageNum},
success: function() {
alert('Comment added!');
},
error: function() {
alert('Error adding comment.');
}
});
});