Skip to content

Commit 4fc6827

Browse files
Blog samples moved
1 parent d0212fb commit 4fc6827

18 files changed

+631
-2
lines changed

README.md

Lines changed: 43 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,43 @@
1-
# pdf-navigation-examples-csharp
2-
This repository includes Syncfusion PDF library examples demonstrating five ways to navigate PDF pages in C#. Learn to create interactive navigation links, buttons, TOC, bookmarks, and named destinations. Perfect for developers looking to enhance PDF interactivity with the Syncfusion .NET PDF Library.
1+
# 5 ways to navigate PDF pages using C#
2+
3+
The Syncfusion® .NET PDF Library offers a robust set of tools for navigating PDF pages programmatically in your .NET applications. This collection of samples showcases five different methods for navigating PDF pages, allowing developers to create seamless and interactive navigation experiences within their PDF documents.
4+
5+
Sample name | Description
6+
------|------
7+
[Navigate PDF pages using document link annotations](https://github.com/SyncfusionExamples/pdf-navigation-examples-csharp/tree/master/navigate-via-document-link-annotation) | Demonstrates how to navigate to specific pages within a PDF document using document link annotations. These annotations provide seamless internal navigation for enhanced document usability.
8+
[Navigate PDF pages using bookmarks](https://github.com/SyncfusionExamples/pdf-navigation-examples-csharp/tree/master/navigate-via-bookmark) | Shows how to implement bookmarks in a PDF to allow quick and structured navigation across different sections or pages of the document.
9+
[Navigate PDF pages using named destinations](https://github.com/SyncfusionExamples/pdf-navigation-examples-csharp/tree/master/named-destinations) | Explains how to create and use named destinations for navigating to specific locations within a PDF, making it easier to jump directly to key content.
10+
[Navigate PDF pages using Table of Contents (TOC)](https://github.com/SyncfusionExamples/pdf-navigation-examples-csharp/tree/master/create-table-of-content-pdf) | Illustrates how to create and use a Table of Contents (TOC) in a PDF document, enabling efficient navigation for structured and lengthy documents.
11+
[Navigate PDF pages using GoTo actions](https://github.com/SyncfusionExamples/pdf-navigation-examples-csharp/tree/master/navigate-via-goto-action) | Demonstrates how to use GoTo actions to provide direct navigation to specific pages or locations within a PDF file, offering an interactive user experience.
12+
13+
## How to run the examples
14+
15+
* Download this project to a location in your disk.
16+
* Open the solution file using Visual Studio.
17+
* Rebuild the solution to install the required NuGet package.
18+
* Run the application.
19+
20+
## Resources
21+
22+
* **Product page:** [Syncfusion® PDF Framework](https://www.syncfusion.com/document-processing/pdf-framework/net)
23+
* **Documentation page:** [Syncfusion® .NET PDF library](https://help.syncfusion.com/document-processing/pdf/pdf-library/net/overview)
24+
* **Online demo:** [Syncfusion® .NET PDF library - Online demos](https://ej2.syncfusion.com/aspnetcore/pdf/default#/fluent2)
25+
* **Blog:** [Syncfusion® .NET PDF library - Blog](https://www.syncfusion.com/blogs/category/pdf)
26+
* **Knowledge Base:** [Syncfusion® .NET PDF library - Knowledge Base](https://www.syncfusion.com/kb/windowsforms/pdf)
27+
* **EBooks:** [Syncfusion® .NET PDF library - EBooks](https://www.syncfusion.com/succinctly-free-ebooks)
28+
* **FAQ:** [Syncfusion® .NET PDF library - FAQ](https://www.syncfusion.com/faq/)
29+
30+
## Support and feedback
31+
32+
* For any other queries, reach our [Syncfusion® support team](https://www.syncfusion.com/support/directtrac/incidents/newincident?utm_source=github&utm_medium=listing&utm_campaign=github-docio-examples) or post the queries through the [community forums](https://www.syncfusion.com/forums?utm_source=github&utm_medium=listing&utm_campaign=github-docio-examples).
33+
* Request new feature through [Syncfusion® feedback portal](https://www.syncfusion.com/feedback?utm_source=github&utm_medium=listing&utm_campaign=github-docio-examples).
34+
35+
## License
36+
37+
This is a commercial product and requires a paid license for possession or use. Syncfusion’s licensed software, including this component, is subject to the terms and conditions of [Syncfusion's EULA](https://www.syncfusion.com/eula/es/?utm_source=github&utm_medium=listing&utm_campaign=github-docio-examples). You can purchase a licnense [here](https://www.syncfusion.com/sales/products?utm_source=github&utm_medium=listing&utm_campaign=github-docio-examples) or start a free 30-day trial [here](https://www.syncfusion.com/account/manage-trials/start-trials?utm_source=github&utm_medium=listing&utm_campaign=github-docio-examples).
38+
39+
## About Syncfusion®
40+
41+
Founded in 2001 and headquartered in Research Triangle Park, N.C., Syncfusion® has more than 26,000+ customers and more than 1 million users, including large financial institutions, Fortune 500 companies, and global IT consultancies.
42+
43+
Today, we provide 1600+ components and frameworks for web ([Blazor](https://www.syncfusion.com/blazor-components?utm_source=github&utm_medium=listing&utm_campaign=github-docio-examples), [ASP.NET Core](https://www.syncfusion.com/aspnet-core-ui-controls?utm_source=github&utm_medium=listing&utm_campaign=github-docio-examples), [ASP.NET MVC](https://www.syncfusion.com/aspnet-mvc-ui-controls?utm_source=github&utm_medium=listing&utm_campaign=github-docio-examples), [ASP.NET WebForms](https://www.syncfusion.com/jquery/aspnet-webforms-ui-controls?utm_source=github&utm_medium=listing&utm_campaign=github-docio-examples), [JavaScript](https://www.syncfusion.com/javascript-ui-controls?utm_source=github&utm_medium=listing&utm_campaign=github-docio-examples), [Angular](https://www.syncfusion.com/angular-ui-components?utm_source=github&utm_medium=listing&utm_campaign=github-docio-examples), [React](https://www.syncfusion.com/react-ui-components?utm_source=github&utm_medium=listing&utm_campaign=github-docio-examples), [Vue](https://www.syncfusion.com/vue-ui-components?utm_source=github&utm_medium=listing&utm_campaign=github-docio-examples), and [Flutter](https://www.syncfusion.com/flutter-widgets?utm_source=github&utm_medium=listing&utm_campaign=github-docio-examples)), mobile ([Xamarin](https://www.syncfusion.com/xamarin-ui-controls?utm_source=github&utm_medium=listing&utm_campaign=github-docio-examples), [Flutter](https://www.syncfusion.com/flutter-widgets?utm_source=github&utm_medium=listing&utm_campaign=github-docio-examples), [UWP](https://www.syncfusion.com/uwp-ui-controls?utm_source=github&utm_medium=listing&utm_campaign=github-docio-examples), and [JavaScript](https://www.syncfusion.com/javascript-ui-controls?utm_source=github&utm_medium=listing&utm_campaign=github-docio-examples)), and desktop development ([WinForms](https://www.syncfusion.com/winforms-ui-controls?utm_source=github&utm_medium=listing&utm_campaign=github-docio-examples), [WPF](https://www.syncfusion.com/wpf-ui-controls?utm_source=github&utm_medium=listing&utm_campaign=github-docio-examples), [WinUI(Preview)](https://www.syncfusion.com/winui-controls?utm_source=github&utm_medium=listing&utm_campaign=github-docio-examples), [Flutter](https://www.syncfusion.com/flutter-widgets?utm_source=github&utm_medium=listing&utm_campaign=github-docio-examples) and [UWP](https://www.syncfusion.com/uwp-ui-controls?utm_source=github&utm_medium=listing&utm_campaign=github-docio-examples)). We provide ready-to-deploy enterprise software for dashboards, reports, data integration, and big data processing. Many customers have saved millions in licensing fees by deploying our software.
Lines changed: 129 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,129 @@
1+
// See https://aka.ms/new-console-template for more information
2+
using Syncfusion.Drawing;
3+
using Syncfusion.Pdf;
4+
using Syncfusion.Pdf.Graphics;
5+
using Syncfusion.Pdf.Interactive;
6+
7+
8+
using (PdfDocument document = new PdfDocument())
9+
{
10+
//Create the font to add the TOC title
11+
PdfStandardFont titleFont = new PdfStandardFont(PdfFontFamily.Helvetica, 20);
12+
13+
//Add a section to create TOC
14+
PdfSection tocSection = document.Sections.Add();
15+
16+
//Add a page for creating TOC
17+
PdfPage tocPage = tocSection.Pages.Add();
18+
19+
tocPage.Graphics.DrawString("Table Of Contents", titleFont, PdfBrushes.Black,
20+
new RectangleF(0, 0, tocPage.GetClientSize().Width, tocPage.GetClientSize().Height), new PdfStringFormat(PdfTextAlignment.Center));
21+
22+
//Add a separate section to draw the content
23+
PdfSection contentSection = document.Sections.Add();
24+
25+
//Add page using the content section
26+
PdfPage contentPage = contentSection.Pages.Add();
27+
28+
//Create necessary fonts
29+
PdfStandardFont paragraphFont = new PdfStandardFont(titleFont, 10);
30+
PdfStandardFont chapterFont = new PdfStandardFont(paragraphFont, 18, PdfFontStyle.Bold);
31+
PdfStandardFont sectionFont = new PdfStandardFont(paragraphFont, 14, PdfFontStyle.Bold);
32+
PdfStandardFont paragraphFontBold = new PdfStandardFont(paragraphFont, 10, PdfFontStyle.Bold);
33+
34+
PdfLayoutResult result = null;
35+
36+
//Get the page size
37+
SizeF pageSize = contentPage.GetClientSize();
38+
39+
//initialize the TOC start height
40+
float y = 40;
41+
42+
//Sample text to draw the paragraph
43+
string paragraphText = "Adobe Systems Incorporated's Portable Document Format (PDF) is the de facto standard for the accurate, reliable, and platform-independent representation of a paged document. It's the only universally accepted file format that allows pixel-perfect layouts. In addition, PDF supports user interaction and collaborative workflows that are not possible with printed documents.";
44+
45+
for (int i = 1; i <= 3; i++)
46+
{
47+
RectangleF bounds = new RectangleF(0, 0, pageSize.Width, pageSize.Height);
48+
49+
if (result != null)
50+
{
51+
bounds = new RectangleF(0, result.Bounds.Bottom + 10, pageSize.Width, pageSize.Height - result.Bounds.Bottom + 10);
52+
}
53+
54+
//Draw TOC
55+
y = DrawTableOfContent(tocPage, result == null ? contentPage : result.Page, document, "Chapter " + i, paragraphFontBold, bounds.Location, 0, y);
56+
57+
//Draw content
58+
result = AddParagraph(result == null ? contentPage : result.Page, "Chapter " + i, bounds, chapterFont);
59+
60+
for (int j = 1; j <= 3; j++)
61+
{
62+
y = DrawTableOfContent(tocPage, result.Page, document, "Section " + i + "." + j, paragraphFontBold, new PointF(0, result.Bounds.Bottom + 10), 10, y);
63+
result = AddParagraph(result.Page, "Section " + i + "." + j, new RectangleF(0, result.Bounds.Bottom + 10, pageSize.Width, pageSize.Height - result.Bounds.Bottom + 10), sectionFont);
64+
65+
for (int k = 1; k <= 3; k++)
66+
{
67+
y = DrawTableOfContent(tocPage, result.Page, document, "Paragraph " + i + "." + j + "." + k, paragraphFont, new PointF(0, result.Bounds.Bottom + 10), 20, y);
68+
result = AddParagraph(result.Page, "Paragraph " + i + "." + j + "." + k, new RectangleF(0, result.Bounds.Bottom + 10, pageSize.Width, pageSize.Height - result.Bounds.Bottom + 10), paragraphFontBold);
69+
result = AddParagraph(result.Page, paragraphText, new RectangleF(0, result.Bounds.Bottom + 10, pageSize.Width, pageSize.Height - result.Bounds.Bottom + 10), paragraphFont);
70+
}
71+
}
72+
}
73+
74+
// Save the PDF document
75+
using (FileStream outputStream = new FileStream("create-table-of-content.pdf", FileMode.Create, FileAccess.Write))
76+
{
77+
document.Save(outputStream);
78+
}
79+
}
80+
81+
PdfLayoutResult AddParagraph(
82+
PdfPage page, string text, RectangleF bounds, PdfFont font)
83+
{
84+
// Create the text element
85+
PdfTextElement textElement = new PdfTextElement(text, font);
86+
87+
PdfLayoutFormat format = new PdfLayoutFormat();
88+
89+
format.Layout = PdfLayoutType.Paginate;
90+
91+
format.PaginateBounds = new RectangleF (0,0, page.GetClientSize().Width, page.GetClientSize().Height);
92+
93+
// Draw the text on the page
94+
return textElement.Draw(page, bounds, format);
95+
}
96+
97+
float DrawTableOfContent(PdfPage tocPage, PdfPage destPage, PdfDocument document, string text, PdfFont font, PointF location, int indent, float y)
98+
{
99+
float textSize = font.MeasureString(text).Width;
100+
float pageWidth = tocPage.GetClientSize().Width;
101+
float dotSize = pageWidth - (30 + textSize + indent);
102+
103+
104+
string textToDraw = text;
105+
float dotWidth = font.MeasureString(".").Width;
106+
float n = 0;
107+
while (n < dotSize)
108+
{
109+
textToDraw += ".";
110+
n += dotWidth; // Dot spacing
111+
}
112+
textToDraw += document.Pages.IndexOf(destPage).ToString();
113+
// Draw the page number on the page
114+
tocPage.Graphics.DrawString(textToDraw, font, PdfBrushes.Black, new PointF(indent, y));
115+
116+
// Create a link annotation
117+
RectangleF annotationBounds = new RectangleF(indent, y, pageWidth - (25 +indent), font.Height);
118+
119+
PdfDocumentLinkAnnotation annotation = new PdfDocumentLinkAnnotation(
120+
annotationBounds,
121+
new PdfDestination(destPage, location))
122+
{
123+
Border = { Width = 0 }
124+
};
125+
tocPage.Annotations.Add(annotation);
126+
127+
return y += font.Height + 2;
128+
}
129+
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
3+
<PropertyGroup>
4+
<OutputType>Exe</OutputType>
5+
<TargetFramework>net9.0</TargetFramework>
6+
<RootNamespace>create_table_of_content_pdf</RootNamespace>
7+
<ImplicitUsings>enable</ImplicitUsings>
8+
<Nullable>enable</Nullable>
9+
</PropertyGroup>
10+
11+
<ItemGroup>
12+
<PackageReference Include="Syncfusion.Pdf.Net.Core" Version="*" />
13+
</ItemGroup>
14+
15+
</Project>
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
2+
Microsoft Visual Studio Solution File, Format Version 12.00
3+
# Visual Studio Version 17
4+
VisualStudioVersion = 17.13.35507.96 d17.13
5+
MinimumVisualStudioVersion = 10.0.40219.1
6+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "create-table-of-content-pdf", "create-table-of-content-pdf.csproj", "{C19D5014-33C5-4559-992A-534FAB5F89C0}"
7+
EndProject
8+
Global
9+
GlobalSection(SolutionConfigurationPlatforms) = preSolution
10+
Debug|Any CPU = Debug|Any CPU
11+
Release|Any CPU = Release|Any CPU
12+
EndGlobalSection
13+
GlobalSection(ProjectConfigurationPlatforms) = postSolution
14+
{C19D5014-33C5-4559-992A-534FAB5F89C0}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
15+
{C19D5014-33C5-4559-992A-534FAB5F89C0}.Debug|Any CPU.Build.0 = Debug|Any CPU
16+
{C19D5014-33C5-4559-992A-534FAB5F89C0}.Release|Any CPU.ActiveCfg = Release|Any CPU
17+
{C19D5014-33C5-4559-992A-534FAB5F89C0}.Release|Any CPU.Build.0 = Release|Any CPU
18+
EndGlobalSection
19+
GlobalSection(SolutionProperties) = preSolution
20+
HideSolutionNode = FALSE
21+
EndGlobalSection
22+
GlobalSection(ExtensibilityGlobals) = postSolution
23+
SolutionGuid = {0DF479DC-DFFB-423E-BC3F-BC36AC03D69F}
24+
EndGlobalSection
25+
EndGlobal

named-destinations/Program.cs

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
// See https://aka.ms/new-console-template for more information
2+
3+
using Syncfusion.Drawing;
4+
using Syncfusion.Pdf;
5+
using Syncfusion.Pdf.Interactive;
6+
using Syncfusion.Pdf.Parsing;
7+
8+
9+
using (FileStream documentStream = new FileStream("input.pdf", FileMode.Open, FileAccess.Read))
10+
{
11+
//Load the PDF file
12+
using (PdfLoadedDocument loadedDocument = new PdfLoadedDocument(documentStream))
13+
{
14+
//Create named destination and add to the document
15+
loadedDocument.NamedDestinationCollection.Add(CreateNamedDestination("Logo Page", loadedDocument.Pages[0], new PointF(0, 0)));
16+
17+
loadedDocument.NamedDestinationCollection.Add(CreateNamedDestination("Author Page", loadedDocument.Pages[1], new PointF(0, 150)));
18+
19+
loadedDocument.NamedDestinationCollection.Add(CreateNamedDestination("TOC Page", loadedDocument.Pages[2], new PointF(0, 0)));
20+
21+
loadedDocument.NamedDestinationCollection.Add(CreateNamedDestination("Introduction", loadedDocument.Pages[3], new PointF(0, 0)));
22+
23+
loadedDocument.NamedDestinationCollection.Add(CreateNamedDestination("Conceptual Overview", loadedDocument.Pages[3], new PointF(0, 450)));
24+
25+
// Save the PDF document
26+
using (FileStream outputStream = new FileStream("named-destination.pdf", FileMode.Create, FileAccess.Write))
27+
{
28+
loadedDocument.Save(outputStream);
29+
}
30+
}
31+
}
32+
33+
PdfNamedDestination CreateNamedDestination(string title, PdfPageBase page, PointF location)
34+
{
35+
//Create a named destination with title
36+
PdfNamedDestination namedDestination = new PdfNamedDestination(title);
37+
38+
//Create and set destination
39+
PdfDestination destination = new PdfDestination(page, location);
40+
41+
//Set the destination
42+
namedDestination.Destination = destination;
43+
44+
return namedDestination;
45+
}

named-destinations/input.pdf

159 KB
Binary file not shown.
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
3+
<PropertyGroup>
4+
<OutputType>Exe</OutputType>
5+
<TargetFramework>net9.0</TargetFramework>
6+
<RootNamespace>named_destinations</RootNamespace>
7+
<ImplicitUsings>enable</ImplicitUsings>
8+
<Nullable>enable</Nullable>
9+
</PropertyGroup>
10+
11+
<ItemGroup>
12+
<PackageReference Include="Syncfusion.Pdf.Net.Core" Version="*" />
13+
</ItemGroup>
14+
15+
<ItemGroup>
16+
<None Update="input.pdf">
17+
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
18+
</None>
19+
</ItemGroup>
20+
21+
</Project>
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
2+
Microsoft Visual Studio Solution File, Format Version 12.00
3+
# Visual Studio Version 17
4+
VisualStudioVersion = 17.13.35507.96 d17.13
5+
MinimumVisualStudioVersion = 10.0.40219.1
6+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "named-destinations", "named-destinations.csproj", "{CDE9A0E3-5808-4CA4-A826-CE672F8E91BA}"
7+
EndProject
8+
Global
9+
GlobalSection(SolutionConfigurationPlatforms) = preSolution
10+
Debug|Any CPU = Debug|Any CPU
11+
Release|Any CPU = Release|Any CPU
12+
EndGlobalSection
13+
GlobalSection(ProjectConfigurationPlatforms) = postSolution
14+
{CDE9A0E3-5808-4CA4-A826-CE672F8E91BA}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
15+
{CDE9A0E3-5808-4CA4-A826-CE672F8E91BA}.Debug|Any CPU.Build.0 = Debug|Any CPU
16+
{CDE9A0E3-5808-4CA4-A826-CE672F8E91BA}.Release|Any CPU.ActiveCfg = Release|Any CPU
17+
{CDE9A0E3-5808-4CA4-A826-CE672F8E91BA}.Release|Any CPU.Build.0 = Release|Any CPU
18+
EndGlobalSection
19+
GlobalSection(SolutionProperties) = preSolution
20+
HideSolutionNode = FALSE
21+
EndGlobalSection
22+
GlobalSection(ExtensibilityGlobals) = postSolution
23+
SolutionGuid = {30CEAB91-B3D2-43DF-B225-470498269F5A}
24+
EndGlobalSection
25+
EndGlobal

0 commit comments

Comments
 (0)