Skip to content
This repository has been archived by the owner on Jun 9, 2023. It is now read-only.

Question: printing #1

Open
shestero opened this issue Sep 23, 2019 · 2 comments
Open

Question: printing #1

shestero opened this issue Sep 23, 2019 · 2 comments

Comments

@shestero
Copy link

It's very interesting if it is possible to initiate print process after PDF window open.
(May be using window.print method).
I see no way to print from wasm application, especially from Qt WebAssembly. This looks like a glimpse of solution. Note that Qt can generate PDF itself.

Can you provide some examples how to print PDF?

@jussiniinikoski
Copy link
Owner

Interesting idea! Perhaps one way would be to introduce printing by opening produced PDF in an iframe..

I think printing goes outside the scope of this project at the moment (which is to build a PDF document).

@Jamie0
Copy link

Jamie0 commented Apr 13, 2022

If anyone is looking for a solution to this that works on recent browsers, try the following snippet in the callback:

const blob = new Blob([data], {
    type: 'application/pdf'
});

let iframe = document.createElement('iframe');
iframe.onload = () => {
    setTimeout(() => {
        iframe.contentWindow.print()
    }, 1);
}

iframe.src = URL.createObjectURL(blob);

iframe.style.position = 'fixed';
iframe.style.top = '-150vh';
iframe.style.left = '-150vw';
iframe.style.width = '100vw';
iframe.style.height = '100vh';

document.body.appendChild(iframe);

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

No branches or pull requests

3 participants