Skip to content

[Bug]: WebContents.print fails with {dpi: {horizontal: 0, vertical: 0}} #39108

@mgalla10

Description

@mgalla10

Preflight Checklist

Electron Version

v25.3.0

What operating system are you using?

Windows

Operating System Version

Windows 10 version 21H2

What arch are you using?

x64

Last Known Working Electron version

v24.6.3

Expected Behavior

We specify a horizontal and vertical DPI of 0 to work around an issue with printing where providing unspecified DPI values seems to result in the lowest available DPI being used, whereas providing unsupported DPI values seems to result in the default DPI being used (#18917 (comment)). In Electron v24, calling webContents.print({ dpi: { horizontal: 0, vertical: 0 } }) doesn't crash and causes the default DPI to be used, as expected.

Actual Behavior

In Electron v25, the webContents.print() call fails if given a DPI with horizontal and vertical sizes of 0. When running from Electron Fiddle, the following message is logged to the console:

[49556:0714/153022.964:ERROR:device_event_log_impl.cc(222)] [15:30:22.964] Printer: print_view_manager_base.cc:352 Printer settings invalid for Microsoft Print to PDF (destination type kLocal): content size is empty; page size is empty; printable area is empty; invalid DPI dimensions

Testcase Gist URL

https://gist.github.com/mgalla10/606893c8c876ff1396a1d87bdc5c0880

Additional Information

No response

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions