Skip to content

Commit 31762c6

Browse files
Merge pull request #215 from SyncfusionExamples/991259-ActionVideo
991259 - How to implement the URI, GoTo, Named, and Launch Action in PDF Using the Syncfusion .NET PDF Library
2 parents ed7a5c9 + f402810 commit 31762c6

File tree

78 files changed

+74922
-0
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

78 files changed

+74922
-0
lines changed

Videos/Actions/Actions.sln

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.14.36310.24 d17.14
5+
MinimumVisualStudioVersion = 10.0.40219.1
6+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Actions", "Actions\Actions.csproj", "{99FE444D-6B80-4E92-B19A-899A03B4E152}"
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+
{99FE444D-6B80-4E92-B19A-899A03B4E152}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
15+
{99FE444D-6B80-4E92-B19A-899A03B4E152}.Debug|Any CPU.Build.0 = Debug|Any CPU
16+
{99FE444D-6B80-4E92-B19A-899A03B4E152}.Release|Any CPU.ActiveCfg = Release|Any CPU
17+
{99FE444D-6B80-4E92-B19A-899A03B4E152}.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 = {D7D33AFE-F12C-4247-B9BA-4A27FB9E0EEA}
24+
EndGlobalSection
25+
EndGlobal
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
<Project Sdk="Microsoft.NET.Sdk.Web">
2+
3+
<PropertyGroup>
4+
<TargetFramework>net8.0</TargetFramework>
5+
<Nullable>enable</Nullable>
6+
<ImplicitUsings>enable</ImplicitUsings>
7+
</PropertyGroup>
8+
9+
<ItemGroup>
10+
<PackageReference Include="Syncfusion.Pdf.Net.Core" Version="*" />
11+
</ItemGroup>
12+
13+
</Project>
Lines changed: 131 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,131 @@
1+
using System.Diagnostics;
2+
using Actions.Models;
3+
using Microsoft.AspNetCore.Mvc;
4+
using Syncfusion.Pdf;
5+
using Syncfusion.Drawing;
6+
using Syncfusion.Pdf.Interactive;
7+
using Syncfusion.Pdf.Parsing;
8+
9+
namespace Actions.Controllers
10+
{
11+
public class HomeController : Controller
12+
{
13+
private readonly ILogger<HomeController> _logger;
14+
15+
public HomeController(ILogger<HomeController> logger)
16+
{
17+
_logger = logger;
18+
}
19+
20+
public IActionResult AddUriAction()
21+
{
22+
FileStream fileStream = new FileStream("Data\\input.pdf", FileMode.Open, FileAccess.Read);
23+
24+
PdfLoadedDocument loadedDocument = new PdfLoadedDocument(fileStream);
25+
26+
PdfPageBase page = loadedDocument.Pages[1];
27+
28+
List<RectangleF> matchedItems;
29+
30+
loadedDocument.FindText("PDF Succinctly", 1, out matchedItems);
31+
32+
PdfUriAction uriAction = new PdfUriAction("https://www.syncfusion.com/document-sdk/net-pdf-library");
33+
34+
PdfActionAnnotation actionAnnotation = new PdfActionAnnotation(matchedItems[0], uriAction);
35+
36+
page.Annotations.Add(actionAnnotation);
37+
38+
return CreateFileResult(loadedDocument, "Output.pdf");
39+
}
40+
41+
public IActionResult AddGoToAction()
42+
{
43+
FileStream fileStream = new FileStream("Data\\input.pdf", FileMode.Open, FileAccess.Read);
44+
45+
PdfLoadedDocument loadedDocument = new PdfLoadedDocument(fileStream);
46+
47+
PdfPageBase page = loadedDocument.Pages[2];
48+
49+
List<RectangleF> matchedItems;
50+
51+
loadedDocument.FindText("PDF Succinctly", 2, out matchedItems);
52+
53+
PdfDestination destination = new PdfDestination(loadedDocument.Pages[4]);
54+
55+
PdfGoToAction gotoAction = new PdfGoToAction(destination);
56+
57+
PdfActionAnnotation gotoAnnotation = new PdfActionAnnotation(matchedItems[0], gotoAction);
58+
59+
page.Annotations.Add(gotoAnnotation);
60+
61+
return CreateFileResult(loadedDocument, "GoToAction.pdf");
62+
}
63+
64+
public IActionResult AddNamedAction()
65+
{
66+
FileStream fileStream = new FileStream("Data\\input.pdf", FileMode.Open, FileAccess.Read);
67+
68+
PdfLoadedDocument loadedDocument = new PdfLoadedDocument(fileStream);
69+
70+
PdfPageBase page = loadedDocument.Pages[1];
71+
72+
List<RectangleF> matchedItems;
73+
74+
loadedDocument.FindText("PDF Succinctly", 1, out matchedItems);
75+
76+
PdfNamedAction namedAction = new PdfNamedAction(PdfActionDestination.LastPage);
77+
78+
PdfActionAnnotation actionAnnotation = new PdfActionAnnotation(matchedItems[0], namedAction);
79+
80+
page.Annotations.Add(actionAnnotation);
81+
82+
return CreateFileResult(loadedDocument, "NamedAction.pdf");
83+
}
84+
85+
public IActionResult AddLaunchAction()
86+
{
87+
FileStream fileStream = new FileStream("Data\\input.pdf", FileMode.Open, FileAccess.Read);
88+
89+
PdfLoadedDocument loadedDocument = new PdfLoadedDocument(fileStream);
90+
91+
PdfPageBase page = loadedDocument.Pages[1];
92+
93+
List<RectangleF> matchedItems;
94+
95+
loadedDocument.FindText("PDF Succinctly", 1, out matchedItems);
96+
97+
PdfLaunchAction launchAction = new PdfLaunchAction("C:\\Users\\Downloads\\input.txt");
98+
99+
PdfActionAnnotation actionAnnotation = new PdfActionAnnotation(matchedItems[0], launchAction);
100+
101+
page.Annotations.Add(actionAnnotation);
102+
103+
return CreateFileResult(loadedDocument, "LaunchAction.pdf");
104+
}
105+
106+
private FileStreamResult CreateFileResult(PdfLoadedDocument document, string fileName)
107+
{
108+
MemoryStream outputStream = new MemoryStream();
109+
document.Save(outputStream);
110+
outputStream.Position = 0;
111+
document.Close(true);
112+
return File(outputStream, "application/pdf", fileName);
113+
}
114+
115+
public IActionResult Index()
116+
{
117+
return View();
118+
}
119+
120+
public IActionResult Privacy()
121+
{
122+
return View();
123+
}
124+
125+
[ResponseCache(Duration = 0, Location = ResponseCacheLocation.None, NoStore = true)]
126+
public IActionResult Error()
127+
{
128+
return View(new ErrorViewModel { RequestId = Activity.Current?.Id ?? HttpContext.TraceIdentifier });
129+
}
130+
}
131+
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Hello world
159 KB
Binary file not shown.
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
namespace Actions.Models
2+
{
3+
public class ErrorViewModel
4+
{
5+
public string? RequestId { get; set; }
6+
7+
public bool ShowRequestId => !string.IsNullOrEmpty(RequestId);
8+
}
9+
}

Videos/Actions/Actions/Program.cs

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
namespace Actions
2+
{
3+
public class Program
4+
{
5+
public static void Main(string[] args)
6+
{
7+
var builder = WebApplication.CreateBuilder(args);
8+
9+
// Add services to the container.
10+
builder.Services.AddControllersWithViews();
11+
12+
var app = builder.Build();
13+
14+
// Configure the HTTP request pipeline.
15+
if (!app.Environment.IsDevelopment())
16+
{
17+
app.UseExceptionHandler("/Home/Error");
18+
// The default HSTS value is 30 days. You may want to change this for production scenarios, see https://aka.ms/aspnetcore-hsts.
19+
app.UseHsts();
20+
}
21+
22+
app.UseHttpsRedirection();
23+
app.UseStaticFiles();
24+
25+
app.UseRouting();
26+
27+
app.UseAuthorization();
28+
29+
app.MapControllerRoute(
30+
name: "default",
31+
pattern: "{controller=Home}/{action=Index}/{id?}");
32+
33+
app.Run();
34+
}
35+
}
36+
}
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
{
2+
"$schema": "http://json.schemastore.org/launchsettings.json",
3+
"iisSettings": {
4+
"windowsAuthentication": false,
5+
"anonymousAuthentication": true,
6+
"iisExpress": {
7+
"applicationUrl": "http://localhost:37757",
8+
"sslPort": 44372
9+
}
10+
},
11+
"profiles": {
12+
"http": {
13+
"commandName": "Project",
14+
"dotnetRunMessages": true,
15+
"launchBrowser": true,
16+
"applicationUrl": "http://localhost:5273",
17+
"environmentVariables": {
18+
"ASPNETCORE_ENVIRONMENT": "Development"
19+
}
20+
},
21+
"https": {
22+
"commandName": "Project",
23+
"dotnetRunMessages": true,
24+
"launchBrowser": true,
25+
"applicationUrl": "https://localhost:7010;http://localhost:5273",
26+
"environmentVariables": {
27+
"ASPNETCORE_ENVIRONMENT": "Development"
28+
}
29+
},
30+
"IIS Express": {
31+
"commandName": "IISExpress",
32+
"launchBrowser": true,
33+
"environmentVariables": {
34+
"ASPNETCORE_ENVIRONMENT": "Development"
35+
}
36+
}
37+
}
38+
}
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
@{
2+
ViewData["Title"] = "Home Page";
3+
}
4+
5+
<div>
6+
<h2 style="margin-bottom: 20px">Working with Actions in PDF</h2>
7+
<div>
8+
<button style="width: 200px; margin-bottom: 20px; height: 40px;display:block;font-size:18px;"
9+
onclick="location.href='@Url.Action("AddUriAction", "Home")'">
10+
URI Action
11+
</button>
12+
<button style="width: 200px; margin-bottom: 20px; height: 40px;display:block;font-size: 18px;"
13+
onclick="location.href='@Url.Action("AddGoToAction", "Home")'">
14+
GoTo Action
15+
</button>
16+
<button style="width: 200px; margin-bottom: 20px; height: 40px;display:block;font-size: 18px;"
17+
onclick="location.href='@Url.Action("AddNamedAction", "Home")'">
18+
Named Action
19+
</button>
20+
<button style="width: 200px; margin-bottom: 20px; height: 40px;display:block;font-size: 18px;"
21+
onclick="location.href='@Url.Action("AddLaunchAction", "Home")'">
22+
Launch Action
23+
</button>
24+
</div>
25+
</div>
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
@{
2+
ViewData["Title"] = "Privacy Policy";
3+
}
4+
<h1>@ViewData["Title"]</h1>
5+
6+
<p>Use this page to detail your site's privacy policy.</p>

0 commit comments

Comments
 (0)