Skip to content

Commit

Permalink
Playground_sample: Resolved the feedback.
Browse files Browse the repository at this point in the history
  • Loading branch information
Sri-hari-haran-g committed Aug 27, 2024
1 parent 0c7c745 commit 11c4cd6
Show file tree
Hide file tree
Showing 18 changed files with 67 additions and 54 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,24 +14,23 @@
PdfLoadedPage loadedPage = loadedDocument.Pages[0] as PdfLoadedPage;

//Get the annotation.
PdfLoadedRectangleAnnotation loadedMarkup = loadedPage.Annotations[0] as PdfLoadedRectangleAnnotation;
PdfLoadedRectangleAnnotation rectangleAnnotation = loadedPage.Annotations[0] as PdfLoadedRectangleAnnotation;

//Get the review history collection for the annotation.
PdfLoadedPopupAnnotationCollection reviewCollection = loadedMarkup.ReviewHistory;

//Get annotation state.
PdfAnnotationState state = reviewCollection[0].State;

//Get annotation state model.
PdfAnnotationStateModel model = reviewCollection[0].StateModel;

//Get the comments of the annotation.
PdfLoadedPopupAnnotationCollection commentsCollection = loadedMarkup.Comments;

//Get the review history of the comment.
PdfLoadedPopupAnnotationCollection reviewCollection1 = commentsCollection[0].ReviewHistory;

Console.WriteLine("Successfully retrive review status from PDF document");
PdfLoadedPopupAnnotationCollection reviewCollection = rectangleAnnotation.ReviewHistory;

//Iterate through the review history collection.
foreach (PdfLoadedPopupAnnotation review in reviewCollection)
{
//Get the author of the annotation.
string author = review.Author;
//Get the state of the annotation.
PdfAnnotationState state = review.State;
//Get the state model of the annotation.
PdfAnnotationStateModel model = review.StateModel;

Console.WriteLine("Author of the reviewer: " + author + "\r\nState: " + state + "\r\nState Model: " + model);
}

//Closes the document.
loadedDocument.Close(true);
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
using Syncfusion.Pdf.Interactive;
using Syncfusion.Pdf.Parsing;

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

Expand All @@ -14,12 +15,21 @@
PdfLoadedPage loadedPage = loadedDocument.Pages[0] as PdfLoadedPage;

//Get the annotation.
PdfLoadedRectangleAnnotation loadedMarkup = loadedPage.Annotations[0] as PdfLoadedRectangleAnnotation;
PdfLoadedRectangleAnnotation rectangleAnnotation = loadedPage.Annotations[0] as PdfLoadedRectangleAnnotation;

//Get the comments of the annotation.
PdfLoadedPopupAnnotationCollection commentsCollection = loadedMarkup.Comments;

Console.WriteLine("Successfully retrive annotation comments from PDF document");
PdfLoadedPopupAnnotationCollection commentsCollection = rectangleAnnotation.Comments;

//Iterate through the comments collection.
foreach (PdfLoadedPopupAnnotation comment in commentsCollection)
{
//Get the author of the comment.
string author = comment.Author;
//Get the content
string content = comment.Text;

Console.WriteLine("Author of the comment: " + author + "\r\nContent: " + content);
}

//Closes the document.
loadedDocument.Close(true);
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 17
VisualStudioVersion = 17.1.32407.343
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Retrieve-the-annotation-comments-from-the-existing-PDF", "Retrieve-the-annotation-comments-from-the-existing-PDF\Retrieve-the-annotation-comments-from-the-existing-PDF.csproj", "{D3C293E5-D34E-447F-99DD-DE563FFB9BA9}"
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Retrieve-the-annotation-comments-from-the-existing-PDF", "Retrieve-the-annotation-comments-from-the-existing-PDF.csproj", "{D3C293E5-D34E-447F-99DD-DE563FFB9BA9}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Expand Down
Original file line number Diff line number Diff line change
@@ -1,32 +1,33 @@
using Syncfusion.Pdf.Parsing;
using Syncfusion.Pdf.Security;


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

//Loads an existing signed PDF document

PdfLoadedDocument document = new PdfLoadedDocument(documentStream);

// Gets the signature field

PdfLoadedSignatureField signatureField = document.Form.Fields[0] as PdfLoadedSignatureField;

// Signature validation options

PdfSignatureValidationOptions options = new PdfSignatureValidationOptions();

// Sets the revocation type

options.RevocationValidationType = RevocationValidationType.Crl;

// Validate signature and get validation result

PdfSignatureValidationResult result = signatureField.ValidateSignature(options);

Console.WriteLine("Successfully validate customized revocation");
//Check whether the CRL is revoked
if (result.RevocationResult.IsRevokedCRL)
{
Console.WriteLine("CRL is revoked");
}
else
{
Console.WriteLine("CRL is not revoked");
}

// Closes the document

document.Close(true);
Original file line number Diff line number Diff line change
@@ -1,45 +1,33 @@


using Syncfusion.Pdf.Parsing;
using Syncfusion.Pdf.Parsing;
using Syncfusion.Pdf.Security;

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

//Loads an existing signed PDF document

PdfLoadedDocument document = new PdfLoadedDocument(documentStream);

// Gets the signature field

PdfLoadedSignatureField signatureField = document.Form.Fields[0] as PdfLoadedSignatureField;

// Validates signature and get validation result

PdfSignatureValidationResult result = signatureField.ValidateSignature();

// Gets the LTV verification Information.

LtvVerificationInfo ltvVerificationInfo = result.LtvVerificationInfo;

// Checks whether the signature document LTV is enabled.

bool isLtvEnabled = ltvVerificationInfo.IsLtvEnabled;

Console.WriteLine("isLtvEnabled :" + isLtvEnabled);

// Checks whether the signature document has CRL embedded.

bool isCrlEmbedded = ltvVerificationInfo.IsCrlEmbedded;

Console.WriteLine("isCrlEmbedded :" + isCrlEmbedded);

// Checks whether the signature document has OCSP embedded.

bool isOcspEmbedded = ltvVerificationInfo.IsOcspEmbedded;

Console.WriteLine("isOcspEmbedded :" + isOcspEmbedded);
Console.WriteLine("LTV enabled: " + isLtvEnabled);
Console.WriteLine("CRL embedded: " + isCrlEmbedded);
Console.WriteLine("OCSP embedded: " + isOcspEmbedded);

// Closes the document

document.Close(true);
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
List<PdfSignatureValidationResult> results;
bool isValid = loadedDocument.Form.Fields.ValidateSignatures(collection, out results);

Console.WriteLine("Successfully validate all signatures in digitally signed PDF");
Console.WriteLine("All signatures in the document are valid: " + isValid);

//Close the document.
loadedDocument.Close(true);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,19 +36,28 @@
//Checks whether the document is modified or not.
bool isModified = result.IsDocumentModified;

Console.WriteLine("Document modified: " + isModified);

//Signature details.
string issuerName = signatureField.Signature.Certificate.IssuerName;
DateTime validFrom = signatureField.Signature.Certificate.ValidFrom;
DateTime validTo = signatureField.Signature.Certificate.ValidTo;
string signatureAlgorithm = result.SignatureAlgorithm;
DigestAlgorithm digestAlgorithm = result.DigestAlgorithm;

Console.WriteLine("Issuer Name: " + issuerName);
Console.WriteLine("Valid From: " + validFrom);
Console.WriteLine("Valid To: " + validTo);
Console.WriteLine("Signature Algorithm: " + signatureAlgorithm);
Console.WriteLine("Digest Algorithm: " + digestAlgorithm);

//Revocation validation details.
RevocationResult revocationDetails = result.RevocationResult;
RevocationStatus revocationStatus = revocationDetails.OcspRevocationStatus;
bool isRevokedCRL = revocationDetails.IsRevokedCRL;

Console.WriteLine("Successfully validate all signatures in digitally signed PDF");
Console.WriteLine("Revocation Status: " + revocationStatus);
Console.WriteLine("Is Revoked CRL: " + isRevokedCRL);

//Close the document.
loadedDocument.Close(true);
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@
<None Update="Data\Input.pdf">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
<None Update="Output\.gitkeep">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
</ItemGroup>

</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,10 @@
//Accessing the attachments.
foreach (PdfAttachment attachment in document.Attachments)
{
FileStream stream = new FileStream(attachment.FileName, FileMode.Create);
FileStream stream = new FileStream(Path.GetFullPath(@"Output/") + attachment.FileName, FileMode.Create);
stream.Write(attachment.Data, 0, attachment.Data.Length);
stream.Dispose();
}

Console.WriteLine("Successfully loaded an encrypt only attachment document");

//Close the document.
document.Close(true);
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,12 @@
//Accessing the attachments.
foreach (PdfAttachment attachment in document.Attachments)
{
FileStream stream = new FileStream(attachment.FileName, FileMode.Create);
FileStream stream = new FileStream(Path.GetFullPath(@"Output/") + attachment.FileName, FileMode.Create);

stream.Write(attachment.Data, 0, attachment.Data.Length);

stream.Dispose();
}
Console.WriteLine("Successfully set user password when accessing the attachment");

//Close the document.
document.Close(true);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@
<None Update="Data\Input.pdf">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
<None Update="Output\.gitkeep">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
</ItemGroup>

</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@
<None Update="Data\Input.pdf">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
<None Update="Output\.gitkeep">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
</ItemGroup>

</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,10 @@
foreach (PdfAttachment attachment in loadedDocument.Attachments)
{
//Extracts the ZUGFeRD invoice attachment and saves it to the disk.
FileStream s = new FileStream(attachment.FileName, FileMode.Create, FileAccess.Write);
FileStream s = new FileStream(Path.GetFullPath(@"Output/") + attachment.FileName, FileMode.Create, FileAccess.Write);
s.Write(attachment.Data, 0, attachment.Data.Length);
s.Dispose();
}
Console.WriteLine("Successfully extract ZUGFeRD invoice from PDF document");

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

0 comments on commit 11c4cd6

Please sign in to comment.