We're sorry Aspose doesn't work properply without JavaScript enabled.

Free Support Forum - aspose.com

Adding text to PDF is not working. The text does not appear in the PDF

I’m trying to figure out how to add text to a PDF document. I’ve created a fresh C# dotnet core console application and copied one of the samples from the Aspose.PDF documentation. The sample I copied is below …

using System;

using Aspose.Pdf;
using Aspose.Pdf.Text;

namespace ConsoleApp1
    class Program
        static void Main(string[] args)
            // Create new document object
            Document pdfDocument = new Document();

            // Get particular page
            Page pdfPage = (Page)pdfDocument.Pages.Add();

            // Create text fragment
            TextFragment textFragment = new TextFragment("main text");
            textFragment.Position = new Position(100, 600);

            // Set text properties
            textFragment.TextState.FontSize = 12;
            textFragment.TextState.Font = FontRepository.FindFont("TimesNewRoman");
            textFragment.TextState.BackgroundColor = Aspose.Pdf.Color.LightGray;
            textFragment.TextState.ForegroundColor = Aspose.Pdf.Color.Red;

            // Set StrokingColor property for drawing border (stroking) around text rectangle
            textFragment.TextState.StrokingColor = Aspose.Pdf.Color.DarkRed;

            // Set DrawTextRectangleBorder property value to true
            textFragment.TextState.DrawTextRectangleBorder = true;

            TextBuilder tb = new TextBuilder(pdfPage);

            // Save the document

This produces a blank PDF and I see no text anywhere. I attached the PDF it created to this post, as well.

I’m using Aspose.PDF version 19.2.0. I’m running this on Windows 10.

Why isn’t the text appearing? Does anybody see something I’m doing incorrectly?

test.pdf (64.8 KB)

Looks like 19.2 is not compatible with .Net Core 3. Looks like 19.10 added .NET Core 3 support.

Aspose.PDF for .NET 19.10 Release Notes | Aspose.PDF for .NET


Yes, the .NET Core 3.0 support was added in 19.10 version of the API. Also, please note that we always recommend using the latest version of the API as it contains maximum features and enhancements. Please try to use it and let us know in case you face any issues.