Skip to content

Commit

Permalink
Merge pull request #1 from moesjarraf/master
Browse files Browse the repository at this point in the history
Updated build script and removed patches
  • Loading branch information
tmcdos authored Mar 13, 2017
2 parents 4e74266 + 500f3d0 commit 9c04fae
Show file tree
Hide file tree
Showing 124 changed files with 4,136 additions and 2,677 deletions.
132 changes: 4 additions & 128 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,143 +43,19 @@ Include `viewer.html` using [SSI](http://httpd.apache.org/docs/2.4/howto/ssi.htm

## Upgrading the source

Normally mozilla's PDF js viewer, will only run as standalone. This version is patched so you can include it within a
Normally mozilla's PDF js viewer, will only run as standalone. We forked the project and patched it, so you can include it within a
page.

To update this version, get the pdf.js source code and build the project
To update this version, get the patched pdf.js source code and build the project

git clone https://github.com/mozilla/pdf.js.git
git https://github.com/legalthings/pdf.js.git
cd pdf.js
npm install
node make generic
gulp generic
cd ..

And update the files from source and patch them

cd pdf.js-viewer
npm install
./build.sh ../pdf.js/build/generic/

### Manual patching

When updating to a new minor (or major) version, it's likely than one or more of the chunks can't be applied. This
means you need to do these modifications manually.


#### function getL10nData()

The viewer uses `l10n.js` with a `<link rel="resource" type="application/l10n">` header for internationalization. This
chunk makes using that optional.

function getL10nData(key, args, fallback) {
var data = gL10nData[key];
if (!data) {
- console.warn('#' + key + ' is undefined.');
+ if (Object.keys(gL10nData).length > 0) {
+ console.warn('#' + key + ' is undefined.');
+ }
if (!fallback) {
return null;
}

#### Dynamic paths

The viewer uses relative paths to JavaScript files. This doesn't work when the viewer is embedded on a web page.
Instead the paths are determined based on the path of the current JavaScript file.

-PDFJS.imageResourcesPath = './images/';
- PDFJS.workerSrc = '../build/pdf.worker.js';
- PDFJS.cMapUrl = '../web/cmaps/';
- PDFJS.cMapPacked = true;
+var scriptTagContainer = document.body ||
+ document.getElementsByTagName('head')[0];
+var pdfjsSrc = scriptTagContainer.lastChild.src;
+
+if (pdfjsSrc) {
+ PDFJS.imageResourcesPath = pdfjsSrc.replace(/pdf\.js$/i, 'images/');
+ PDFJS.workerSrc = pdfjsSrc.replace(/pdf\.js$/i, 'pdf.worker.js');
+ PDFJS.cMapUrl = pdfjsSrc.replace(/pdf\.js$/i, 'cmaps/');
+}
+
+PDFJS.cMapPacked = true;

#### Explicitly load a PDF document

The viewer shouldn't start loading a (default) document when it's loaded. Instead we want to expose the initialization,
so it can be called in JavaScript with `PDFJS.webViewerLoad()`.

-document.addEventListener('DOMContentLoaded', webViewerLoad, true);
+// document.addEventListener('DOMContentLoaded', webViewerLoad, true);
+PDFJS.webViewerLoad = function (src) {
+ if (src) DEFAULT_URL = src;
+
+ webViewerLoad();
+}

~~On several places the code assumes that a PDF is loaded, which (because of the explicit load) might not be the case. We
need to check if `pdfDocument` is set before using it.~~ This is fixed in v1.6.210 of PDF.js

~~The pagesCount method for both `PDFViewerApplication` and `PDFLinkService`. Both need to be patched.~~

##### PDFViewerApplication.cleanup()

cleanup: function pdfViewCleanup() {
this.pdfViewer.cleanup();
this.pdfThumbnailViewer.cleanup();
- this.pdfDocument.cleanup();
+ if (this.pdfDocument) {
+ this.pdfDocument.cleanup();
+ }
},

#### overlayManagerRegister

The overlay is registered when the viewer is loaded. The original code will only do this once and give an error on each
subsequent call. Escpecially with single-page applications (eg an Angular app), the viewer may be loaded multiple times.
This patch causes pdf.js to unregister an unusued (closed) overlay.

register: function overlayManagerRegister(name, callerCloseMethod, canForceClose) {
return new Promise(function (resolve) {
var element, container;
if (!name || !(element = document.getElementById(name)) ||
!(container = element.parentNode)) {
throw new Error('Not enough parameters.');
} else if (this.overlays[name]) {
- throw new Error('The overlay is already registered.');
+ if (this.active !== name) {
+ this.unregister(name);
+ } else {
+ throw new Error('The overlay is already registered and active.');
+ }
}

#### webViewerChange trigger on file upload dialog

Whenever a file dialog is used (so with any `<input type="file">` on the page), the file is loaded into the pdf.js
viewer. We don't want this behaviour, so comment it out.

if (!files || files.length === 0) {
return;
}
+ if(evt.target.id == PDFViewerApplication.appConfig.openFileInputName)
eventBus.dispatch('fileinputchange', { fileInput: evt.target });
});
}


#### handleMouseWheel()

~~The JavaScript pdf.js file might be loaded while the viewer isn't being displayed. This causes an error on mouse move.
We need to check if the viewer is initialized, before handling the event.~~ There is no such function in v1.6.210 of PDF.js

#### Load code for worker using AJAX if needed

This has been fixed in v1.6.210 of PDF.js

A [Web Worker](https://developer.mozilla.org/en-US/docs/Web/API/Web_Workers_API/Using_web_workers) ~~can't use code from
a same-origin domain. The CORS headers don't apply.~~

~~The patch will cause pdf.js to first try to create the Worker the regular way, with a URL to the JavaScript source. If
this fails, the source is fetched using AJAX and used to create an~~
[object url](https://developer.mozilla.org/en-US/docs/Web/API/URL/createObjectURL). ~~If this also fails, pdf.js will go
onto it's last resort by calling `setupFakeWorker()`.~~
9 changes: 3 additions & 6 deletions build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -13,18 +13,15 @@ if [[ ! -f "$source/build/pdf.js" ]]; then
fi

cat "$source/web/l10n.js" "$source/build/pdf.js" "$source/web/debugger.js" "$source/web/viewer.js" > pdf.js
patch -u pdf.js < pdf.js.patch

cp "$source/build/pdf.worker.js" .
#patch pdf.worker.js < pdf.worker.js.patch

cat "$source/web/viewer.html" | tr '\n' '\f' | sed -r 's/^.+<body [^>]*>/<pdfjs-wrapper>/' | sed -r 's/<\/body>.+$/<\/pdfjs-wrapper>/' | tr '\f' '\n' > ./viewer.html

uglifycss "$source/web/viewer.css" > viewer.css
node node_modules/uglifycss/uglifycss "$source/web/viewer.css" > viewer.css
node grunt/css-prefix.js viewer.css viewer.css pdfjs
cat viewer-overwrites.css >> viewer.css;

sed -r 's/url\((")?images\//url\(\1@pdfjsImagePath\//g' < "$source/web/viewer.css" | uglifycss > viewer.less
node grunt/css-prefix.js viewer.less viewer.less pdfjs
sed -r 's/url\((")?images\//url\(\1@pdfjsImagePath\//g' < viewer.css > viewer.less

cp "$source/web/cmaps/" "$source/web/images/" "$source/web/locale/" . -a

Binary file modified images/texture.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified images/toolbarButton-menuArrows.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified images/[email protected]
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified images/[email protected]
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added images/treeitem-collapsed-rtl.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added images/[email protected]
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added images/treeitem-collapsed.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added images/[email protected]
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added images/treeitem-expanded.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added images/[email protected]
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
36 changes: 25 additions & 11 deletions locale/ach/viewer.properties
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,15 @@ previous_label=Mukato
next.title=Pot buk malubo
next_label=Malubo

# LOCALIZATION NOTE (page_label, page_of):
# These strings are concatenated to form the "Page: X of Y" string.
# Do not translate "{{pageCount}}", it will be substituted with a number
# representing the total number of pages.
page_label=Pot buk:
page_of=pi {{pageCount}}
# LOCALIZATION NOTE (page.title): The tooltip for the pageNumber input.
page.title=Pot buk
# LOCALIZATION NOTE (of_pages): "{{pagesCount}}" will be replaced by a number
# representing the total number of pages in the document.
of_pages=pi {{pagesCount}}
# LOCALIZATION NOTE (page_of_pages): "{{pageNumber}}" and "{{pagesCount}}"
# will be replaced by a number representing the currently visible page,
# respectively a number representing the total number of pages in the document.
page_of_pages=({{pageNumber}} me {{pagesCount}})

zoom_out.title=Jwik Matidi
zoom_out_label=Jwik Matidi
Expand Down Expand Up @@ -67,28 +70,39 @@ document_properties.title=Jami me gin acoya…
document_properties_label=Jami me gin acoya…
document_properties_file_name=Nying pwail:
document_properties_file_size=Dit pa pwail:
# LOCALIZATION NOTE (document_properties_kb): "{{size_kb}}" and "{{size_b}}"
# will be replaced by the PDF file size in kilobytes, respectively in bytes.
document_properties_kb={{size_kb}} KB ({{size_b}} bytes)
# LOCALIZATION NOTE (document_properties_mb): "{{size_mb}}" and "{{size_b}}"
# will be replaced by the PDF file size in megabytes, respectively in bytes.
document_properties_mb={{size_mb}} MB ({{size_b}} bytes)
document_properties_title=Wiye:
document_properties_author=Ngat mucoyo:
document_properties_subject=Lok:
document_properties_keywords=Lok mapire tek:
document_properties_creation_date=Nino dwe me cwec:
document_properties_modification_date=Nino dwe me yub:
# LOCALIZATION NOTE (document_properties_date_string): "{{date}}" and "{{time}}"
# will be replaced by the creation/modification date, and time, of the PDF file.
document_properties_date_string={{date}}, {{time}}
document_properties_creator=Lacwec:
document_properties_producer=Layub PDF:
document_properties_version=Kit PDF:
document_properties_page_count=Kwan me pot buk:
document_properties_close=Lor

print_progress_message=Yubo coc me agoya…
# LOCALIZATION NOTE (print_progress_percent): "{{progress}}" will be replaced by
# a numerical per cent value.
print_progress_percent={{progress}}%
print_progress_close=Juki

# Tooltips and alt text for side panel toolbar buttons
# (the _label strings are alt text for the buttons, the .title strings are
# tooltips)
toggle_sidebar.title=Lok gintic ma inget
toggle_sidebar_label=Lok gintic ma inget
outline.title=Nyut rek pa gin acoya
outline_label=Pek pa gin acoya
document_outline_label=Pek pa gin acoya
attachments.title=Nyut twec
attachments_label=Twec
thumbs.title=Nyut cal
Expand Down Expand Up @@ -149,7 +163,7 @@ loading_error_indicator=Bal
loading_error=Bal otime kun cano PDF.
invalid_file_error=Pwail me PDF ma pe atir onyo obale woko.
missing_file_error=Pwail me PDF tye ka rem.
unexpected_response_error=Lagam mape kigeno pa lapok tic
unexpected_response_error=Lagam mape kigeno pa lapok tic.

# LOCALIZATION NOTE (text_annotation_type.alt): This is used as a tooltip.
# "{{type}}" will be replaced with an annotation type from a list defined in
Expand All @@ -159,9 +173,9 @@ text_annotation_type.alt=[{{type}} Lok angea manok]
password_label=Ket mung me donyo me yabo pwail me PDF man.
password_invalid=Mung me donyo pe atir. Tim ber i tem doki.
password_ok=OK
password_cancel=Juk
password_cancel=Juki

printing_not_supported=Ciko: Layeny ma pe teno goyo liweng.
printing_not_ready=Ciko: PDF pe ocane weng me agoya.
web_fonts_disabled=Kijuko dit pa coc me kakube woko: pe romo tic ki dit pa coc me PDF ma kiketo i kine.
document_colors_disabled=Pe ki ye ki gin acoya me PDF me tic ki rangi gi kengi: 'Ye pot buk me yero rangi mamegi kengi' kijuko woko i layeny.
document_colors_not_allowed=Pe ki yee ki gin acoya me PDF me tic ki rangi gi kengi: Kijuko woko “Yee pot buk me yero rangi mamegi kengi” ki i layeny.
35 changes: 25 additions & 10 deletions locale/af/viewer.properties
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,15 @@ previous_label=Vorige
next.title=Volgende bladsy
next_label=Volgende

# LOCALIZATION NOTE (page_label, page_of):
# These strings are concatenated to form the "Page: X of Y" string.
# Do not translate "{{pageCount}}", it will be substituted with a number
# representing the total number of pages.
page_label=Bladsy:
page_of=van {{pageCount}}
# LOCALIZATION NOTE (page.title): The tooltip for the pageNumber input.
page.title=Bladsy
# LOCALIZATION NOTE (of_pages): "{{pagesCount}}" will be replaced by a number
# representing the total number of pages in the document.
of_pages=van {{pagesCount}}
# LOCALIZATION NOTE (page_of_pages): "{{pageNumber}}" and "{{pagesCount}}"
# will be replaced by a number representing the currently visible page,
# respectively a number representing the total number of pages in the document.
page_of_pages=({{pageNumber}} van {{pagesCount}})

zoom_out.title=Zoem uit
zoom_out_label=Zoem uit
Expand Down Expand Up @@ -67,28 +70,40 @@ document_properties.title=Dokumenteienskappe…
document_properties_label=Dokumenteienskappe…
document_properties_file_name=Lêernaam:
document_properties_file_size=Lêergrootte:
# LOCALIZATION NOTE (document_properties_kb): "{{size_kb}}" and "{{size_b}}"
# will be replaced by the PDF file size in kilobytes, respectively in bytes.
document_properties_kb={{size_kb}} kG ({{size_b}} grepe)
# LOCALIZATION NOTE (document_properties_mb): "{{size_mb}}" and "{{size_b}}"
# will be replaced by the PDF file size in megabytes, respectively in bytes.
document_properties_mb={{size_mb}} MG ({{size_b}} grepe)
document_properties_title=Titel:
document_properties_author=Outeur:
document_properties_subject=Onderwerp:
document_properties_keywords=Sleutelwoorde:
document_properties_creation_date=Skeppingsdatum:
document_properties_modification_date=Wysigingsdatum:
# LOCALIZATION NOTE (document_properties_date_string): "{{date}}" and "{{time}}"
# will be replaced by the creation/modification date, and time, of the PDF file.
document_properties_date_string={{date}}, {{time}}
document_properties_creator=Skepper:
document_properties_producer=PDF-vervaardiger:
document_properties_version=PDF-weergawe:
document_properties_page_count=Aantal bladsye:
document_properties_close=Sluit

print_progress_message=Berei tans dokument voor om te druk…
# LOCALIZATION NOTE (print_progress_percent): "{{progress}}" will be replaced by
# a numerical per cent value.
print_progress_percent={{progress}}%
print_progress_close=Kanselleer

# Tooltips and alt text for side panel toolbar buttons
# (the _label strings are alt text for the buttons, the .title strings are
# tooltips)
toggle_sidebar.title=Sypaneel aan/af
toggle_sidebar_label=Sypaneel aan/af
outline.title=Wys dokumentoorsig
outline_label=Dokumentoorsig
document_outline.title=Wys dokumentskema (dubbelklik om alle items oop/toe te vou)
document_outline_label=Dokumentoorsig
attachments.title=Wys aanhegsels
attachments_label=Aanhegsels
thumbs.title=Wys duimnaels
Expand Down Expand Up @@ -155,7 +170,7 @@ unexpected_response_error=Onverwagse antwoord van bediener.
# "{{type}}" will be replaced with an annotation type from a list defined in
# the PDF spec (32000-1:2008 Table 169 – Annotation types).
# Some common types are e.g.: "Check", "Text", "Comment", "Note"
text_annotation_type.alt=[{{type}}-annotasie
text_annotation_type.alt=[{{type}}-annotasie]
password_label=Gee die wagwoord om dié PDF-lêer mee te open.
password_invalid=Ongeldige wagwoord. Probeer gerus weer.
password_ok=OK
Expand All @@ -164,4 +179,4 @@ password_cancel=Kanselleer
printing_not_supported=Waarskuwing: Dié blaaier ondersteun nie drukwerk ten volle nie.
printing_not_ready=Waarskuwing: Die PDF is nog nie volledig gelaai vir drukwerk nie.
web_fonts_disabled=Webfonte is gedeaktiveer: kan nie PDF-fonte wat ingebed is, gebruik nie.
document_colors_disabled=PDF-dokumente word nie toegelaat om hul eie kleure te gebruik nie: 'Laat bladsye toe om hul eie kleure te kies' is gedeaktiveer in die blaaier.
document_colors_not_allowed=PDF-dokumente word nie toegelaat om hul eie kleure te gebruik nie: Laat bladsye toe om hul eie kleure te kies is gedeaktiveer in die blaaier.
29 changes: 19 additions & 10 deletions locale/ak/viewer.properties
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,12 @@ previous_label=Ekyiri-baako
next.title=Krataafa a edi so baako
next_label=Dea-ɛ-di-so-baako

# LOCALIZATION NOTE (page_label, page_of):
# These strings are concatenated to form the "Page: X of Y" string.
# Do not translate "{{pageCount}}", it will be substituted with a number
# representing the total number of pages.
page_label=Krataafa:
page_of=wɔ {{pageCount}}
# LOCALIZATION NOTE (page.title): The tooltip for the pageNumber input.
# LOCALIZATION NOTE (of_pages): "{{pagesCount}}" will be replaced by a number
# representing the total number of pages in the document.
# LOCALIZATION NOTE (page_of_pages): "{{pageNumber}}" and "{{pagesCount}}"
# will be replaced by a number representing the currently visible page,
# respectively a number representing the total number of pages in the document.

zoom_out.title=Zuum pue
zoom_out_label=Zuum ba abɔnten
Expand All @@ -45,15 +45,23 @@ bookmark_label=Seisei nhwɛ


# Document properties dialog box
# LOCALIZATION NOTE (document_properties_kb): "{{size_kb}}" and "{{size_b}}"
# will be replaced by the PDF file size in kilobytes, respectively in bytes.
# LOCALIZATION NOTE (document_properties_mb): "{{size_mb}}" and "{{size_b}}"
# will be replaced by the PDF file size in megabytes, respectively in bytes.
document_properties_title=Ti asɛm:
# LOCALIZATION NOTE (document_properties_date_string): "{{date}}" and "{{time}}"
# will be replaced by the creation/modification date, and time, of the PDF file.

# LOCALIZATION NOTE (print_progress_percent): "{{progress}}" will be replaced by
# a numerical per cent value.

# Tooltips and alt text for side panel toolbar buttons
# (the _label strings are alt text for the buttons, the .title strings are
# tooltips)
toggle_sidebar.title=Sɔ anaaso dum saedbaa
toggle_sidebar_label=Sɔ anaaso dum saedbaa
outline.title=Kyerɛ dɔkomɛnt bɔbea
outline_label=Dɔkomɛnt bɔbea
document_outline_label=Dɔkomɛnt bɔbea
thumbs.title=Kyerɛ mfoniwaa
thumbs_label=Mfoniwaa
findbar.title=Hu wɔ dɔkomɛnt no mu
Expand Down Expand Up @@ -102,6 +110,8 @@ page_scale_width=Krataafa tɛtrɛtɛ
page_scale_fit=Krataafa ehimtwa
page_scale_auto=Zuum otomatik
page_scale_actual=Kɛseyɛ ankasa
# LOCALIZATION NOTE (page_scale_percent): "{{scale}}" will be replaced by a
# numerical scale value.

# Loading indicator messages
loading_error_indicator=Mfomso
Expand All @@ -115,9 +125,8 @@ missing_file_error=PDF fael no ayera.
# Some common types are e.g.: "Check", "Text", "Comment", "Note"
text_annotation_type.alt=[{{type}} Tɛkst-nyiano]
password_ok=OK
password_cancel=Twa-mu

printing_not_supported=Kɔkɔbɔ: Brawsa yi nnhyɛ daa mma prent ho kwan.
printing_not_ready=Kɔkɔbɔ: Wɔnntwee PDF fael no nyinara mmbaee ama wo ɛ tumi aprente.
web_fonts_disabled=Ɔedum wɛb-mfɔnt: nntumi mmfa PDF mfɔnt a wɔhyɛ mu nndi dwuma.
document_colors_disabled=Wɔmma ho kwan sɛ PDF adɔkomɛnt de wɔn ara wɔn ahosu bɛdi dwuma: wɔ adum 'Ma ho kwan ma nkrataafa mpaw wɔn ara wɔn ahosu' wɔ brawsa yi mu.
document_colors_not_allowed=Wɔmma ho kwan sɛ PDF adɔkomɛnt de wɔn ara wɔn ahosu bɛdi dwuma: wɔ adum 'Ma ho kwan ma nkrataafa mpaw wɔn ara wɔn ahosu' wɔ brawsa yi mu.
Loading

0 comments on commit 9c04fae

Please sign in to comment.