-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
afc6111
commit 636ace2
Showing
4 changed files
with
14 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |