Custom fonts for Text, Tables, Stamps, Header/Footer in PDF using Cloud API

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 the unique font). In order to support this capability, the recent release of Aspose.PDF Cloud has been upgraded to support this feature.

Text with custom font

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

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 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 replace, 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.