Aspose.Pdf.Examples.CSharp.AsposePDF.Text.AddText.LoadingFontFromStream C# (CSharp) Method

LoadingFontFromStream() public static method

public static LoadingFontFromStream ( ) : void
return void
        public static void LoadingFontFromStream()
        {
            // ExStart:LoadingFontFromStream
            // The path to the documents directory.
            string dataDir = RunExamples.GetDataDir_AsposePdf_Text();
            string fontFile = "";

            // Load input PDF file
            Document doc = new Document( dataDir + "input.pdf");
            // Create text builder object for first page of document
            TextBuilder textBuilder = new TextBuilder(doc.Pages[1]);
            // Create text fragment with sample string
            TextFragment textFragment = new TextFragment("Hello world");

            if (fontFile != "")
            {
                // Load the TrueType font into stream object
                using (FileStream fontStream = File.OpenRead(fontFile))
                {
                    // Set the font name for text string
                    textFragment.TextState.Font = FontRepository.OpenFont(fontStream, FontTypes.TTF);
                    // Specify the position for Text Fragment
                    textFragment.Position = new Position(10, 10);
                    // Add the text to TextBuilder so that it can be placed over the PDF file
                    textBuilder.AppendText(textFragment);
                }

                dataDir = dataDir + "LoadingFontFromStream_out.pdf";

                // Save resulting PDF document.
                doc.Save(dataDir);
            }
            // ExEnd:LoadingFontFromStream
            Console.WriteLine("\nFont from stream loaded successfully.\nFile saved at " + dataDir);
        }
        public static void AddTextUsingTextParagraph()