alexa
menu

    Show / Hide Table of Contents

    Class PdfFontEventArgs

    Arguments of Pdf font..

    Inheritance
    System.Object
    PdfFontEventArgs
    Namespace: Syncfusion.Pdf.Parsing
    Assembly: Syncfusion.Pdf.Portable.dll
    Syntax
    public class PdfFontEventArgs : Object
    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

    Declaration
    public string FontName { get; }
    Property Value
    Type
    System.String

    FontStream

    Declaration
    public Stream FontStream { get; set; }
    Property Value
    Type
    System.IO.Stream

    FontStyle

    Get the PDF font style from the arguments

    Declaration
    public PdfFontStyle FontStyle { get; }
    Property Value
    Type
    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;
    }       
    Back to top Generated by DocFX
    Copyright © 2001 - 2025 Syncfusion Inc. All Rights Reserved