Skip to content

Commit

Permalink
more
Browse files Browse the repository at this point in the history
  • Loading branch information
johnwhitington committed Aug 17, 2022
1 parent afc6111 commit 636ace2
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 14 deletions.
2 changes: 1 addition & 1 deletion cpdflibtest.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const cpdf = require('./cpdf.js');
const cpdf = require('./coherentpdf.js');

//CHAPTER 0. Preliminaries
console.log("***** CHAPTER 0. Preliminaries");
Expand Down
19 changes: 10 additions & 9 deletions cpdfworker.js
Original file line number Diff line number Diff line change
@@ -1,28 +1,29 @@
importScripts('dist/cpdf.browser.js')
importScripts('dist/coherentpdf.browser.js')

self.onmessage = function(e) {
switch (e.data.mtype)
{
case 'pdf':
//Load the PDF from the array of bytes handed to us by index.html
var pdf = cpdf.fromMemory(e.data.bytes, "");
var pdf = coherentpdf.fromMemory(e.data.bytes, "");
coherentpdf.setFast();
self.postMessage({mtype: 'progress', message: '(1/4) PDF loaded successfully from file ...'});
//Send some metadata back to index.html
self.postMessage({mtype: 'pages', x: cpdf.pages(pdf)});
self.postMessage({mtype: 'creator', x: cpdf.getCreator(pdf)});
self.postMessage({mtype: 'producer', x: cpdf.getProducer(pdf)});
self.postMessage({mtype: 'pages', x: coherentpdf.pages(pdf)});
self.postMessage({mtype: 'creator', x: coherentpdf.getCreator(pdf)});
self.postMessage({mtype: 'producer', x: coherentpdf.getProducer(pdf)});
//If the PDF is encrypted with blank owner password, decrypt it.
cpdf.decryptPdf(pdf, "");
coherentpdf.decryptPdf(pdf, "");
self.postMessage({mtype: 'progress', message: '(2/4) File decrypted if necessary...'});
//Rotate the contents of each page by 10 degrees
cpdf.rotateContents(pdf, cpdf.all(pdf), 10);
coherentpdf.rotateContents(pdf, coherentpdf.all(pdf), 10);
self.postMessage({mtype: 'progress', message: '(3/4) File rotated....'});
//Write the result to a PDF file as an array of bytes
var mem = cpdf.toMemory(pdf, false, false);
var mem = coherentpdf.toMemory(pdf, false, false);
self.postMessage({mtype: 'progress', message: '(4/4) File serialized to memory...'});
//Send the file back to index.html
self.postMessage({mtype: 'pdfout', bytes: mem});
//This worker will be terminated by index.html, so no need to call cpdf.deletePdf
//This worker will be terminated by index.html, so no need to call coherentpdf.deletePdf
break;
}
}
6 changes: 3 additions & 3 deletions index.html
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<!DOCTYPE html>
<html>
<!-- Load cpdf. We only use this for getting the version number. Everything else is done by the cpdfworker.js -->
<script src="dist/cpdf.browser.js"></script>
<script src="dist/coherentpdf.browser.js"></script>

<!-- Script for downloading the resultant file -->
<script>
Expand Down Expand Up @@ -35,7 +35,7 @@

<!-- The page itself -->
<body>
<h1>cpdf.js example</h1>
<h1>coherentpdf.js example</h1>
<p>Choose a PDF file, and this web page will use a web worker to rotate the file 10 degrees, and then prompt you to download it.</p>
<p>This happens entirely within the browser.</p>
<p id="demo"></p>
Expand Down Expand Up @@ -81,7 +81,7 @@ <h3>PDF Information</h3>
}
}

document.getElementById("demo").innerHTML = 'cpdf.js, loaded version: ' + cpdf.version();
document.getElementById("demo").innerHTML = 'coherentpdf.js, loaded version: ' + coherentpdf.version();

ensureFooIsSet(100000).then(function(){
document.getElementById("progress").innerHTML = '(0/4) PDF File loaded from disc. Processing...';
Expand Down
1 change: 0 additions & 1 deletion run
Original file line number Diff line number Diff line change
@@ -1,2 +1 @@
cp dist/cpdf.js .
CAMLPDF_REPRODUCIBLE_IDS=true CPDF_REPRODUCIBLE_DATES=true node cpdflibtest.js

0 comments on commit 636ace2

Please sign in to comment.