Table of Contents

Class PdfFontEventArgs

Namespace
Syncfusion.Pdf.Parsing
Assembly
Syncfusion.Pdf.Portable.dll

Arguments of Pdf font..

public class PdfFontEventArgs
Inheritance
PdfFontEventArgs
Inherited Members

Examples

FileStream docStream = new FileStream(@"Input.pdf", FileMode.Open, FileAccess.Read);
PdfLoadedDocument doc = new PdfLoadedDocument(docStream);
PdfLoadedTextBoxField textBoxField = doc.Form.Fields[0] as PdfLoadedTextBoxField;
doc.Form.SetDefaultAppearance(false);  
doc.SubstituteFont += Doc_SubstituteFont;
TextBoxField.Text = "syncfusion";      
Save(doc, "Output.pdf");
Close the document
doc.Close(true);
Update Pdf Font event handler
void Doc_SubstituteFont(object sender, PdfFontEventArgs args)
{
  string fontName = args.FontName
 //Create the type face. 
  SKTypeface typeface = SKTypeface.FromFamilyName(fontName, SkiaSharp.SKFontStyleWeight.Light, SkiaSharp.SKFontStyleWidth.Normal, SkiaSharp.SKFontStyleSlant.Upright);
   //Create stream assest using type face. 
  SKStreamAsset typeFaceStream = typeface.OpenStream();
  MemoryStream memoryStream = null;
  if (typeFaceStream != null and typeFaceStream.Length > 0)
  {
     //Create fontData from type face stream. 
     byte[] fontData = new byte[typeFaceStream.Length - 1];
     typeFaceStream.Read(fontData, typeFaceStream.Length);
     typeFaceStream.Dispose();
     //Create the new memory stream from font data. 
    memoryStream = new MemoryStream(fontData);
  }
//set the font stream to the event args. 
  args.FontStream = memoryStream;
}

Properties

FontName

public string FontName { get; }

Property Value

string

FontStream

public Stream FontStream { get; set; }

Property Value

Stream

FontStyle

Get the PDF font style from the arguments

public PdfFontStyle FontStyle { get; }

Property Value

PdfFontStyle

Examples

 FileStream docStream = new FileStream(@"Input.pdf", FileMode.Open, FileAccess.Read);
 PdfLoadedDocument doc = new PdfLoadedDocument(docStream);
 PdfLoadedTextBoxField textBoxField = doc.Form.Fields[0] as PdfLoadedTextBoxField;
 doc.Form.SetDefaultAppearance(false);  
 doc.SubstituteFont += Doc_SubstituteFont;
 TextBoxField.Text = "syncfusion";      
 Save(doc, "Output.pdf");
 Close the document
 doc.Close(true);
 Update Pdf Font event handler
 void Doc_SubstituteFont(object sender, PdfFontEventArgs args)
 {
        string fontName = args.FontName;
        PdfFontStyle fontStyle = args.FontStyle;
        SKFontStyle sKFontStyle = SKFontStyle.Normal;
            if (fontStyle != PdfFontStyle.Regular)
            {
                if (fontStyle == PdfFontStyle.Bold)
                {
                    sKFontStyle = SKFontStyle.Bold;
                }
                else if (fontStyle == PdfFontStyle.Italic)
                {
                    sKFontStyle = SKFontStyle.Italic;
                }
                else if (fontStyle == (PdfFontStyle.Italic | PdfFontStyle.Bold))
                {
                    sKFontStyle = SKFontStyle.BoldItalic;
                }
            }            
            //Create the type face.  
            SKTypeface typeface = SKTypeface.FromFamilyName(fontName, sKFontStyle);
Create stream assest using type face.  
SKStreamAsset typeFaceStream = typeface.OpenStream();
MemoryStream memoryStream = null;
            if (typeFaceStream != null and typeFaceStream.Length > 0)
            {
                //Create fontData from type face stream.  
                byte[] fontData = new byte[typeFaceStream.Length - 1];
typeFaceStream.Read(fontData, typeFaceStream.Length);
                typeFaceStream.Dispose();
                //Create the new memory stream from font data.  
                memoryStream = new MemoryStream(fontData);
            }
            //set the font stream to the event args.  
            args.FontStream = memoryStream;
   }
 //set the font stream to the event args. 
   args.FontStream = memoryStream;
 }