Skip to content

Commit 97972ab

Browse files
Initial commit - blog samples added.
1 parent 973bbed commit 97972ab

23 files changed

+477
-2
lines changed

README.md

Lines changed: 43 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,43 @@
1-
# import-export-pdf-annotations-csharp
2-
This repository provides C# examples using the Syncfusion .NET PDF Library to import and export annotations in PDF documents seamlessly. Explore five practical techniques to efficiently manage annotation data and enhance document workflows in your .NET applications
1+
# 5 Easy Ways to Import and Export PDF Annotations in C#
2+
3+
The Syncfusion® .NET PDF Library provides powerful APIs to manage annotations in PDF documents. This collection of samples demonstrates five easy and effective ways to import and export annotations using different formats and customization options, helping developers streamline annotation workflows in their .NET applications.
4+
5+
Sample name | Description
6+
------|------
7+
[Export and import annotations using XFDF format](https://github.com/SyncfusionExamples/import-export-pdf-annotations-csharp/tree/master/export-and-import-annotations-using-xfdf) | Demonstrates how to export annotations from a PDF document to XFDF format and import them back, ensuring a seamless round-trip annotation workflow.
8+
[Export and import annotations using FDF format](https://github.com/SyncfusionExamples/import-export-pdf-annotations-csharp/tree/master/export-and-import-annotations-to-fdf) | Shows how to use the FDF format to export and import annotations, offering a compact and structured way to manage annotation data.
9+
[Export and import annotations using JSON format](https://github.com/SyncfusionExamples/import-export-pdf-annotations-csharp/tree/master/export-and-import-annotations-json) | Explains how to serialize and deserialize PDF annotations using JSON, making it easy to integrate with web services and modern data workflows.
10+
[Export specific types of annotations](https://github.com/SyncfusionExamples/import-export-pdf-annotations-csharp/tree/master/export-specific-type-of-annotations) | Illustrates how to selectively export only certain types of annotations (e.g., highlights, text notes), allowing for targeted annotation management.
11+
[Export annotation with appearance](https://github.com/SyncfusionExamples/import-export-pdf-annotations-csharp/tree/master/export-annotations-with-appearance) | Demonstrates how to export annotations along with their visual appearance, ensuring consistent rendering across different platforms and viewers.
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.

data/Annotation.pdf

945 KB
Binary file not shown.

data/annotations.pdf

137 KB
Binary file not shown.

data/export-annotation.fdf

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
%FDF-1.2
2+
2 0 obj
3+
<</Type/Annot/Contents(Introduction)/BS<</W 2/S/S>>/C[.00 .00 1.00]/T(John Milton)/Subtype/Line/Rect[52.00 702.00 195.00 718.00]/LE[/None/None]/L[60.00 710.00 187.00 710.00]/IT/LineDimension/LLE 0/LL 0/CP/Inline/Cap false/Page 0>>
4+
endobj
5+
3 0 obj
6+
<</Type/Annot/Rect[475.00 27.00 549.00 71.00]/Contents(Page Number)/BS<</W 2/S/S>>/C[1.00 .00 .00]/T(John Milton)/Subtype/Circle/Page 0>>
7+
endobj
8+
4 0 obj
9+
<</Type/Annot/Rect[57.00 493.00 565.00 592.00]/Contents(Usage)/BS<</W 2/S/S>>/C[1.00 .6666667 .00]/T(John Milton)/Subtype/Square/AP 5 0 R/Page 0>>
10+
endobj
11+
5 0 obj
12+
<</N 6 0 R>>
13+
endobj
14+
6 0 obj
15+
<</BBox[.00 .00 508.00 99.00]/Type/XObject/Subtype/Form/Matrix[1.00 .00 .00 1.00 .00 .00]/Resources<</ProcSet[/PDF]>>/Filter/FlateDecode/Length 130>>stream
16+
x^]�1 �0���?��6�dm��cš�O[��4A�ߛ��;���6��n� �Sn�ǹ ��A&��\C�3c*�������F+mS�>�E�Η�왶x3i�����\)�&U��N�Pf�E�����&�
17+
endstream
18+
endobj
19+
7 0 obj
20+
<</Type/Annot/Contents(Chapter 1 Conceptual Overview)/BS<</W 2/S/S>>/C[1.00 .00 .00]/T(John Milton)/Subtype/Polygon/Rect[81.00 308.00 534.00 358.00]/Vertices[129.00 356.00 486.00 356.00 532.00 333.00 486.00 310.00 129.00 310.00 83.00 333.00 129.00 356.00]/Page 0>>
21+
endobj
22+
8 0 obj
23+
<</Type/Annot/Rect[60.00 632.00 555.00 677.00]/Contents(Introduction)/C[1.00 1.00 .00]/T(John Milton)/Subtype/Highlight/QuadPoints[251.00 677.00 555.00 677.00 251.00 662.00 555.00 662.00 60.00 662.00 555.00 662.00 60.00 647.00 555.00 647.00 60.00 647.00 160.00 647.00 60.00 632.00 160.00 632.00]/Page 0>>
24+
endobj
25+
9 0 obj
26+
<</Type/Annot/Rect[225.00 451.00 245.00 471.00]/Contents(PDF Standard)/C[1.00 1.00 .00]/T(John Milton)/Open true/Subtype/Text/Name/Comment/Page 0>>
27+
endobj
28+
1 0 obj
29+
<</FDF<</Annots[2 0 R 3 0 R 4 0 R 7 0 R 8 0 R 9 0 R]/F()/UF()>>/Type/Catalog>>
30+
endobj
31+
trailer
32+
<</Root 1 0 R>>
33+
%%EOF

data/export-annotation.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
{"pdfAnnotation":{ "0":{ "shapeAnnotation":[{"type":"Line","page":"0","start":"60,710","end":"187,710","contents":"Introduction","width":"2","style":"solid","color":"#0000FF","title":"John Milton","rect":{"x":"52","y":"702","width":"195","height":"718"},"head":"None","tail":"None","IT":"LineDimension","leaderExtend":"0","leaderLength":"0","caption-style":"Inline","caption":"false"},{"type":"Circle","page":"0","rect":{"x":"475","y":"27","width":"549","height":"71"},"contents":"Page Number","width":"2","style":"solid","color":"#FF0000","title":"John Milton"},{"type":"Square","page":"0","rect":{"x":"57","y":"493","width":"565","height":"592"},"contents":"Usage","width":"2","style":"solid","color":"#FFAA00","title":"John Milton","appearance":"eyJhcCI6eyJOIjp7InN0cmVhbSI6eyJCQm94Ijp7ImFycmF5IjpbeyJpbnQiOiIwIn0seyJpbnQiOiIwIn0seyJpbnQiOiI1MDgifSx7ImludCI6Ijk5In1dfSwiVHlwZSI6eyJuYW1lIjoiWE9iamVjdCJ9LCJTdWJ0eXBlIjp7Im5hbWUiOiJGb3JtIn0sIk1hdHJpeCI6eyJhcnJheSI6W3siaW50IjoiMSJ9LHsiaW50IjoiMCJ9LHsiaW50IjoiMCJ9LHsiaW50IjoiMSJ9LHsiaW50IjoiMCJ9LHsiaW50IjoiMCJ9XX0sIlJlc291cmNlcyI6eyJkaWN0Ijp7IlByb2NTZXQiOnsiYXJyYXkiOlt7Im5hbWUiOiJQREYifV19fX0sIkZpbHRlciI6eyJuYW1lIjoiRmxhdGVEZWNvZGUifSwiTGVuZ3RoIjp7ImludCI6IjEzMCJ9LCJkYXRhIjp7Im1vZGUiOiJyYXciLCJlbmNvZGluZyI6ImhleCIsImJ5dGVzIjoiMjUyMDQzNjg2MTZFNjc2NTIwNjM2RjJENkY3MjY0Njk2RTYxNzQ2NTIwNzM3OTczNzQ2NTZEMjA3NDZGMjA2QzY1NjY3NDJGNzQ2RjcwMkUwRDBBMzEyMDMwMjAzMDIwMzEyMDMwMjAzOTM5MjA2MzZEMEQwQTJGNDQ2NTc2Njk2MzY1NTI0NzQyMjA0MzUzMEQwQTJGNDQ2NTc2Njk2MzY1NTI0NzQyMjA2MzczMEQwQTVCNUQyMDMwMjA2NDBEMEEzMjIwNzcwRDBBMzAyMDZBMEQwQTMwMjA0QTBEMEEzMTIwMzAyRTM2MzYzNjM2MzYzNjM2MzYzNjM2MzYzNjM2MzYzNjM2MjAzMDIwNTI0NzBEMEEzMTIwMkQzMTIwMzUzMDM2MjAyRDM5MzcyMDcyNjUwRDBBNTMwRDBBIn19fX19"},{"type":"Polygon","page":"0","contents":"Chapter 1 Conceptual Overview","width":"2","style":"solid","color":"#FF0000","title":"John Milton","rect":{"x":"81","y":"308","width":"534","height":"358"},"vertices":"129,356;486,356;532,333;486,310;129,310;83,333;129,356"},{"type":"Highlight","page":"0","rect":{"x":"60","y":"632","width":"555","height":"677"},"contents":"Introduction","color":"#FFFF00","title":"John Milton","coords":"251,677,555,677,251,662,555,662,60,662,555,662,60,647,555,647,60,647,160,647,60,632,160,632"},{"type":"Text","page":"0","rect":{"x":"225","y":"451","width":"245","height":"471"},"contents":"PDF Standard","color":"#FFFF00","title":"John Milton","Open":"true","icon":"Comment"}]}}}

data/export-annotation.xfdf

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<xfdf xml:space="preserve" xmlns="http://ns.adobe.com/xfdf/">
3+
<annots>
4+
<line page="0" start="60,710" end="187,710" width="2" style="solid" color="#0000FF" title="John Milton" rect="52,702,195,718" head="None" tail="None" IT="LineDimension" leaderExtend="0" leaderLength="0" caption-style="Inline" caption="no">
5+
<contents>Introduction</contents>
6+
</line>
7+
<circle page="0" rect="475,27,549,71" width="2" style="solid" color="#FF0000" title="John Milton">
8+
<contents>Page Number</contents>
9+
</circle>
10+
<square page="0" rect="57,493,565,592" width="2" style="solid" color="#FFAA00" title="John Milton">
11+
<contents>Usage</contents>
12+
</square>
13+
<polygon page="0" width="2" style="solid" color="#FF0000" title="John Milton" rect="81,308,534,358">
14+
<vertices>129,356;486,356;532,333;486,310;129,310;83,333;129,356</vertices>
15+
<contents>Chapter 1 Conceptual Overview</contents>
16+
</polygon>
17+
<highlight page="0" rect="60,632,555,677" color="#FFFF00" title="John Milton" coords="251,677,555,677,251,662,555,662,60,662,555,662,60,647,555,647,60,647,160,647,60,632,160,632">
18+
<contents>Introduction</contents>
19+
</highlight>
20+
<text page="0" rect="225,451,245,471" color="#FFFF00" title="John Milton" open="yes" icon="Comment">
21+
<contents>PDF Standard</contents>
22+
</text>
23+
</annots>
24+
<f href="" />
25+
</xfdf>

data/input-empty.pdf

117 KB
Binary file not shown.

data/input-with-annotations.pdf

121 KB
Binary file not shown.
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
using Syncfusion.Pdf.Parsing;
2+
3+
//Register your Syncfusion License Key
4+
Syncfusion.Licensing.SyncfusionLicenseProvider.RegisterLicense("Your License Key");
5+
6+
//Export annotations to JSON format
7+
ExportAnnotationsToJson();
8+
9+
//Import annotations from JSON format
10+
ImportAnnotationsFromJson();
11+
12+
static void ExportAnnotationsToJson()
13+
{
14+
//Load the PDF document
15+
using (PdfLoadedDocument document = new PdfLoadedDocument("../../../../data/input-with-annotations.pdf"))
16+
{
17+
//Export the annotations to JSON format
18+
document.ExportAnnotations("export-annotation.json", AnnotationDataFormat.Json);
19+
}
20+
}
21+
static void ImportAnnotationsFromJson()
22+
{
23+
//Load the PDF document
24+
using (PdfLoadedDocument document = new PdfLoadedDocument("../../../../data/input-empty.pdf"))
25+
{
26+
//Import the annotations from JSON format
27+
document.ImportAnnotations("../../../../data/export-annotation.json", AnnotationDataFormat.Json);
28+
29+
//Save the modified document
30+
document.Save("imported-annotations.pdf");
31+
}
32+
}
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>net8.0</TargetFramework>
6+
<RootNamespace>export_and_import_annotations_json</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>

0 commit comments

Comments
 (0)