Skip to content

Commit

Permalink
Added missing files
Browse files Browse the repository at this point in the history
  • Loading branch information
domoritz committed Sep 20, 2012
1 parent b298bc4 commit 0ea00bb
Show file tree
Hide file tree
Showing 3 changed files with 554 additions and 1 deletion.
63 changes: 63 additions & 0 deletions ckan/public/base/datapreview/pdfpreview.js
@@ -0,0 +1,63 @@
var CKAN = CKAN || {};

CKAN.View = CKAN.View || {};
CKAN.Model = CKAN.Model || {};
CKAN.Utils = CKAN.Utils || {};
CKAN.Strings = CKAN.Strings || {};

(function ($) {
$(document).ready(function () {
//CKAN.PdfPreview.loadPreview(preload_resource);
});
}(jQuery));

/* =================== */
/* == PDF Previewer == */
/* =================== */
CKAN.PdfPreview = function ($, my) {
my.dialogId = 'ckanext-pdfpreview';

// **Public: Opens a pdf preview**
//
// Returns nothing.
my.loadPreview = function(resourceData) {
'use strict';

// disable worker for now
// TODO: enable
PDFJS.disableWorker = true;

//
// Fetch the PDF document from the URL using promices
//
PDFJS.getDocument(resourceData['url']).then(function(pdf) {
// Using promise to fetch the page
pdf.getPage(1).then(function(page) {
var scale = 1.5;
var viewport = page.getViewport(scale);

//
// Prepare canvas using PDF page dimensions
//
var canvas = document.getElementById(my.dialogId);
var context = canvas.getContext('2d');
canvas.height = viewport.height;
canvas.width = viewport.width;

//
// Render PDF page into canvas context
//
var renderContext = {
canvasContext: context,
viewport: viewport
};
page.render(renderContext);
});
});
}

// Export the CKANEXT object onto the window.
$.extend(true, window, {CKANEXT: {}});
CKANEXT.PDFPREVIEW = my;
return my;
}(jQuery, CKAN.PdfPreview || {});

0 comments on commit 0ea00bb

Please sign in to comment.