stephanrauh / ngx-extended-pdf-viewer

A full-blown PDF viewer for Angular 16, 17, and beyond
https://pdfviewer.net
Apache License 2.0
450 stars 167 forks source link

How can i change baseHref, need for Single page app #2334

Closed ietabhi closed 1 month ago

ietabhi commented 1 month ago

I need your help! How can i change baseHref instead of directly reading from browser?

Describe the bug

I am looking to update baseHref so that i can point child app pdfjs file? For SPA parent app domain is getting picked and baseHref not allowing to set public path for js files

Version info

Demo PDF file NA

stephanrauh commented 1 month ago

Sorry for answering late - I've missed your ticket during my vacations. I'm afraid I don't understand what you're trying to do. Are you looking for pdfDefaultOptions.assetsFolder?

https://pdfviewer.net/extended-pdf-viewer/options A live demo of using a different assets folder is here: https://pdfviewer.net/extended-pdf-viewer/pdfjs-versions (although it seems to be broken at the moment - but the code snippets on the page are still valid).

ietabhi commented 1 month ago

as part of SPA we need to pass /mfes/ from child add, as this is called from parent App,

currently we are updating basehref with this code and no way i can update same.

this.baseHref = this.platformLocation.getBaseHrefFromDOM();

exp : https://abc.xyz.com/portal Child App URL : https://abc.xyz.com/childApp

If i want to use Child app assets inside parent app i need to pass assets like below exp :

https://abc.xyz.com/mfes/childApp/assets/images/1.png

so for SPA if you can allow me to override this value it will be really helpful

stephanrauh commented 1 month ago

This sounds like you're looking for pdfDefaultOptions.assetsFolder. Modifying this property allows you to use an arbitrary folder instead of the default assets folder.

ietabhi commented 1 month ago

This is not just updating assetsFolder as basehref will be always taken by below code

this.baseHref = this.platformLocation.getBaseHrefFromDOM();

so if i have app running with https://abc.xyz.com/123ismybasehref/home.html

and i change assets folder by pdfDefaultOptions.assetsFolder = newassets/images

default path for images will change to /123ismybasehref/newassets/images

for SPA apps we need to access assets from /mfes/123ismybasehref/newassets/images

So there is no way to add /mfes before basehref currently as it will always take from browser url.

This is important change needs to be added for all SPA apps.

stephanrauh commented 1 month ago

Can you send me a reproducuer, please?

This is important change needs to be added for all SPA apps.

Please elaborate. Every application written in React, Vue.js or Angular is an SPA app. Why do you think changing my library improves any application written in React.js or Vue.js?