pdf links

PDF Rendering
Convert PDF to Image (.NET)
Convert PDF to image on Android (Xamarin)
Convert PDF to image on iOS (Xamarin)
Convert PDF to image in Windows Store apps (.NET)
Convert PDF to image in Windows Phone apps (.NET)
PDF to image in Universal Windows Store apps (.NET)
Free PDF Viewer control for Windows Forms (.NET)
How to integrate PDF Viewer control in WPF app (.NET)
Creating WPF PDF Viewer supporting bookmarks (.NET)
Cross-platform PDF Viewer using GTK# (MONO)
Silverlight PDF viewer control (Silverlight 5)
Multithreaded PDF rendering (.NET)
Convert pdf to image in Silverlight app (C# sample)
How to set fallback fonts for PDF rendering (C#)
Avoiding the out-of-memory exception on rendering (C#)
PDF viewer single page application (WebAPI, AngularJS)
PDF viewer control for Windows 10 universal applications
Use custom ICC profile for CMYK to RGB conversion
PDF layers - separate images, text, annotations, graphics

PDF Forms Creation PDF Security
Conversion to PDF/A
Other topics
PDF Document Manipulation
PDF Content Generation
Fixed and Flow layout document API (.NET)
Creation of grids and tables in PDF (C# sample)
How to create interactive documents using Actions (C# sample)
Text flow effects in PDF (C# sample)
How to generate ordered and bulleted lists in PDF (C# sample)
Convert HTML to PDF using flow layout API (C# sample)
How to use custom fonts for PDF generation (.NET)
Create document with differently sized pages (C#)
Create PDF documents using MONO (C#/MONO/Windows/OSX)
How to use background images for content elements (C#/PDF Kit/FlowLayout)
Add transparent images to PDF document (C#)
Draw round rect borders in PDF documents(C#)
ICC color profiles and and ICC based colors in PDF (C#)
How to use bidirectional and right to left text in PDF (C#)
Create PDF documents from XML templates (C# sample)
How to resize PDF pages and use custom stamps (C#)
Add header and footer to PDF page (.NET sample)
How to use clipping mask for drawing on PDF page
Fill graphics path with gradient brushes in PDF (Shadings)
Apitron PDF Kit and Rasterizer engine settings
Add layers to PDF page (optional content, C# sample)
How to create free text annotation with custom appearance

PDF Content Extraction
PDF Navigation

PDF to TIFF conversion
Contact us if you have a PDF related question and we'll cover it in our blog.

2015-05-12

Scroll to the specific grid row using links in pdf

This post is an addition to our previously posted article showing how to create grids, and describes how to use PDF links for navigation between grid rows.

Imaging that you have a grid with many data rows and it spans across, say, five pages. You’d like to provide the viewer with a set or links quickly navigating to each 10th, 20th, etc. row. Here the Link property of ContentElement comes into play. Let’s use a slightly modified sample from section 2.5 Multipage Grid.

C# code:

public void CreateMultipageGridWithLinks()
{
    int rowCount = 45;

    // create resource manager and document object
    ResourceManager resourceManager = new ResourceManager();
    FlowDocument doc = new FlowDocument() { Margin = new Thickness(5) };
    // register a style for links
    doc.StyleManager.RegisterStyle(".link",
        new Style(){ Color = RgbColors.Blue, Margin = new Thickness(5)});

    // create grid with 4 autosized columns taking 100% of the available space
    Grid grid = new Grid(Length.Auto, Length.Auto, Length.Auto, Length.Auto);
    // add col headers
    grid.Add(new GridRow(new TextBlock("Order"), new TextBlock("Date"),
        new TextBlock("Customer"), new TextBlock("Paid")));

    // add data records
    for (int rowIndex = 1; rowIndex <= rowCount; rowIndex++)
    {
        string rowId = rowIndex.ToString();
        /* setting an id for the entire gridrow won't work because
           gridrow objects can't be matched via styles. They are
           special elements which don't actually exist on page.
           So, we assign the id to the first textbox in this row. */
        grid.Add(new GridRow(new TextBlock(rowId){Id=rowId}, new TextBlock("01/02/2015"),
            new TextBlock("Jon Doe"), new TextBlock("Yes")));

        // check if the row should get a link to it
        if (rowIndex % 10 == 0)
        {           
            // create textblock serving as link, 
            // and reference a row using id set to the first cell
            TextBlock link = new TextBlock(string.Format("Row {0} ↓", rowIndex));           
            link.Link = new CrossReference(rowId);
            link.Class = "link";
            doc.Add(link);
        }
    }   
    // add grid to document
    doc.Add(grid);
    // save document
    using (Stream stream = File.Create("multipage_grid_with_links.pdf"))
    {
        doc.Write(stream, resourceManager, new PageBoundary(Boundaries.A6));
    }

}

The code from above produces a set of links which, when clicked, navigate the viewer to the specific row. See the image below:

Pic. 9 Grid navigation in pdf

Pic. 9 Grid navigation

Note that the textblock links placed on top of the page, are connected to elements in grid using their Link property and a CrossReference object, describing the link. A cross reference is a link within the same document created using either element’s Id or its instance.

In order to reference a GridRow, you’d have to add a link to one of its cells because GridRow objects are special content elements. They group other objects together logically, but are not getting created on PDF page; thus, they can’t be linked to.

It’s also possible to create outbound links to other resources using LinkUri object, or bookmark page elements using the Bookmark property. Read more about Apitron PDF Kit for .NET component on its product page.

Complete downloadable version of this article can be found by the following link [PDF].

No comments:

Post a Comment