Skip to content

Commit

Permalink
911183: Added volume 3 feature samples.
Browse files Browse the repository at this point in the history
  • Loading branch information
Sri-hari-haran-g committed Sep 20, 2024
1 parent ecd40b6 commit 40c2c58
Show file tree
Hide file tree
Showing 15 changed files with 187 additions and 65 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 17
VisualStudioVersion = 17.11.35219.272
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Add-cloud-border-styled-circle-annotation-in-the-PDF", "Add-cloud-border-styled-circle-annotation-in-the-PDF\Add-cloud-border-styled-circle-annotation-in-the-PDF.csproj", "{E80AEF8E-84CC-44AB-AE2C-524A4AE82696}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{E80AEF8E-84CC-44AB-AE2C-524A4AE82696}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{E80AEF8E-84CC-44AB-AE2C-524A4AE82696}.Debug|Any CPU.Build.0 = Debug|Any CPU
{E80AEF8E-84CC-44AB-AE2C-524A4AE82696}.Release|Any CPU.ActiveCfg = Release|Any CPU
{E80AEF8E-84CC-44AB-AE2C-524A4AE82696}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {26638CAE-A8D9-4A36-9F37-B3BD7A414210}
EndGlobalSection
EndGlobal
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net8.0</TargetFramework>
<RootNamespace>Add_cloud_border_styled_circle_annotation_in_the_PDF</RootNamespace>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Syncfusion.Pdf.Net.Core" Version="*" />
</ItemGroup>

<ItemGroup>
<None Update="Output\.gitkeep">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
</ItemGroup>

</Project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
// See https://aka.ms/new-console-template for more information

using Syncfusion.Pdf.Interactive;
using Syncfusion.Pdf;
using Syncfusion.Drawing;

//Create a new PDF document
PdfDocument document = new PdfDocument();
//Add a new page
PdfPage page = document.Pages.Add();
//Create a new circle annotation
PdfCircleAnnotation annotation = new PdfCircleAnnotation(new RectangleF(0, 0, 200, 200), "Circle");
//Assign the border width
annotation.Border.BorderWidth = 1;
//Assign the color
annotation.Color = Color.Red;
//Assign the InnerColor
annotation.InnerColor = Color.Blue;
//Create a new PdfBorderEffect class
PdfBorderEffect bordereffect = new PdfBorderEffect();
//Assign the intensity value
bordereffect.Intensity = 2;
//Assign the cloud style
bordereffect.Style = PdfBorderEffectStyle.Cloudy;
//Assign the BorderEffect to the annotation
annotation.BorderEffect = bordereffect;
//Set appearance for the annotation
annotation.SetAppearance(true);
//Adds the annotation to the page
page.Annotations.Add(annotation);

//Create file stream.
using (FileStream outputFileStream = new FileStream(Path.GetFullPath(@"Output/Output.pdf"), FileMode.Create, FileAccess.ReadWrite))
{
//Save the PDF document to file stream.
document.Save(outputFileStream);
}

//Close the document.
document.Close(true);

Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 17
VisualStudioVersion = 17.11.35219.272
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Add-cloud-border-styled-ellipse-annotation-in-the-PDF", "Add-cloud-border-styled-ellipse-annotation-in-the-PDF\Add-cloud-border-styled-ellipse-annotation-in-the-PDF.csproj", "{9DCFB496-350A-439F-AA19-9DFFBF3A542B}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{9DCFB496-350A-439F-AA19-9DFFBF3A542B}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{9DCFB496-350A-439F-AA19-9DFFBF3A542B}.Debug|Any CPU.Build.0 = Debug|Any CPU
{9DCFB496-350A-439F-AA19-9DFFBF3A542B}.Release|Any CPU.ActiveCfg = Release|Any CPU
{9DCFB496-350A-439F-AA19-9DFFBF3A542B}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {4841D089-BFAC-4027-A297-80B2E9EC4B7A}
EndGlobalSection
EndGlobal
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net8.0</TargetFramework>
<RootNamespace>Add_cloud_border_styled_ellipse_annotation_in_the_PDF</RootNamespace>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Syncfusion.Pdf.Net.Core" Version="*" />
</ItemGroup>

<ItemGroup>
<None Update="Output\.gitkeep">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
</ItemGroup>

</Project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
// See https://aka.ms/new-console-template for more information

using Syncfusion.Pdf.Interactive;
using Syncfusion.Pdf;
using Syncfusion.Drawing;

//Create a new PDF document
PdfDocument document = new PdfDocument();
//Add a new page
PdfPage page = document.Pages.Add();
// create a new ellipse annotation
PdfEllipseAnnotation annotation = new PdfEllipseAnnotation(new RectangleF(0, 0, 200, 100), "Ellipse");
//Assign the border width
annotation.Border.BorderWidth = 1;
//Assign the color
annotation.Color = Color.Red;
//Assign the InnerColor
annotation.InnerColor = Color.Blue;
//Create a new PdfBorderEffect class
PdfBorderEffect bordereffect = new PdfBorderEffect();
//Assign the intensity value
bordereffect.Intensity = 2;
//Assign the cloud style
bordereffect.Style = PdfBorderEffectStyle.Cloudy;
//Assign the BorderEffect
annotation.BorderEffect = bordereffect;
//Set appearance for the annotation.
annotation.SetAppearance(true);
// Adds the annotation to the page.
page.Annotations.Add(annotation);

//Create file stream.
using (FileStream outputFileStream = new FileStream(Path.GetFullPath(@"Output/Output.pdf"), FileMode.Create, FileAccess.ReadWrite))
{
//Save the PDF document to file stream.
document.Save(outputFileStream);
}

//Close the document.
document.Close(true);
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,9 @@
//Load an existing PDF document.
PdfLoadedDocument loadedDocument = new PdfLoadedDocument(documentStream);

//Get the page of the existing PDF document.
PdfLoadedPage loadedPage = loadedDocument.Pages[0] as PdfLoadedPage;

//Create a new PDF signature without PdfCertificate instance.
PdfSignature signature = new PdfSignature(loadedDocument, loadedPage, null, "Signature1");

//Hook up the ComputeHash event.
signature.ComputeHash += Signature_ComputeHash;
//Gets the first signature field of the PDF document
PdfLoadedSignatureField signatureField = loadedDocument.Form.Fields[0] as PdfLoadedSignatureField;
PdfSignature signature = signatureField.Signature;

//Create X509Certificate2 from your certificate to create a long-term validity.
X509Certificate2 x509 = new X509Certificate2(Path.GetFullPath(@"Data/PDF.pfx"), "syncfusion");
Expand All @@ -38,22 +33,4 @@
//Close the document.
loadedDocument.Close(true);

void Signature_ComputeHash(object sender, PdfSignatureEventArgs ars)
{
//Get the document bytes
byte[] documentBytes = ars.Data;

SignedCms signedCms = new SignedCms(new ContentInfo(documentBytes), detached: true);

//Compute the signature using the specified digital ID file and the password
X509Certificate2 certificate = new X509Certificate2(Path.GetFullPath(@"Data/PDF.pfx"), "syncfusion");
CmsSigner cmsSigner = new CmsSigner(certificate);

//Set the digest algorithm SHA256
cmsSigner.DigestAlgorithm = new Oid("2.16.840.1.101.3.4.2.1");

signedCms.ComputeSignature(cmsSigner);

//Embed the encoded digital signature to the PDF document
ars.SignedData = signedCms.Encode();
}
Binary file not shown.
Binary file not shown.
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,7 @@
</ItemGroup>

<ItemGroup>
<None Update="Data\PDF.pfx">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
<None Update="Data\syncfusion_logo.png">
<None Update="Data\Input.pdf">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
<None Update="Output\.gitkeep">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,55 +3,30 @@
using Syncfusion.Drawing;
using Syncfusion.Pdf;
using Syncfusion.Pdf.Graphics;
using Syncfusion.Pdf.Parsing;
using Syncfusion.Pdf.Security;

//Creates a new PDF document.
PdfDocument document = new PdfDocument();
//Get the stream from the document.
FileStream documentStream = new FileStream(Path.GetFullPath(@"Data/Input.pdf"), FileMode.Open, FileAccess.Read);

//Adds a new page.
PdfPageBase page = document.Pages.Add();
//Load an existing PDF document.
PdfLoadedDocument loadedDocument = new PdfLoadedDocument(documentStream);

//Create graphics for the page.
PdfGraphics graphics = page.Graphics;

//Creates a certificate instance from PFX file with private key.
FileStream certificateStream = new FileStream(Path.GetFullPath(@"Data/PDF.pfx"), FileMode.Open, FileAccess.Read);
PdfCertificate pdfCert = new PdfCertificate(certificateStream, "DigitalPass123");

//Creates a digital signature.
PdfSignature signature = new PdfSignature(document, page, pdfCert, "Signature");
signature.Settings.CryptographicStandard = CryptographicStandard.CADES;
signature.Settings.DigestAlgorithm = DigestAlgorithm.SHA256;


//Sets an image for signature field.
FileStream imageStream = new FileStream(Path.GetFullPath(@"Data/syncfusion_logo.png"), FileMode.Open, FileAccess.Read);

//Sets an image for signature field.
PdfBitmap image = new PdfBitmap(imageStream);

//Adds time stamp by using the server URI and credentials.
signature.TimeStampServer = new TimeStampServer(new Uri("http://time.certum.pl/ "));
//Gets the first signature field of the PDF document
PdfLoadedSignatureField signatureField = loadedDocument.Form.Fields[0] as PdfLoadedSignatureField;
PdfSignature signature = signatureField.Signature;

//Enable LTV on Signature.
signature.EnableLtv = true;

//Sets signature info.
signature.Bounds = new RectangleF(new PointF(0, 0), image.PhysicalDimension);
signature.ContactInfo = "[email protected]";
signature.LocationInfo = "Honolulu, Hawaii";
signature.Reason = "I am author of this document.";

//Draws the signature image.
signature.Appearance.Normal.Graphics.DrawImage(image, 0, 0);

//Create file stream.
using (FileStream outputFileStream = new FileStream(Path.GetFullPath(@"Output/Output.pdf"), FileMode.Create, FileAccess.ReadWrite))
{
//Save the PDF document to file stream.
document.Save(outputFileStream);
loadedDocument.Save(outputFileStream);
}

//Close the document.
document.Close(true);
loadedDocument.Close(true);

0 comments on commit 40c2c58

Please sign in to comment.