As explained in https://www.telerik.com/forums/size-of-pdf-document
RadPdfProcessing does not embed the whole font but instead embeds only the font subset of the used characters which guarantees minimum font size
I want to use a docx as a template for PDF, so from your sample github https://github.com/telerik/document-processing-sdk/tree/master/WordsProcessing/ContentControls
I use Telerik.Windows.Documents.Flow.FormatProviders.Pdf.PdfFormatProvider.ExportToFixedDocument to create a RadFixedDocument
then use Telerik.Windows.Documents.Fixed.FormatProviders.Pdf.PdfFormatProvider to export to final PDF.
The problem is the docx is using non standard font, so when I embed the font set (normal, italic, bold, italic bold) the final PDF size reached 3MB with just simple text and no image. This PDF is definitely embedding the full font sets, not the subset.
Is this scenario unsupported or bug?
I modified your DocumentGenerator.cs in ContentControls_NetStandard project. Must copy the segoeui.ttf and seguili.ttf to the SampleData folder.
//overwrite this
private void Save(RadFlowDocument document)
{
IFormatProvider<RadFlowDocument> formatProvider = new DocxFormatProvider();
string path = "CVTemplate.docx";
using (FileStream stream = File.OpenWrite(path))
{
formatProvider.Export(document, stream);
}
Console.WriteLine("Document generated.");
ProcessStartInfo psi = new ProcessStartInfo()
{
FileName = path,
UseShellExecute = true
};
Process.Start(psi);
//modification
ExportToFixedDocumentPdfFromRadFlowDocumentDocx(document);
}
private void ExportToFixedDocumentPdfFromRadFlowDocumentDocx(RadFlowDocument document)
{
//handle png image for NetStandard
Telerik.Windows.Documents.Extensibility.JpegImageConverterBase jpegImageConverter = new Telerik.Documents.ImageUtils.JpegImageConverter();
Telerik.Windows.Documents.Extensibility.FixedExtensibilityManager.JpegImageConverter = jpegImageConverter;
using (FileStream stream = File.Create("ExportedToFixedDocumentPdfFromRadFlow_with_embeddedFont.pdf"))
{
// Read the font file -- copy these 2 ttf to sample folder
byte[] fontDataNormal = File.ReadAllBytes($"{SampleDataFolder}segoeui.ttf");
byte[] fontDataLight = File.ReadAllBytes($"{SampleDataFolder}seguili.ttf");
// Register the font set
Telerik.Documents.Core.Fonts.FontFamily fontFamily = new Telerik.Documents.Core.Fonts.FontFamily("Segoe UI");
Telerik.Documents.Core.Fonts.FontFamily fontFamily2 = new Telerik.Documents.Core.Fonts.FontFamily("Segoe UI Light");
Telerik.Windows.Documents.Fixed.Model.Fonts.FontsRepository.RegisterFont(
fontFamily,
Telerik.Documents.Core.Fonts.FontStyles.Normal,
Telerik.Documents.Core.Fonts.FontWeights.Normal, fontDataNormal);
Telerik.Windows.Documents.Fixed.Model.Fonts.FontsRepository.RegisterFont(
fontFamily2,
Telerik.Documents.Core.Fonts.FontStyles.Normal,
Telerik.Documents.Core.Fonts.FontWeights.Normal, fontDataLight);
//export the docx RadFlowDocument to RadFixedDocument
var radFixedDocument = (new Telerik.Windows.Documents.Flow.FormatProviders.Pdf.PdfFormatProvider()).ExportToFixedDocument(document);
var fixedFormatProvider = new Telerik.Windows.Documents.Fixed.FormatProviders.Pdf.PdfFormatProvider();
fixedFormatProvider.Export(radFixedDocument, stream);
}
}