Which product are you using?
PDF.js Express Viewer
PDF.js Express Version
UI version | ‘8.7.0’ |
---|---|
Core version | ‘8.7.0’ |
webviewer.min.js | ‘8.7.0’ |
Build | ‘Ny8yMC8yMDIyfDJhMWM5ZWYwOA==’ |
Detailed description of issue
Error when setting language
“setLanguage.js:44 Uncaught (in promise) TypeError: Cannot set properties of undefined (setting ‘i18n’) at setLanguage.js:44:12”
Expected behaviour
Set the language without generating an error.
Does your issue happen with every document, or just one?
Happens with every document, and multiple instances.
Link to document
(Transfer - Dropbox)
Code snippet
ngOnInit() {
this.route.paramMap.subscribe((paramMap: any) => {
if (paramMap.get('bookmark') !== null) {
this.bookmarkName = paramMap.get('bookmark').replace(/%20/g, ' ');
}
});
this.setLanguageDocument();
}
ngAfterViewInit(): void {
WebViewer(
{
path: '../lib',
// initialDoc: '/assets/documents/help/' + this.languageDocument,
initialDoc: '/assets/documents/help/lorem-ipsum.pdf',
licenseKey: 'VMeLR5MsW5lX3X9YfqQF',
css: '/assets/pdf-viewer/pdf-viewer.css',
},
this.viewer.nativeElement
).then((instance: any) => {
const { Core, UI } = instance;
UI.setHeaderItems((header: any) => {
header.getHeader('default').push({
img: 'icon-header-print-line',
index: -1,
type: 'actionButton',
element: 'printButton',
onClick: () => {
instance.UI.print();
},
});
const items = header.getItems().filter((item: any) => item.type !== 'divider');
header.update(items);
});
instance.setFitMode(instance.FitMode.FitWidth);
Core.documentViewer.addEventListener('documentLoaded', () => {
Core.documentViewer
.getDocument()
.getBookmarks()
.then((bookmarks: any) => {
if (this.bookmarkName !== '') {
this.bookmarks = bookmarks;
this.currentBookmark = this.bookmarks.find(
(bookmark: any) => bookmark.name.toLowerCase() === this.bookmarkName.toLocaleLowerCase()
);
if (this.currentBookmark) {
Core.documentViewer.displayBookmark(this.currentBookmark);
}
}
});
UI.setActiveLeftPanel('outlinesPanel');
UI.openElements(['leftPanel']);
console.log(UI);
UI.setLanguage(this.localizationService.currentLaungageCode);
UI.disableElements([
'menuButton',
'leftPanelButton',
'zoomOverlayButton',
'viewControlsButton',
'selectToolButton',
'panToolButton',
'thumbnailsPanelButton',
]);
});
UI.useEmbeddedPrint(true);
});
}
onBack() {
this.location.back();
}
setLanguageDocument() {
switch (this.localizationService.currentLaungageCode) {
case 'en':
this.languageDocument = 'Host Help.pdf';
break;
case 'fr':
this.languageDocument = 'Host Help (fr).pdf';
break;
case 'es':
this.languageDocument = 'Host Help (es).pdf';
break;
case 'de':
this.languageDocument = 'Host Help (de).pdf';
break;
case 'it':
this.languageDocument = 'Host Help (it).pdf';
break;
case 'pt':
this.languageDocument = 'Host Help (pt).pdf';
break;
default:
this.languageDocument = 'Host Help.pdf';
}
}