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

[Bug]: webContents.print() not working correctly #28828

Closed
3 tasks done
antiochtech opened this issue Apr 24, 2021 · 3 comments
Closed
3 tasks done

[Bug]: webContents.print() not working correctly #28828

antiochtech opened this issue Apr 24, 2021 · 3 comments

Comments

@antiochtech
Copy link

Preflight Checklist

Electron Version

11.2.3

What operating system are you using?

Ubuntu

Operating System Version

18.04

What arch are you using?

x64

Last Known Working Electron version

No response

Expected Behavior

expected to print to hardware printers, as well as virtual printers, with margins and any other options as specified.

Actual Behavior

does not print to hardware printer. instead device perpetually indicates that it is processing data.

prints to virtual pdf printer, ignoring specified options such as margintype and margins when margintype is custom.

Testcase Gist URL

No response

Additional Information

<!DOCTYPE html>
<html>
    <head>
        <meta charset="UTF-8">
    </head>
    <body>
        <div style="position: absolute; top: 0in; left: 0in;">0</div>
        <div style="position: absolute; top: 0in; left: 1in;">1</div>
        <div style="position: absolute; top: 0in; left: 2in;">2</div>
        <div style="position: absolute; top: 0in; left: 3in;">3</div>
        <div style="position: absolute; top: 0in; left: 4in;">4</div>
        <div style="position: absolute; top: 0in; left: 5in;">5</div>
        <div style="position: absolute; top: 0in; left: 6in;">6</div>
        <div style="position: absolute; top: 0in; left: 6.5in;">6.5</div>

        <div style="position: absolute; top: 0in; left: 0in;">0</div>
        <div style="position: absolute; top: 1in; left: 0in;">1</div>
        <div style="position: absolute; top: 2in; left: 0in;">2</div>
        <div style="position: absolute; top: 3in; left: 0in;">3</div>
        <div style="position: absolute; top: 4in; left: 0in;">4</div>
        <div style="position: absolute; top: 5in; left: 0in;">5</div>
        <div style="position: absolute; top: 6in; left: 0in;">6</div>
        <div style="position: absolute; top: 7in; left: 0in;">7</div>
        <div style="position: absolute; top: 8in; left: 0in;">8</div>
        <div style="position: absolute; top: 9in; left: 0in;">9</div>
    </body>
    <script>
        document.addEventListener("DOMContentLoaded", function () {
            let win = BrowserWindow.getFocusedWindow();
            var options = {
                color: false,
                dpi: {
                    horizontal: 300,
                    vertical: 300
                },
                margins: {
                    marginType: "custom",
                    top: 300,
                    bottom: 300,
                    left: 300,
                    right: 300
                },
                pageSize: "Letter"
            };

            win.webContents.print(options, (success, failureReason) => {
                if (!success) console.log(failureReason);
                console.log('Print Initiated');
            });
        });
    </script>
</html>
@abnerlee
Copy link

abnerlee commented Jul 20, 2021

I met the same issue on 13.1.7 on Ubuntu

Message is "libva error: va_getDriverName() failed with unknown libva error,driver_name=(null)"

may relates intel/libva#278

execute "window.print()" directly in rendered works, though.

@antiochtech
Copy link
Author

antiochtech commented Jul 20, 2021

i eventually used printToPDF(), PDFJS and then the pdf-to-printer module to both workaround it and provide a preview.

@codebytere
Copy link
Member

Closing as this should be working in latest supported versions.

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

No branches or pull requests

4 participants