Back to Devexpress

PdfGraphics.AddLinkToPage(RectangleF, Int32, Single, Single) Method

officefileapi-devexpress-dot-pdf-dot-pdfgraphics-dot-addlinktopage-x28-system-dot-drawing-dot-rectanglef-system-dot-int32-system-dot-single-system-dot-single-x29.md

latest6.9 KB
Original Source

PdfGraphics.AddLinkToPage(RectangleF, Int32, Single, Single) Method

Adds a link that refers to the document page with the specified number. Allows you to set a page point positioned at the top left corner of the document window.

Namespace : DevExpress.Pdf

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

NuGet Package : DevExpress.Pdf.Drawing

Declaration

csharp
public void AddLinkToPage(
    RectangleF linkArea,
    int pageNumber,
    float destinationX,
    float destinationY
)
vb
Public Sub AddLinkToPage(
    linkArea As RectangleF,
    pageNumber As Integer,
    destinationX As Single,
    destinationY As Single
)

Parameters

NameTypeDescription
linkAreaRectangleF

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

| | pageNumber | Int32 |

The page number.

| | destinationX | Single |

The horizontal coordinate of a target page point (in the world coordinate system) that is positioned at the top left corner of the document window.

| | destinationY | Single |

The vertical coordinate of a target page point (in the world coordinate system) that is positioned at the top left corner of the document window.

|

Remarks

This method specifies the page area on which you can click to refer to a specific page location defined by the destinationX and destinationY parameters. The pageNumber parameter specifies the target page number.

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 (for example, system rotation) are not taken into account when the AddLinkToPage method is called.

Example

The following code snippet adds a link that refers to the point with coordinates (168, 230) from the second document page.

View Example

cs
using DevExpress.Pdf;
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 a page specifying link area, the page number and X, Y destinations.
        graphics.AddLinkToPage(new RectangleF(180, 160, 480, 30), 1, 168, 230);

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

static void DrawGraphics(PdfGraphics graphics) {

    // Draw a text line on the page.
    DXSolidBrush black = (DXSolidBrush)DXBrushes.Black;
    using (DXFont font = new DXFont("Times New Roman", 32, DXFontStyle.Bold)) {
        graphics.DrawString("PDF Document Processor", font, black, 180, 150);
    }
}
vb
Imports DevExpress.Pdf
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 a page specifying link area, the page number and X, Y destinations.
        graphics.AddLinkToPage(New RectangleF(180, 160, 480, 30), 1, 168, 230)
        ' Render a page with graphics.
        processor.RenderNewPage(PdfPaperSize.Letter, graphics)
    End Using
End Using

Private Shared Sub DrawGraphics(ByVal graphics As PdfGraphics)
    ' Draw a text line on the page.
    Dim black As DXSolidBrush = CType(DXBrushes.Black, DXSolidBrush)
    Using font As DXFont = New DXFont("Times New Roman", 32, DXFontStyle.Bold)
        graphics.DrawString("PDF Document Processor", font, black, 180, 150)
    End Using
End Sub

The following code snippet (auto-collected from DevExpress Examples) contains a reference to the AddLinkToPage(RectangleF, Int32, Single, Single) 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-page/CS/AddLinkToPage/Program.cs#L18

csharp
// Create a link to a page specifying link area, the page number and X, Y destinations.
graphics.AddLinkToPage(new RectangleF(180, 160, 480, 30), 1, 168, 230);

pdf-document-api-add-link-to-page/VB/AddLinkToPage/Program.vb#L16

vb
' Create a link to a page specifying link area, the page number and X, Y destinations.
graphics.AddLinkToPage(New RectangleF(180, 160, 480, 30), 1, 168, 230)
' Render a page with graphics.

See Also

Configure Links in PDF Files with DevExpress PDF Document API

PdfGraphics Class

PdfGraphics Members

DevExpress.Pdf Namespace