The PDF file typically includes 14 standard fonts, but many projects require custom fonts for better text presentation. Custom fonts can be applied to regular text, watermark stamps, headers/footers, or table objects. You may use a single font throughout the document or assign different fonts to each object (even individual objects of the same type can have unique fonts). To support this, the latest release of Aspose.PDF Cloud now includes custom‑font capabilities.
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 Aspose.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 added support for referencing custom fonts 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
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, you can specify new font formatting, including a custom 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
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 explained how to use a custom font in PDF files when adding new text and when replacing existing text. Beyond these examples, explore many other powerful features in the Programmers Guide. Our Cloud APIs are open‑source under the MIT license, and the full source code is available on GitHub.
If you encounter any issues while using the API, please reach out via our free customer support services.
Related Articles
We recommend visiting the following links to learn more about: