Back to Devexpress

PdfGraphics.AddLinkToUri(RectangleF, Uri) Method

officefileapi-devexpress-dot-pdf-dot-pdfgraphics-dot-addlinktouri-x28-system-dot-drawing-dot-rectanglef-system-dot-uri-x29.md

latest5.8 KB
Original Source

PdfGraphics.AddLinkToUri(RectangleF, Uri) Method

Adds a link to a URI at the specified page rectangle.

Namespace : DevExpress.Pdf

Assembly : DevExpress.Pdf.v25.2.Drawing.dll

NuGet Package : DevExpress.Pdf.Drawing

Declaration

csharp
public void AddLinkToUri(
    RectangleF linkArea,
    Uri uri
)
vb
Public Sub AddLinkToUri(
    linkArea As RectangleF,
    uri As Uri
)

Parameters

NameTypeDescription
linkAreaRectangleF

A page area (in the world coordinate system) where you can add a link.

| | uri | Uri |

A Uri object that is the link URI.

|

Remarks

This method specifies the page area on which you can click to refer to the URI defined by the uri parameter.

To draw a link on the PDF page, use one of the following methods:

PdfGraphics.AddToPageForeground, PdfGraphics.AddToPageBackgroundThese methods allow you to draw content on an existing page.PdfDocumentProcessor.RenderNewPageDraws content on a new page.

Note

Coordinate system transformations (e.g., system rotation) are not taken into account when the AddLinkToUri method is called.

The following code snippet creates the PdfGraphics.AddLinkToUri method to create a link to a URI.

cs
using System;
using DevExpress.Pdf;
using System.Drawing;
using DevExpress.Drawing;

//...
using (PdfDocumentProcessor processor = new PdfDocumentProcessor()) {

    // Create an empty document.
    processor.CreateEmptyDocument("..\\..\\Result.pdf");

    // Create and draw graphics.
    using (PdfGraphics graphics = processor.CreateGraphicsPageSystem()) {
        DrawGraphics(graphics);

        // Create a link to URI specifying link area and URI.
        graphics.AddLinkToUri(new RectangleF(310, 150, 180, 15), new Uri("https://www.devexpress.com"));

        // Render a page with graphics.
        processor.RenderNewPage(PdfPaperSize.Letter, graphics);
    }
}

static void DrawGraphics(PdfGraphics graphics)
{
    // Draw a text line on the page.
    DXFont font = new DXFont("Arial", 10);

    DXSolidBrush blue = new DXSolidBrush(Color.Blue);
    graphics.DrawString("https://www.devexpress.com", font, blue, 310, 150);
}
vb
Imports System
Imports DevExpress.Pdf
Imports System.Drawing
Imports DevExpress.Drawing

'...
Using processor As PdfDocumentProcessor = New PdfDocumentProcessor()
    ' Create an empty document.
    processor.CreateEmptyDocument("..\..\Result.pdf")
    ' Create and draw graphics.
    Using graphics As PdfGraphics = processor.CreateGraphicsPageSystem()
        DrawGraphics(graphics)
        ' Create a link to URI specifying link area and URI.
        graphics.AddLinkToUri(New RectangleF(310, 150, 180, 15), New Uri("https://www.devexpress.com"))
        ' Render a page with graphics.
        processor.RenderNewPage(PdfPaperSize.Letter, graphics)
    End Using
End Using

Shared Sub DrawGraphics(ByVal graphics As PdfGraphics)
    ' Draw a text line on the page.
    Dim font As New DXFont("Arial", 10)

    Dim blue As New DXSolidBrush(Color.Blue)
    graphics.DrawString("https://www.devexpress.com", font, blue, 310, 150)
End Sub

The following code snippet (auto-collected from DevExpress Examples) contains a reference to the AddLinkToUri(RectangleF, Uri) method.

Note

The algorithm used to collect these code examples remains a work in progress. Accordingly, the links and snippets below may produce inaccurate results. If you encounter an issue with code examples below, please use the feedback form on this page to report the issue.

pdf-document-api-add-link-to-uri/CS/AddLinkToUri/Program.cs#L19

csharp
// Create a link to URI specifying link area and URI.
graphics.AddLinkToUri(new RectangleF(310, 150, 180, 15), new Uri("https://www.devexpress.com"));

pdf-document-api-add-link-to-uri/VB/AddLinkToUri/Program.vb#L17

vb
' Create a link to URI specifying link area and URI.
graphics.AddLinkToUri(New RectangleF(310, 150, 180, 15), New Uri("https://www.devexpress.com"))
' Render a page with graphics.

See Also

Configure Links in PDF Files with DevExpress PDF Document API

PdfGraphics Class

PdfGraphics Members

DevExpress.Pdf Namespace