From 65ff3d8ed4009d61185870043a878305f550722a Mon Sep 17 00:00:00 2001 From: ismailbennani Date: Thu, 24 Apr 2025 12:20:08 +0200 Subject: [PATCH] fix: use base href when getting pdf worker --- .../src/app/app.component.ts | 15 +++++++++++++-- .../components/editor-menu/editor-menu.service.ts | 4 ---- 2 files changed, 13 insertions(+), 6 deletions(-) diff --git a/src/FacturXDotNet.WebEditor/src/app/app.component.ts b/src/FacturXDotNet.WebEditor/src/app/app.component.ts index 7c31abe2..79879697 100644 --- a/src/FacturXDotNet.WebEditor/src/app/app.component.ts +++ b/src/FacturXDotNet.WebEditor/src/app/app.component.ts @@ -1,8 +1,10 @@ -import { Component } from '@angular/core'; +import { Component, inject } from '@angular/core'; import { RouterOutlet } from '@angular/router'; import { ToasterComponent } from './core/toasts/toaster.component'; import { ImportFileComponent } from './core/import-file/import-file.component'; import { NgbTooltipConfigComponent } from './core/ng-bootstrap/ngb-tooltip-config.component'; +import * as pdf from 'pdfjs-dist'; +import { PlatformLocation } from '@angular/common'; @Component({ selector: 'app-root', @@ -16,4 +18,13 @@ import { NgbTooltipConfigComponent } from './core/ng-bootstrap/ngb-tooltip-confi `, styles: [], }) -export class AppComponent {} +export class AppComponent { + constructor() { + const platformLocation = inject(PlatformLocation); + pdf.GlobalWorkerOptions.workerSrc = trimEnd(platformLocation.getBaseHrefFromDOM(), '/') + '/pdf.worker.min.mjs'; + } +} + +function trimEnd(str: string, end: string) { + return str.endsWith(end) ? str.substring(0, str.length - end.length) : str; +} diff --git a/src/FacturXDotNet.WebEditor/src/app/features/editor/components/editor-menu/editor-menu.service.ts b/src/FacturXDotNet.WebEditor/src/app/features/editor/components/editor-menu/editor-menu.service.ts index bf40144e..bb39b1ef 100644 --- a/src/FacturXDotNet.WebEditor/src/app/features/editor/components/editor-menu/editor-menu.service.ts +++ b/src/FacturXDotNet.WebEditor/src/app/features/editor/components/editor-menu/editor-menu.service.ts @@ -40,10 +40,6 @@ export class EditorMenuService { private isExportingInternal = signal(false); - constructor() { - pdf.GlobalWorkerOptions.workerSrc = '/pdf.worker.min.mjs'; - } - async backToWelcomePage(): Promise { this.isImportingInternal.set(true); try {