Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open PDF in new window blocked by browser - IOS / Capacitor #2166

Closed
mignam opened this issue Jan 8, 2021 · 5 comments
Closed

Open PDF in new window blocked by browser - IOS / Capacitor #2166

mignam opened this issue Jan 8, 2021 · 5 comments

Comments

@mignam
Copy link

mignam commented Jan 8, 2021

Hello,

pdfMake.createPdf(docDefinition)open() is working fine on browsers but not on ios device. This error is triggered:

Error: Open PDF in new window blocked by browser

I'm working on a webapp using Angular 7 and Capacitor.

I saw many posts about this subject and tested solutions but none is working... => #587

Some says that i have to store PDF in local using cordova fileOpener plugin but i don't want to use cordova :) =>

I just want to generate a pdf and open it in another window. I don't know what can be wrong here:

var win = window.open('', '_blank');
pdfMake.createPdf(documentDefinition).open({}, win);

Also, pdfMake.createPdf(docDefinition).open({}, window) is working but this is not what i want because pdf is open on my webview :)

Sorry if i miss something or if i did something wrong !

@liborm85
Copy link
Collaborator

liborm85 commented Jan 9, 2021

As described in issue #800 on Safari (iOS) for open action is require disabled popup blocker.

@mignam
Copy link
Author

mignam commented Jan 11, 2021

I'm on capacitor, so my app is running inside a webview. I tried to disable "popup blocker" in safari's option. Same problem, i don't know if my problem is related to capacitor or not.

@liborm85
Copy link
Collaborator

Capacitor is not standard browser, this feature is not supported.

@mignam
Copy link
Author

mignam commented Jan 11, 2021

Capacitor is not a browser, it's a framework like Cordova, used to implement web app with ionic. Capacitor is only showing a safari webview. I did some test:

pdfMake.createPdf(docDefinition).open() is working on my device when i access my webapp through Safari, no need to disable popup.

But not working when I start the app through the App icon (capacitor => safari web view).

Anyway, i'll dig out.

Thanks !

@linoleum89
Copy link

hey @mignam, I found a way to download at least for the moment the PDF in the device using pdfmake along with this other solution on this page (using capacitor Filesystem plugin): https://www.pragma.com.co/academia/lecciones/convertir-y-descargar-un-pdf-en-base64-con-iconic-4-y-capacitor, I will leave this sample snippet just for you reference, this is enough to download it:

const pdfDocGenerator = pdfMake.createPdf(docDefinition);
        pdfDocGenerator.getBase64((dataBase64) => {
            const fileName = 'PDF-base64.pdf';
            Filesystem.writeFile({
                path: fileName,
                data: dataBase64,
                directory: FilesystemDirectory.Documents,
                // encoding: FilesystemEncoding.UTF8
            }).then(writeFileResponse => {
                console.log('writeFile success => ', writeFileResponse);
            }, error => {
                console.log('writeFile error => ', error);
            });
        });

if you still have troubles let me know, regards.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants