Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Playground_sample: Updated the github sample for playground integration. #93

Merged
merged 7 commits into from
Aug 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -14,22 +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;
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 @@ -14,10 +14,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;
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,30 +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);

// Closes the document
//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,39 +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;

// Checks whether the signature document has CRL embedded.

bool isCrlEmbedded = ltvVerificationInfo.IsCrlEmbedded;

// Checks whether the signature document has OCSP embedded.

bool isOcspEmbedded = ltvVerificationInfo.IsOcspEmbedded;

// Closes the document
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 @@ -4,7 +4,7 @@
using System.Security.Cryptography.X509Certificates;

//Load a PDF document
FileStream docStream = new FileStream(@"Data/Input.pdf", FileMode.Open, FileAccess.Read);
FileStream docStream = new FileStream(Path.GetFullPath(@"Data/Input.pdf"), FileMode.Open, FileAccess.Read);
PdfLoadedDocument document = new PdfLoadedDocument(docStream);
//Gets the signature field.
PdfLoadedSignatureField signatureField = document.Form.Fields[0] as PdfLoadedSignatureField;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
using System.Security.Cryptography.X509Certificates;

//Gets the stream from the document
FileStream documentStream = new FileStream(@"Data/DigitalSignature.pdf", FileMode.Open, FileAccess.Read);
FileStream documentStream = new FileStream(Path.GetFullPath(@"Data/DigitalSignature.pdf"), FileMode.Open, FileAccess.Read);
//Load an existing signed PDF document.
PdfLoadedDocument loadedDocument = new PdfLoadedDocument(documentStream);

Expand All @@ -14,11 +14,11 @@
//X509Certificate2Collection to check the signer's identity using root certificates.
X509CertificateCollection collection = new X509CertificateCollection();
//Create new X509Certificate2 with the root certificate.
X509Certificate2 certificate = new X509Certificate2(@"Data/Root.cer");
X509Certificate2 certificate = new X509Certificate2(Path.GetFullPath(@"Data/Root.cer"));
//Add the certificate to the collection.
collection.Add(certificate);
//Create new X509Certificate2 with the intermediate certificate.
certificate = new X509Certificate2(@"Data/Intermediate0.cer");
certificate = new X509Certificate2(Path.GetFullPath(@"Data/Intermediate0.cer"));
//Add the certificate to the collection.
collection.Add(certificate);
//Validate signature and get the validation result
Expand All @@ -31,6 +31,7 @@
foreach (X509Certificate2 item in signerCertificate.OcspCertificate.Certificates)
{
string subjectName = "The OCSP Response was signed by " + item.SubjectName.Name;
Console.WriteLine(subjectName);
}
bool isEmbbed = signerCertificate.OcspCertificate.IsEmbedded;
DateTime validForm = signerCertificate.OcspCertificate.ValidFrom;
Expand All @@ -41,6 +42,7 @@
foreach (X509Certificate2 item in signerCertificate.CrlCertificate.Certificates)
{
string subjectName = "The CRL was signed by " + item.SubjectName.Name;
Console.WriteLine(subjectName);
}
bool isEmbbed = signerCertificate.CrlCertificate.IsEmbedded;
DateTime validForm = signerCertificate.CrlCertificate.ValidFrom;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
using Syncfusion.Pdf.Parsing;

//Loads an existing document
FileStream docStream = new FileStream(@"Data/Input.pdf", FileMode.Open, FileAccess.Read);
FileStream docStream = new FileStream(Path.GetFullPath(@"Data/Input.pdf"), FileMode.Open, FileAccess.Read);
PdfLoadedDocument document = new PdfLoadedDocument(docStream);

//Gets an array of revisions.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,5 +28,9 @@
List<PdfSignatureValidationResult> results;
bool isValid = loadedDocument.Form.Fields.ValidateSignatures(collection, out results);

Console.WriteLine("All signatures in the document are valid: " + isValid);

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


Original file line number Diff line number Diff line change
Expand Up @@ -36,17 +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("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 @@ -20,5 +20,7 @@
//Extracts the XMP metadata from PDF image.
XmpMetadata metadata = imagesInfo[0].Metadata;

Console.WriteLine(metadata.XmlData);

//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 @@ -3,21 +3,27 @@
using Syncfusion.Pdf;
using Syncfusion.Pdf.Parsing;

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

//Load an existing PDF document.
//Load an existing PDF document.
PdfLoadedDocument loadedDocument = new PdfLoadedDocument(docStream);

//Set the conformance for PDF/A-1b conversion.
loadedDocument.Conformance = PdfConformanceLevel.Pdf_A1B;
//Subscribe to the PdfAConversionProgress event to track the PDF to PDF/A conversion process
loadedDocument.PdfAConversionProgress += new PdfLoadedDocument.PdfAConversionProgressEventHandler(pdfAConversion_TrackProgress);

loadedDocument.ConvertToPDFA(PdfConformanceLevel.Pdf_A1B);

//Save the document
FileStream outputStream = new FileStream(Path.GetFullPath(@"Output/Output.pdf"), FileMode.Create, FileAccess.Write);
loadedDocument.Save(outputStream);

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

loadedDocument.PdfAConversionProgress += pdfAConversion_TrackProgress;

//Event handler for Track PDF to PDF/A conversion process
void pdfAConversion_TrackProgress(object sender, PdfAConversionProgressEventArgs arguments)
{
Console.WriteLine(String.Format("PDF to PDF/A conversion process " + arguments.ProgressValue + "% completed"));
Console.ReadLine();
}

Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,7 @@
//Get the conformance level of the loaded document.
PdfConformanceLevel conformance = loadedDocument.Conformance;

Console.WriteLine("Conformance level :" + conformance);

//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,10 +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();
}
Sri-hari-haran-g marked this conversation as resolved.
Show resolved Hide resolved

//Close the document.
document.Close(true);
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
//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);

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>
25 changes: 25 additions & 0 deletions Split PDFs/Split-a-Range-of-Pages/.NET/Split-a-Range-of-Pages.sln
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}") = "Split-a-Range-of-Pages", "Split-a-Range-of-Pages\Split-a-Range-of-Pages.csproj", "{392F17B4-BD09-4931-A8C4-763232397426}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{392F17B4-BD09-4931-A8C4-763232397426}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{392F17B4-BD09-4931-A8C4-763232397426}.Debug|Any CPU.Build.0 = Debug|Any CPU
{392F17B4-BD09-4931-A8C4-763232397426}.Release|Any CPU.ActiveCfg = Release|Any CPU
{392F17B4-BD09-4931-A8C4-763232397426}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {225136D5-4D2E-449E-A6A0-83FBAB1D3AC7}
EndGlobalSection
EndGlobal
Binary file not shown.
Loading
Loading