Add option to not embed fonts in PrintToPdf

Think CEF could benefit from a new feature or capability? Discuss CEF feature requests here.

Add option to not embed fonts in PrintToPdf

Postby AndyB » Fri Apr 28, 2017 9:07 am

Hello,

my users produce about 1000 PDF's each week which are stored on the server, i am looking for a way to minimize the needed disk space.
I tried to remove the font with itext, but this does not work correctly, for ex. bold text gets displayed as normal text then.
Adobe Acrobat cannot un-embed the font at all, the font is not displayed in their pdf optimazition dialog.

It would be great if you can add an option to not embed fonts in the PDF.

Thanks,
Andy
AndyB
Techie
 
Posts: 39
Joined: Sun Apr 16, 2017 3:00 pm

Re: Add option to not embed fonts in PrintToPdf

Postby Czarek » Fri Apr 28, 2017 9:19 am

Are these the fonts embedded on web pages?
Maintainer of the CEF Python, PHP Desktop and CEF C API projects. I'm available for contract work, see my resume.
User avatar
Czarek
Virtuoso
 
Posts: 1829
Joined: Sun Nov 06, 2011 2:12 am

Re: Add option to not embed fonts in PrintToPdf

Postby magreenblatt » Fri Apr 28, 2017 11:02 am

It's unlikely that such a special purpose function will be added. You can build your own CEF/Chromium version with custom changes to PDFium or you can find a way to post-process the PDF files.
magreenblatt
Site Admin
 
Posts: 9831
Joined: Fri May 29, 2009 6:57 pm

Re: Add option to not embed fonts in PrintToPdf

Postby AndyB » Sat Apr 29, 2017 8:29 am

I think the fonts which are used in the web page are generally used in the PDF, at least common fonts.
If i print for ex. this page to PDF:
Code: Select all
<html>
<head>
<style>
body {margin: 0; padding: 0; color: #000000; background-color: #FFFFFF; font-family: Times;}
</style>
</head>
<body>
<div>
Sample Text
</div>
<div style="font-weight: bold">
Sample Bold Text
</div>
</body>
</html>


then i get the attached PrintToPdfTest.pdf with 57KB. The font which is specified in the web page (Times in this sample) gets embedded in the PDF.
If i remove the embedded font with Itext then i get the attached PrintToPdfTest_EmbeddedFontRemovedWithItext.pdf with 4KB.
This post-process would work fine for me, however the text displays not properly with the embedded font removed as you can see in this sample.
Times is a standard font, so i whould think there might be an issue with the way PDFium creates the PDF, but absolutely possible that i am completely wrong with my guess.

Thanks,
Andy
Attachments
PrintToPdfTest_EmbeddedFontRemovedWithItext.pdf
(3.37 KiB) Downloaded 407 times
PrintToPdfTest.pdf
(56.77 KiB) Downloaded 420 times
AndyB
Techie
 
Posts: 39
Joined: Sun Apr 16, 2017 3:00 pm

Re: Add option to not embed fonts in PrintToPdf

Postby Czarek » Sat Apr 29, 2017 9:26 am

Maintainer of the CEF Python, PHP Desktop and CEF C API projects. I'm available for contract work, see my resume.
User avatar
Czarek
Virtuoso
 
Posts: 1829
Joined: Sun Nov 06, 2011 2:12 am

Re: Add option to not embed fonts in PrintToPdf

Postby AndyB » Sat Apr 29, 2017 5:29 pm

Thank you.
I think the problem why in my sample the bold text gets displayed as normal text when the font stream is removed, is because the PDF contains no info about the font weight.

1st font:
Code: Select all
<</Type /Font
/FontDescriptor 9 0 R
/BaseFont /Times#20New#20Roman
/Subtype /CIDFontType2
/CIDToGIDMap /Identity
/CIDSystemInfo <</Registry (Adobe)
/Ordering (Identity)
/Supplement 0>>
/W [0 [777.83203 0 0 250] 54 [556.15234 610.83984] 68 72 443.84766 79 [277.83203 777.83203 0 0 500 0 0 0 277.83203 0 0 0 500]]
/DW 0>>
endobj
9 0 obj
<</Type /FontDescriptor
/FontName /Times#20New#20Roman
/Flags 6
/Ascent 891.11328
/Descent 216.30859
/StemV 0
/CapHeight 662.10938
/ItalicAngle 0
/FontBBox [-568.35938 -306.64063 2045.8984 1039.55078]
/FontFile2 10 0 R>>


2nd font:
Code: Select all
<</Type /Font
/FontDescriptor 14 0 R
/BaseFont /Times#20New#20Roman
/Subtype /CIDFontType2
/CIDToGIDMap /Identity
/CIDSystemInfo <</Registry (Adobe)
/Ordering (Identity)
/Supplement 0>>
/W [0 [777.83203 0 0 250] 37 [666.99219] 54 [556.15234 666.99219] 68 [500 0 0 556.15234 443.84766] 79 [277.83203 833.00781 0 500 556.15234 0 0 0 333.00781 0 0 0 500]]
/DW 0>>
endobj
14 0 obj
<</Type /FontDescriptor
/FontName /Times#20New#20Roman
/Flags 6
/Ascent 891.11328
/Descent 216.30859
/StemV 0
/CapHeight 662.10938
/ItalicAngle 0
/FontBBox [-558.10547 -327.63672 2000 1055.66406]
/FontFile2 15 0 R>>


The FontDescriptor does not contain FontWeight (400=normal, 700=bold). This info is missing, so all text gets displayed as normal text.
Maybe the font stream bytes contain this info, will see if i find some time to look further into this.

Andy
AndyB
Techie
 
Posts: 39
Joined: Sun Apr 16, 2017 3:00 pm

Re: Add option to not embed fonts in PrintToPdf

Postby fddima » Sat Apr 29, 2017 5:58 pm

Andy - font weight is fucking as all about fonts virtual property. Bold font is actually separate font.

I'm understand your problem, and i'm agree that your font hit in standard 14 fonts. On other side: standard fonts doesnt mean same glyphs or same width. So it is question of interchangiabilityblablabla. Pdf is liked by community is ONLY cause it can be printed in sane way.

PDF represent of pre-printed document (it actually very similar or match to PostScript). I.e. it is can't handle layout. This usually means that all PDF without embedded fonts becomes unusable on foreign systems: no matter what standard font is supported: it just *actually* has different glyphs and/or sizes. For pre-printed docs is unacceptable. Even if you still in standard 14 fonts - there is no exist any law to support them.

So... In our time may be easier solve storage size question. Or report format.
fddima
Master
 
Posts: 774
Joined: Tue Dec 07, 2010 6:10 am

Re: Add option to not embed fonts in PrintToPdf

Postby AndyB » Mon May 01, 2017 8:53 am

Thank you for explaining this to me, i was not aware that even the standard fonts are not guaranteed to display exactly identical on all systems.

But our system has created about 1 million PDF reports with no fonts embedded in the past, for internal use and sent to customers (US only), i never noticed an issue.
I would prefer to exclude the fonts, knowing that then there is no 100% guarantee that it displays well on all devices in all countries.

As far i know now, it's not possible (or by far too complicated for me) to un-embed the fonts in a save way.
I see now 3 options for me to solve my size problem.
1) change the CEF/Chromium sources, perhaps there is an easy way to not embed the fonts without destroying the appearance
2) post-process the PDF's at byte level, cut out the font steam bytes for storage and insert the bytes back when the PDF needs to be delivered/displayed.
3) just add more disk space. Not my preferred option, but maybe the cheapest

Thank you all,
Andy
AndyB
Techie
 
Posts: 39
Joined: Sun Apr 16, 2017 3:00 pm

Re: Add option to not embed fonts in PrintToPdf

Postby fddima » Wed May 03, 2017 4:37 pm

@AndyB for me chrome's (Save as PDF) sometimes embeds two fonts (Arial and Times) even if Arial is not used...

Actually i'm think that it is a chrome/pdfium bug or hidden feature. If it is bug - it is should be fixed in upstream, not in CEF. And if it is feature - then... this is should be a way to disable it. So, probably it is more better to ask this question at chrome related groups.

PS: Using "Print to PDF" printer (in Windows it is exist, not sure who it provides) - generates fine documents without embedded fonts (but it is accessible from CEF only via host print dialog which is not automatize).
fddima
Master
 
Posts: 774
Joined: Tue Dec 07, 2010 6:10 am

Re: Add option to not embed fonts in PrintToPdf

Postby AndyB » Thu May 04, 2017 4:59 pm

Perhaps Arial is always embeded if no default font is specified as body style, just a guess.

As far i figured out, the PDFs are created by Skia. In the PDF document properties the PDF Producer is "Skia/PDF m55".
I asked in the Skia forum https://groups.google.com/forum/#!forum/skia-discuss and a very kind guy provided a code change for not embeding fonts.
I will try this, hope i can get CEF compiled in Windows without too much work... and then i must see how it works with CefSharp.....

Yes, i also considered to use the Windows 10 print to pdf, but as you say there is no way to print without user interaction in CEF for Windows.
Is this forum the right place to ask for a silent printing feature, or is this something for the Chromium forum?
I printed a simple PDF created by Skia to "Print to PDF", it looked not bad and the file size was much smaller than the original PDF.
If the Skia code change does not work, maybe i try this strange approach.
AndyB
Techie
 
Posts: 39
Joined: Sun Apr 16, 2017 3:00 pm

Next

Return to Feature Request Forum

Who is online

Users browsing this forum: No registered users and 1 guest