mono / SkiaSharp

SkiaSharp is a cross-platform 2D graphics API for .NET platforms based on Google's Skia Graphics Library. It provides a comprehensive 2D API that can be used across mobile, server and desktop models to render images.
MIT License
4.41k stars 535 forks source link

Enable font subsetting for PDFs through Harfbuzz #2180

Closed bennetbo closed 2 years ago

bennetbo commented 2 years ago

Related issues: #848

PDFs generated with SkiaSharp are very large in size. The root cause of this issue seems to be, that Skia embeds all used fonts inside the document, as stated here.

Fonts contain information for a lot of characters. However most of the time, there is only a small percentage of these characters that is actually needed to display the document correctly. Subsetting these fonts would reduce the size of the font files drastically, which would result in much smaller PDFs.

Looking at Skia`s source code (SkPDFSubsetFont) there seems to be a way to automatically subset all used fonts inside a PDF document with harfbuzz ("SK_PDF_USE_HARFBUZZ_SUBSET"). This line seems to enable the subsetting support.

Other Skia binding libraries (Skiko, Rust-Skia) seem to enable this flag, which results in a much smaller PDFs. I can provide some example PDF files (with and without subsetting) generated with these libraries if someone wants to take a look at it.

Would be great if we could enable this for SkiaSharp. I am not familar with the build system, but there should be a way to specify this flag, right? Maybe here?

By the way, QuestPDF uses SkiaSharp for PDF document generation and smaller pdf file sizes is one of the most requested features, so it would be great to have this.

rnight commented 2 years ago

That's great! I hope so, too.

MarcinZiabek commented 2 years ago

As the author of the QuestPDF library, I really think that this feature would help the entire community. Thank you @Bebo-Maker for creating this feature request.

mattleibow commented 2 years ago

Duplicate of #848