Back to Devexpress

PdfGraphics.AddLinkToPage(RectangleF, Int32, Single) Method

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

latest4.8 KB
Original Source

PdfGraphics.AddLinkToPage(RectangleF, Int32, Single) Method

Adds a link that refers to the document page with the specified number and zoom factor.

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 zoom
)
vb
Public Sub AddLinkToPage(
    linkArea As RectangleF,
    pageNumber As Integer,
    zoom As Single
)

Parameters

NameTypeDescription
linkAreaRectangleF

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

| | pageNumber | Int32 |

The target page number.

| | zoom | Single |

A zoom factor by which the document is scaled after you click a link.

|

Remarks

This method defines the clickable page area that links to the document page specified by the pageNumber parameter. When you click the link, the target page is displayed at the specified zoom level.

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.

the following code snippet adds a link that refers to the second document page and scales this page by 300%.

View Example

csharp
using System;
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())
    {
        // Draw a link text.
        DXSolidBrush black = (DXSolidBrush)DXBrushes.Black;
        using (DXFont font = new DXFont("Times New Roman", 32, FontStyle.Bold)) {
            graphics.DrawString("PDF Document API", font, black, 180, 150);
        }

        // Create a link to the second document page.
        graphics.AddLinkToPage(new RectangleF(180, 160, 480, 30), 2, 3);

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

        // Create the second document page to which the link refers.
        processor.AddNewPage(PdfPaperSize.A4);
    }
}
vb
Imports System
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()

        ' Draw a link text.
        Dim black As DXSolidBrush = CType(DXBrushes.Black, DXSolidBrush)
        Using font As DXFont = New DXFont("Times New Roman", 32, FontStyle.Bold)
            graphics.DrawString("PDF Document API", font, black, 180, 150)
        End Using

        ' Create a link to the second document page.
        graphics.AddLinkToPage(New RectangleF(180, 160, 480, 30), 2, 3)

        ' Render a page with graphics.
        processor.RenderNewPage(PdfPaperSize.Letter, graphics)

        ' Create the second document page to which the link refers.
        processor.AddNewPage(PdfPaperSize.A4)
    End Using
End Using

See Also

Configure Links in PDF Files with DevExpress PDF Document API

PdfGraphics Class

PdfGraphics Members

DevExpress.Pdf Namespace