Skip to content

Commit 7f742d3

Browse files
committed
Merge branch 'master' of https://github.com/SyncfusionExamples/PDF-Examples into 1003826-sample
2 parents 18c29a1 + 308027b commit 7f742d3

File tree

36 files changed

+670
-0
lines changed

36 files changed

+670
-0
lines changed
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.36221.1 d17.14
5+
MinimumVisualStudioVersion = 10.0.40219.1
6+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Move-and-reorder-bookmark-in-the-PDF", "Move-and-reorder-bookmark-in-the-PDF\Move-and-reorder-bookmark-in-the-PDF.csproj", "{2D864F6D-C55F-4995-9871-B322FAFA3B30}"
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+
{2D864F6D-C55F-4995-9871-B322FAFA3B30}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
15+
{2D864F6D-C55F-4995-9871-B322FAFA3B30}.Debug|Any CPU.Build.0 = Debug|Any CPU
16+
{2D864F6D-C55F-4995-9871-B322FAFA3B30}.Release|Any CPU.ActiveCfg = Release|Any CPU
17+
{2D864F6D-C55F-4995-9871-B322FAFA3B30}.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 = {77EDC987-03C1-47D2-AD47-61625B9D80FC}
24+
EndGlobalSection
25+
EndGlobal
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>net8.0</TargetFramework>
6+
<RootNamespace>Move_and_reorder_bookmark_in_the_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>

Bookmarks/Move-and-reorder-bookmark-in-the-PDF/.NET/Move-and-reorder-bookmark-in-the-PDF/Output/gitkeep.txt

Whitespace-only changes.
Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
using Syncfusion.Pdf.Graphics;
2+
using Syncfusion.Pdf.Interactive;
3+
using Syncfusion.Pdf.Parsing;
4+
5+
class Program
6+
{
7+
static void Main(string[] args)
8+
{
9+
// Load the PDF document
10+
using (PdfLoadedDocument loadedDocument = new PdfLoadedDocument(Path.GetFullPath(@"Data/Input.pdf")))
11+
{
12+
PdfBookmarkBase bookmarks = loadedDocument.Bookmarks;
13+
// Reorder: move bookmark from index
14+
if (bookmarks.Count > 2)
15+
MoveBookmark(bookmarks, 2, 0, loadedDocument);
16+
// Remove bookmark by title.
17+
RemoveBookmarkByTitle(bookmarks, "Bookmark To Remove");
18+
loadedDocument.Save(Path.GetFullPath(@"Output/Output.pdf"));
19+
}
20+
}
21+
22+
// Moves a bookmark from one index to another within its parent collection.
23+
static void MoveBookmark(PdfBookmarkBase parentCollection, int fromIndex, int toIndex, PdfLoadedDocument document)
24+
{
25+
if (fromIndex == toIndex || fromIndex < 0 || fromIndex >= parentCollection.Count)
26+
return;
27+
PdfLoadedBookmark sourceBookmark = parentCollection[fromIndex] as PdfLoadedBookmark;
28+
if (sourceBookmark == null)
29+
return;
30+
// Store bookmark details.
31+
string title = sourceBookmark.Title;
32+
PdfTextStyle textStyle = sourceBookmark.TextStyle;
33+
PdfColor color = sourceBookmark.Color;
34+
PdfDestination destination = sourceBookmark.Destination ?? new PdfDestination(document.Pages[0]);
35+
List<PdfBookmark> children = new List<PdfBookmark>();
36+
foreach (PdfBookmark child in sourceBookmark)
37+
children.Add(child);
38+
// Remove from original position.
39+
parentCollection.RemoveAt(fromIndex);
40+
// Adjust target index.
41+
int adjustedIndex = toIndex > fromIndex ? toIndex - 1 : toIndex;
42+
adjustedIndex = Math.Max(0, Math.Min(adjustedIndex, parentCollection.Count));
43+
// Insert at new position.
44+
var movedBookmark = parentCollection.Insert(adjustedIndex, title);
45+
movedBookmark.TextStyle = textStyle;
46+
movedBookmark.Color = color;
47+
movedBookmark.Destination = destination;
48+
// Re-add children.
49+
foreach (var child in children)
50+
AddBookmark(movedBookmark, child, document);
51+
}
52+
53+
// Clones an existing bookmark (including all descendants) and adds it to a parent.
54+
static void AddBookmark(PdfBookmark parent, PdfBookmark sourceBookmark, PdfLoadedDocument document)
55+
{
56+
if (parent == null || sourceBookmark == null)
57+
return;
58+
PdfBookmark newBookmark = parent.Insert(parent.Count, sourceBookmark.Title);
59+
newBookmark.TextStyle = sourceBookmark.TextStyle;
60+
newBookmark.Color = sourceBookmark.Color;
61+
newBookmark.Destination = sourceBookmark.Destination ?? new PdfDestination(document.Pages[0]);
62+
foreach (PdfBookmark child in sourceBookmark)
63+
AddBookmark(newBookmark, child, document);
64+
}
65+
66+
// Removes the first occurrence of a bookmark with the specified title from a parent (searches recursively).
67+
static void RemoveBookmarkByTitle(PdfBookmarkBase parent, string title)
68+
{
69+
if (parent == null || string.IsNullOrWhiteSpace(title))
70+
return;
71+
72+
for (int i = parent.Count - 1; i >= 0; i--)
73+
{
74+
PdfBookmark bookmark = parent[i] as PdfBookmark;
75+
if (bookmark != null)
76+
{
77+
RemoveBookmarkByTitle(bookmark, title);
78+
if (bookmark.Title == title)
79+
parent.RemoveAt(i);
80+
}
81+
}
82+
}
83+
}
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.36616.10 d17.14
5+
MinimumVisualStudioVersion = 10.0.40219.1
6+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Multi‑Page-PDF-Radio-Button-Group-Synchronization", "Multi‑Page-PDF-Radio-Button-Group-Synchronization\Multi‑Page-PDF-Radio-Button-Group-Synchronization.csproj", "{268276E6-E841-4FDC-BA43-80B6A95921CE}"
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+
{268276E6-E841-4FDC-BA43-80B6A95921CE}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
15+
{268276E6-E841-4FDC-BA43-80B6A95921CE}.Debug|Any CPU.Build.0 = Debug|Any CPU
16+
{268276E6-E841-4FDC-BA43-80B6A95921CE}.Release|Any CPU.ActiveCfg = Release|Any CPU
17+
{268276E6-E841-4FDC-BA43-80B6A95921CE}.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 = {05CFF1BA-A827-4272-A101-1018EB8FC017}
24+
EndGlobalSection
25+
EndGlobal
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>net8.0</TargetFramework>
6+
<RootNamespace>Multi_Page_PDF_Radio_Button_Group_Synchronization</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>

Forms/Multi‑Page-PDF-Radio-Button-Group-Synchronization/.NET/Multi‑Page-PDF-Radio-Button-Group-Synchronization/Output/gitkeep.txt

Whitespace-only changes.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
using Syncfusion.Drawing;
2+
using Syncfusion.Pdf;
3+
using Syncfusion.Pdf.Graphics;
4+
using Syncfusion.Pdf.Interactive;
5+
6+
// Create a new PDF document
7+
using (PdfDocument document = new PdfDocument())
8+
{
9+
// Create two pages
10+
PdfPage page1 = document.Pages.Add();
11+
PdfPage page2 = document.Pages.Add();
12+
// Access the form
13+
PdfForm form = document.Form;
14+
form.FieldAutoNaming = false;
15+
// Label font
16+
PdfFont labelFont = new PdfStandardFont(PdfFontFamily.Helvetica, 12f, PdfFontStyle.Regular);
17+
// Group name
18+
string groupName = "EmployeesRadioGroup";
19+
float labelOffsetX = 10f;
20+
float labelOffsetY = -2f;
21+
// Create ONE radio button list field (anchor it on the first page; items can be on any page)
22+
PdfRadioButtonListField radioField = new PdfRadioButtonListField(page1, groupName)
23+
{
24+
// Keep standard radio behavior: only one selection in the group
25+
AllowUnisonSelection = false
26+
};
27+
// Define the 4 radio items: 2 on page 1, 2 on page 2
28+
var items = new (PdfPage page, string export, RectangleF bounds, string label)[]
29+
{
30+
(page1, "rb1", new RectangleF(100f, 200f, 20f, 20f), "Radio Button 1"),
31+
(page1, "rb2", new RectangleF(100f, 240f, 20f, 20f), "Radio Button 2"),
32+
(page2, "rb3", new RectangleF(100f, 200f, 20f, 20f), "Radio Button 3"),
33+
(page2, "rb4", new RectangleF(100f, 240f, 20f, 20f), "Radio Button 4"),
34+
};
35+
// Add items to the single radio field and draw their labels
36+
foreach (var (page, export, bounds, label) in items)
37+
{
38+
PdfRadioButtonListItem item = new PdfRadioButtonListItem(page, export)
39+
{
40+
Bounds = bounds
41+
};
42+
radioField.Items.Add(item);
43+
// Label beside the radio button
44+
page.Graphics.DrawString(label, labelFont, PdfBrushes.Black,
45+
bounds.Right + labelOffsetX, bounds.Y + labelOffsetY);
46+
}
47+
// Set default selection
48+
radioField.SelectedValue = "rb4";
49+
// Add the single field to the form
50+
form.Fields.Add(radioField);
51+
// Save the PDF document
52+
document.Save(Path.GetFullPath(@"Output/Output.pdf"));
53+
}
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
<Solution>
2+
<Project Path="Resource-preservation-in-HTML-to-PDF/Resource-preservation-in-HTML-to-PDF.csproj" />
3+
</Solution>

0 commit comments

Comments
 (0)