printing on windows?

91 views
Skip to first unread message

Noel Grandin

unread,
Jul 3, 2025, 2:34:33 AMJul 3
to skia-discuss
Hi

There is a comment in my source code (LibreOffice) that says that skia surfaces don't work for printing.

Anybody know anything about this? Possibly an old restriction?

Thanks, Noel Grandin

bungeman

unread,
Jul 21, 2025, 11:22:58 AMJul 21
to skia-discuss
It is quite difficult to say without more information. This is somewhat true, as the SkPDF equivalent of a SkSurface is an SkDocument (or SkPDFDocument). That is to say, SkSurface and SkDocument are ways to obtain an SkCanvas to draw into. SkSurface is very "pixels" based. That being said, drawing a surface into an SkDocument (SkSurface::makeImageSnapshot and SkCanvas::drawImage) should work, but this will be like drawing any bitmap image.

Noel Grandin

unread,
Jul 21, 2025, 12:47:04 PMJul 21
to skia-discuss
On Monday, July 21, 2025 at 5:22:58 PM UTC+2 bungeman wrote:
It is quite difficult to say without more information.

So possibly to ask in a different way : This is on Microsoft Windows, if I create a handle to a printer DC with CreateDCW, can I pass that to skia and expect it to work?

Or does Chrome use something other than skia to generate printer output?

Or possibly Chrome uses a different windows API to get a different kind of handle?

Thanks, Noel Grandin




bungeman

unread,
Jul 21, 2025, 2:00:39 PMJul 21
to skia-discuss
No, Skia does not have a SkCanvas GDI backend, so there is no way to draw into an HDC/GDI/EMF (there is no API to pass the HDC to in Skia). When Chrome prints it always creates a PDF (using SkPDF). When printing this PDF to a printer on Windows, it is Pdfium that can output the PDF as EMF (or one of the other formats it supports). The format Pdfium uses for printing defaults to EMF and is set through (on the Chromium side) PDFiumEngineExports::SetPDFUsePrintMode https://source.chromium.org/chromium/chromium/src/+/main:pdf/pdfium/pdfium_engine_exports.cc;l=182;drc=d0cdb873a9f5d9b6ef2696f65cdd80b619240b14 .

Note this is why it is always incorrect to attempt to use something like Distiller when printing with Chrome. When doing so, one is creating a PDF, translating the PDF into GDI/EMF, then attempting to create a PDF from that. This is always information lossy. Approaches like Distiller work well with applications that drew with GDI anyway and then just drew into the print HDC. But Chrome very much does not work like that.

Skia does have an XPS backend, but it is quite limited, not tested much, and has known issues which aren't being worked on, mostly due to staffing, priorities, and interest.

Noel Grandin

unread,
Jul 21, 2025, 2:29:11 PMJul 21
to skia-discuss

Thanks, that is useful to know.

K. Moon

unread,
Jul 22, 2025, 3:57:42 PMJul 22
to skia-d...@googlegroups.com
Questions about what Chrome does probably would be better directed to the chromium-dev group. (Or maybe there's a printing-specific group?)

I used to work on Chrome printing, but I don't remember exactly what we do on Windows. I think it involves metafiles, though, and I don't think Skia is involved directly.

--
You received this message because you are subscribed to the Google Groups "skia-discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to skia-discuss...@googlegroups.com.
To view this discussion visit https://groups.google.com/d/msgid/skia-discuss/ee3e5c24-ae3c-4a4e-bf5d-c976a9f490c6n%40googlegroups.com.
Reply all
Reply to author
Forward
0 new messages