Unplanned
Last Updated: 08 Jan 2021 08:19 by ADMIN
Fadi
Created on: 21 Dec 2020 18:11
Category: PdfProcessing
Type: Feature Request
11
PdfProcessing: Provide a mechanism to reuse an already embedded font when merging documents with the PdfStreamWriter

When merging documents containing the same embedded font every time a document is merged the same font is repeatedly embedded in the merged document. This leads to very large files.

A possible workaround before this feature is developed could be to use the PdfProcessing model to import and merge the documents. After the documents are merged to iterate the document`s content in order to cache the fonts using their name and if there are duplicated names to set the already cached one (check the attached project). 

As a side note, the suggested workaround doesn't cover all possible cases (e.g. if there are fonts with a common name but different font sets (modified fonts or font subsets) this may lead to missing/different characters in the produced document). So in order to use this workaround, you will need to ensure the font names are unique for every different font.

4 comments
ADMIN
Martin
Posted on: 08 Jan 2021 08:19

Hello Fadi,

If I understood you right this workaround solves your case. I am happy to hear this.

On the other hand, if you need to cache the fonts of TextBoxFields content (if not flatten) you can iterate the FormFields and apply the same logic:

foreach (FormField field in mergedDocument.AcroForm.FormFields)
{
	if (field is TextBoxField textBoxField)
	{
		if (fontNameToFont.TryGetValue(textBoxField.TextProperties.Font.Name, out FontBase font))
		{
			textBoxField.TextProperties.Font = font;
		}
		else
		{
			fontNameToFont[textBoxField.TextProperties.Font.Name] = textBoxField.TextProperties.Font;
		}
	}
}

Regards,
Martin
Progress Telerik

Virtual Classroom, the free self-paced technical training that gets you up to speed with Telerik and Kendo UI products quickly just got a fresh new look + new and improved content including a brand new Blazor course! Check it out at https://learn.telerik.com/.

Fadi
Posted on: 07 Jan 2021 21:24

This actually works quite well.

I did have to check if the content was a Form and include the FormSource.Content items, since they also contain TextFragement which initially made me think this was not working. Our PDF's are forms initially, then flattened, perhaps that is why this was not apparent in the example.

ADMIN
Martin
Posted on: 07 Jan 2021 11:06

Hi Fadi,

I updated the feature request with a project that demonstrates a possible workaround using the PdfProcessing model until the feature is developed. I hope it could be a solution to your scenario.

The functionality for comparing fonts in order to skip the duplicates is complicated and could lead to a performance hit. Therefore, this feature request is still not implemented. I want to apologize for the inconvenience this missing functionality might be causing you.

Regards,
Martin
Progress Telerik

Virtual Classroom, the free self-paced technical training that gets you up to speed with Telerik and Kendo UI products quickly just got a fresh new look + new and improved content including a brand new Blazor course! Check it out at https://learn.telerik.com/.

Fadi
Posted on: 06 Jan 2021 15:38
This defect is preventing the use of the PDF component in our product at this time.