The PDF file usually is comprised of 14 standard fonts but sometimes we stumble upon a requirement to use custom fonts for a better presentation of text. The custom fonts can be used with regular text, Watermark stamp, Header/Footer, or within in table object. You may use a single font throughout the document or may consider using a separate font for each object (even individual objects of the same type may have a unique font). In order to support this capability, the recent release of Aspose.PDF Cloud has been upgraded to support this feature.

PDF Processing API

Aspose.PDF Cloud provides the capabilities to create as well as manipulate PDF files. As the APIs are developed as per REST architecture, we can use the API on any platform i.e. Windows, Linux, macOS. Also, you can engage our APIs in a variety of applications including Desktop, Mobile, Web, etc. As per the scope of this article, we are going to use Apsose.PDF Cloud for .NET which is a wrapper around Aspose.PDF Cloud and enables the .NET developers to utilize all PDF processing capabilities within their native .NET application. Now in order to get started with Cloud SDKs. the first step is their installation and related details can be found over How to install Aspose.Cloud SDKs.

Text with Custom Font

The recent release of Aspose.PDF Cloud has supported the capabilities to reference custom font while adding text to PDF files.

cURL

curl -X PUT "https://api.aspose.cloud/v3.0/pdf/MyNewFile.pdf/pages/1/text" -H  "accept: application/json" -H  "authorization: Bearer <JWT Token>" -H  "Content-Type: application/json" -H  "x-aspose-client: Containerize.Swagger" -d "{  \"LineSpacing\": \"FontSize\",  \"WrapMode\": \"ByWords\",  \"HorizontalAlignment\": \"FullJustify\",  \"LeftMargin\": 10,  \"RightMargin\": 10,  \"TopMargin\": 20,  \"BottomMargin\": 20,  \"Rectangle\": {    \"LLX\": 100,    \"LLY\": 600,    \"URX\": 300,    \"URY\": 200  },  \"Rotation\": 10,  \"SubsequentLinesIndent\": 10,  \"VerticalAlignment\": \"Center\",  \"Lines\": [    {      \"HorizontalAlignment\": \"Left\",      \"Segments\": [        {          \"Value\": \"Hello World..\",          \"TextState\": {            \"FontSize\": 18,            \"Font\": \"Arial\",            \"ForegroundColor\": {              \"A\": 0x00,              \"R\": 0x33,              \"G\": 0x33,              \"B\": 0x99            },            \"BackgroundColor\": {              \"A\": 0x00,              \"R\": 0xCC,              \"G\": 0xFF,              \"B\": 0xCC            },            \"FontStyle\": \"Regular\",            \"FontFile\": \"Allura-Regular.otf\"          }        }      ]    }  ]}"

Request URL

https://api.aspose.cloud/v3.0/pdf/MyNewFile.pdf/pages/1/text

C#.NET

Preview of Text with custom font.

Image 1:- Preview of text with a custom font.

Use Custom font during Text replace

The Cloud API provides the capabilities to search text and replace it with a new text segment. During text replacement, we can provide the option to change font formatting including a new Font file.

cURL command

curl -X POST "https://api.aspose.cloud/v3.0/pdf/MyNewFile.pdf/pages/1/text/replace" -H  "accept: application/json" -H  "authorization: Bearer <JWT Token>" -H  "Content-Type: application/json" -H  "x-aspose-client: Containerize.Swagger" -d "{  \"TextReplaces\": [    {      \"OldValue\": \"API\",      \"NewValue\": \".NET SDK\",      \"Regex\": true,      \"TextState\": {        \"FontSize\": 12,        \"Font\": \"Arial\",        \"ForegroundColor\": {          \"A\": 0x00,          \"R\": 0x33,          \"G\": 0x33,          \"B\": 0x99        },        \"BackgroundColor\": {          \"A\": 0x00,          \"R\": 0xCC,          \"G\": 0xFF,          \"B\": 0xCC        },        \"FontStyle\": \"Regular\",        \"FontFile\": \"KaushanScript-Regular.otf\"      },      \"Rect\": {        \"LLX\": 0,        \"LLY\": 0,        \"URX\": 0,        \"URY\": 0      }    }  ],  \"DefaultFont\": \"string\",  \"StartIndex\": 0,  \"CountReplace\": 0}"

Request URL

https://api.aspose.cloud/v3.0/pdf/MyNewFile.pdf/pages/1/text/replace

C#.NET

Preview of Text Replace

Image 2:- Preview of Text replace using a custom font.

The custom font can also be used on Header/Footer, Table, and Stamp objects.

Conclusion

This article has explained the steps on how to use a custom font in PDF while adding new text as well as using custom font when replacing an existing text in a PDF document. Apart from the features stated above, you may explore a plethora of other amazing features explained in the Programmers Guide. Furthermore, please note that our Cloud APIs are published under MIT license and their complete source code can be downloaded from GitHub.

In case you encounter any issues while using the API, please contact us via free customer support services.