You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I have some list of encrypted pdf files. On click of each pdf, it should be decrypted and viewed in pdf.js. I get decrypted pdf file string as output and pass it to display pdf using **base64 encoded PDF format**. Below is my code:
var canvas = document.getElementById('can');
var context = canvas.getContext('2d');
var pdfDoc = null,
pageNum = 1,
pageRendering = false,
pageNumPending = null,
scale = 1.5;
function renderPage(num) {
pageRendering = true;
// Using promise to fetch the page
pdfDoc.getPage(num).then(function(page) {
var viewport = page.getViewport({scale: scale});
canvas.height = viewport.height;
canvas.width = viewport.width;
// Render PDF page into canvas context
var renderContext = {
canvasContext: context,
viewport: viewport
};
var renderTask = page.render(renderContext);
// Wait for rendering to finish
renderTask.promise.then(function() {
pageRendering = false;
if (pageNumPending !== null) {
// New page rendering is pending
renderPage(pageNumPending);
pageNumPending = null;
}
});
});
// Update page counters
document.getElementById('page_num').textContent = num;
}
/**
* If another page rendering in progress, waits until the rendering is
* finised. Otherwise, executes rendering immediately.
*/
function queueRenderPage(num) {
if (pageRendering) {
pageNumPending = num;
} else {
renderPage(num);
}
}
/**
* Displays previous page.
*/
function onPrevPage() {
if (pageNum <= 1) {
return;
}
pageNum--;
queueRenderPage(pageNum);
}
document.getElementById('prev').addEventListener('click', onPrevPage);
/**
* Displays next page.
*/
function onNextPage() {
if (pageNum >= pdfDoc.numPages) {
return;
}
pageNum++;
queueRenderPage(pageNum);
}
document.getElementById('next').addEventListener('click', onNextPage);
function showPdf(pdfData){
// Loaded via <script> tag, create shortcut to access PDF.js exports.
var pdfjsLib = window['pdfjs-dist/build/pdf'];
// The workerSrc property shall be specified.
pdfjsLib.GlobalWorkerOptions.workerSrc = './build/pdf.worker.js';
// Using DocumentInitParameters object to load binary data.
var loadingTask = pdfjsLib.getDocument({data: pdfData});
loadingTask.promise.then(function(pdf) {
console.log('PDF loaded');
pdfDoc = pdf;
//display total page number.
document.getElementById('page_count').textContent = pdf.numPages;
renderPage(pageNum);
/* // Fetch the first page
var pageNumber = 1;
pdf.getPage(pageNumber).then(function(page) {
console.log('Page loaded');
var scale = 1.5;
var viewport = page.getViewport({scale: scale});
// Prepare canvas using PDF page dimensions
canvas.height = viewport.height;
canvas.width = viewport.width;
// Render PDF page into canvas context
var renderContext = {
canvasContext: context,
viewport: viewport
};
var renderTask = page.render(renderContext);
renderTask.promise.then(function () {
console.log('Page rendered');
});
}); */
}, function (reason) {
// PDF loading error
console.error(reason);
});
}
showPdf() is the function which I called from HTML and sent a decrypted text as an input parameter. My problem is pdf is loaded but not getting displayed. I am not getting the problem. Only the thing is the decrypted string which has unreadable data in some symbols, that pdf is not getting displayed otherwise if the decrypted string is all readable without symbolic patterns that pdf is getting displayed. Please help.
The text was updated successfully, but these errors were encountered:
If you are developing a custom solution, first check the examples at https://github.com/mozilla/pdf.js#learning and search existing issues. If this does not help, please prepare a short well-documented example that demonstrates the problem and make it accessible online on your website, JS Bin, GitHub, etc. before opening a new issue or contacting us in the Matrix room -- keep in mind that just code snippets won't help us troubleshoot the problem.
I have some list of encrypted pdf files. On click of each pdf, it should be decrypted and viewed in pdf.js. I get decrypted pdf file string as output and pass it to display pdf using
**base64 encoded PDF format**
. Below is my code:showPdf()
is the function which I called from HTML and sent a decrypted text as an input parameter. My problem is pdf is loaded but not getting displayed. I am not getting the problem. Only the thing is the decrypted string which has unreadable data in some symbols, that pdf is not getting displayed otherwise if the decrypted string is all readable without symbolic patterns that pdf is getting displayed. Please help.The text was updated successfully, but these errors were encountered: