Running this sample https://github.com/mono/SkiaSharp/blob/master/samples/Gallery/Shared/Samples/CreatePdfSample.cs which creates a simple two pages PDF file, the created file (under Windows) is about 510KB
Is there any compression setting to get the output PDF file size lighter? 510KB for a two pages PDF with a simple text seems to be somehow heavy... Any hints?
@neodynamic Can you see what Skia produces?
@charlesroddie no, and you?
You could have a look at setting the quality down: https://docs.microsoft.com/en-us/dotnet/api/skiasharp.skdocumentpdfmetadata
We've been reviewing this matter and we can conclude that the concerns about pdf output file size cannot be improved because the following... it seems that Skia (native lib) PDF backend design will embed any font file needed to render the text at the target device. That page states the following:
We can't assume that an arbitrary font will be available at PDF view time, so we embed all fonts in accordance with modern PDF guidelines.
The sample here https://github.com/mono/SkiaSharp/blob/master/samples/Gallery/Shared/Samples/CreatePdfSample.cs will use the default font in the system, which under Windows, it's likely to be Segoe UI which TTF file size is about 900KB
The output PDF file for that simple test where a single text is drawn is about 510KB. That big size for such a simple pdf is because Segoe UI font file is embedded in the file by Skia design. We've made another tests by drawing Chinese text using the Yu Gothic font which file size is about 13MB! and the output pdf file is about 8MB! which confirms that the size is because the font files being embedded. Linked fonts seems not to be supported which could make the pdf output file size smaller.
If no one here has more comments on this matter, then @mattleibow you can close this issue.
You could use HarfBuzz's subsetting to reduce the font's size. Then load that font to produce the PDF. Sadly this isn't supported by HarfBuzzSharp. Yet....
Yes, that could be the only way to reduce pdf output file size...
Looking at the skia code, it seems there is 2 subsetters built in. But, this is disabled because we are not building with either icu or harfbuzz/sfntly.
However, there is a hook that makes subsetting work, but it is not a "public API". But, since it is fairly simple, we might be able to do something. The API hasn't changed much, so it might just be safe to do something.
I'll have a look at what we can do. Can't promise anything as I haven't had a look at exactly how the PDF is constructed, but it seems to only write the fonts when the PDF is closed, so we could potentially add a argument there, or in the metadata in the constructor. They actually have an enum there that allows you to pick either harfbuzz or sfntly. Seems to be not too hard to add one for us, and then we can use _any_ font subsetter.
Started a thing on the skia bugtracker. I want to do this right: https://bugs.chromium.org/p/skia/issues/detail?id=10491
And discussion: https://groups.google.com/g/skia-discuss/c/XIvDEEwZrAM
You could have a look at setting the quality down: https://docs.microsoft.com/en-us/dotnet/api/skiasharp.skdocumentpdfmetadata
Hi @mattleibow. I've tried to set lower EncodingQuality and RasterDpi and they have no impact on the output file at all. It outputs the same file size and quality. Latest SkiaSharp on Windows 10.
Most helpful comment
Started a thing on the skia bugtracker. I want to do this right: https://bugs.chromium.org/p/skia/issues/detail?id=10491
And discussion: https://groups.google.com/g/skia-discuss/c/XIvDEEwZrAM