Can't find what you're looking for?

Contact us or post in our forums and we'll help you find an answer.

How to add a drop shadow effect to text in .NET/.NETCore using GcPDF

Issue:

The ability to show blurred drop shadows is a bitmap effect, this is why GcPDF does not exposes a direct method/approach for adding shadow effect to text while generating PDF.

Therefore, this article shows how to add blurred/drop shadow effects to text using GcPDF.

Resolution

To show shadow effects with text, place the text in HTML template and set text-shadow attribute. Then, this HTML text can be added to the exported PDF using the DrawHtml method of GcPDF as seen in this code snippet:

// HTML code that represents the content to render:
var html = "<!DOCTYPE html>" +
    "<html>" +
    "<head>" +
    "<style></style>" +
    "</head>" +
    "<body>" +
    "<p class='round'>Text generated using HTML with <span class='bold'>GcHtml</span>!</p>" +
    "</body>" +
    "</html>";

// Create a new PDF document, add a page, get graphics to draw on:
var doc = new GcPdfDocument();
var page = doc.NewPage();
var g = page.Graphics;
// Render HTML text
g.DrawHtml(html, 50, 50, new HtmlToPdfFormat(false) { MaxPageWidth = 6.5f }, out SizeF size);

Here is the text showing the shadow effect has been applied:

Get the Latest Version of Documents for PDF .NET
Download the Free Trial Now