Skip to content

Conversation

github-actions[bot]
Copy link
Contributor

No description provided.

@github-actions github-actions bot requested a review from a team as a code owner January 23, 2024 18:37
@LanceMcCarthy
Copy link
Contributor

cc @dessyordanova @dimodi This is a merge of all the concepts into one KB. We can consider duplication in the DPL docs, too.

@@ -0,0 +1,152 @@
---
title: Signing PDFs with PdfPRocessing in DdfViewer

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

DdfViewer >> PdfViewer

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Handled

Copy link
Contributor

@ikoevska ikoevska left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Marking this as Request Changes due to the 404 link that needs to be fixed.

## Notes

- The Telerik Blazor PdfViewer does not currently support digital signature management in the UI.
- You can use Telerik PdfProcessing to digitally sign the PDF on the server-side.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
- You can use Telerik PdfProcessing to digitally sign the PDF on the server-side.
- You can use Telerik PdfProcessing to digitally sign the PDF on the server side.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Handled

## See Also

- [PdfViewer - Overview](https://docs.telerik.com/blazor-ui/components/pdfviewer/overview)
- [Document Processing Digital Signature documentation](https://docs.telerik.com/devtools/document-processing/libraries/radpdfprocessing/features/security/digital-signatures)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
- [Document Processing Digital Signature documentation](https://docs.telerik.com/devtools/document-processing/libraries/radpdfprocessing/features/security/digital-signatures)
- [Document Processing Digital Signature Documentation](https://docs.telerik.com/devtools/document-processing/libraries/radpdfprocessing/features/digital-signature)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Handled

## See Also

- [PdfViewer - Overview](https://docs.telerik.com/blazor-ui/components/pdfviewer/overview)
- [Document Processing Digital Signature documentation](https://docs.telerik.com/devtools/document-processing/libraries/radpdfprocessing/features/security/digital-signatures)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Double-check the link - it's a 404 for me. https://docs.telerik.com/devtools/document-processing/libraries/radpdfprocessing/features/digital-signature seems to be the correct link.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You're correct, it is in the Features section of the documentation. I'm not sure where this one came from, could be hallucination, or that it is a last minute copy/paste mistake on my part.

The PdfViewer does not currently have the capability to manage digitial signatures of the document. However, this is still possible using the Telerik Document Processing Libraries PdfProcessing to programmatically manage the signature and the certificate of the document, while the PdfViewer's sole responsibility is to display the document.

1. Create a custom button in the Blazor PdfViewer to handle the logic for applying the digital signature to the PDF. See [PdfViewer - Custom Toolbar Button](https://docs.telerik.com/blazor-ui/components/pdfviewer/toolbar#custom-tools) for instructions.
2. Use the PdfProcessing tool to add a digital signature programmatically to the PDF. See [Document Processing - Digital Signature documentation](https://docs.telerik.com/devtools/document-processing/libraries/radpdfprocessing/features/security/digital-signatures) for instructions.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
2. Use the PdfProcessing tool to add a digital signature programmatically to the PDF. See [Document Processing - Digital Signature documentation](https://docs.telerik.com/devtools/document-processing/libraries/radpdfprocessing/features/security/digital-signatures) for instructions.
2. Use the PdfProcessing tool to add a digital signature programmatically to the PDF. See [Document Processing - Digital Signature documentation](https://docs.telerik.com/devtools/document-processing/libraries/radpdfprocessing/features/digital-signature) for instructions.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Handled

x509Store.Open(OpenFlags.ReadOnly | OpenFlags.OpenExistingOnly);
var validCerts = x509Store.Certificates.Find(X509FindType.FindByTimeValid, DateTime.Now, false);

// IMPORTANT: This example is just taking the very first valid cert. In a real app, you will selected the cert you want to sign the document with
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
// IMPORTANT: This example is just taking the very first valid cert. In a real app, you will selected the cert you want to sign the document with
// IMPORTANT: This example is taking the very first valid certificate. In a real app, you need to select the certificate you want to sign the document with.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Handled,

Except the "need to" part. The developer can/must select whatever certificate it is from the Store that they use. In most cases the first certificate will be the SSL one, and you don't want that one for the PDF document.

var signatureField = new SignatureField(signatureName);
signatureField.Signature = new Telerik.Windows.Documents.Fixed.Model.DigitalSignatures.Signature(certificate);

// close the local cert store now that we're done
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
// close the local cert store now that we're done
// Close the local cert store now that you're done.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Handled


var document = new PdfFormatProvider().Import(unsignedDocumentBytes);

// For the sake of this demo, we are adding a new page and adding a new signature field there, if your document already has a signature field, you can search for it instead
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
// For the sake of this demo, we are adding a new page and adding a new signature field there, if your document already has a signature field, you can search for it instead
// This demo adds a new page and a new signature field there. If your document already has a signature field, you can search for it instead.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Handled

FormSource = new FormSource { Size = new Size(220, 220) }
};

// We will use the editor to fill the Form XObject.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
// We will use the editor to fill the Form XObject.
// The demo uses the editor to fill the Form XObject.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Handled

widget.Content.NormalContentSource = form.FormSource;
widget.RecalculateContent();

// Finally add the SignatureWidget to the page's annotations
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
// Finally add the SignatureWidget to the page's annotations
// Finally add the SignatureWidget to the page's annotations.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Handled

</PdfViewerToolBar>
</TelerikPdfViewer>

@code {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The tabbing on some lines looks off.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Handled


## Notes

- The Telerik Blazor PdfViewer does not currently support digital signature management in the UI.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This repeats similar content above. Since it's the reason to create a KB, I guess the statement is unnecessary here.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Handled

@LanceMcCarthy
Copy link
Contributor

LanceMcCarthy commented Jan 25, 2024

Looks like I do not have edit permissions to this branch to make the suggested changes :/

image

Copy link
Contributor

@LanceMcCarthy LanceMcCarthy left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since I cannot make edits to the branch, here is the updated version of the entire file, after making all the recommended changes.

@dimodi Can you make the edit on my behalf? Or add me as a collaborator and I will update the PR. Thanks!

--- title: Signing PDFs with PdfPRocessing in PdfViewer description: Learn how to use PdfProcessing to sign PDFs using the Telerik PdfViewer in a web application. type: how-to page_title: How to Sign PDFs in Telerik PDF Viewer slug: pdfviewer-sign-pdfs tags: telerik, pdf, viewer, sign, digital signature res_type: kb --- ## Environment | Product | Version | | --- | --- | | RadPdfProcessing for Document Processing | 2023.3 | | Telerik UI for Blazor PdfViewer | 2023.3 | ## Description I want to be able to apply a digital signature to a document in the Telerik UI for Blazor PdfViewer. ## Solution The PdfViewer does not currently have the capability to manage digitial signatures of the document. However, this is still possible using the Telerik Document Processing Libraries PdfProcessing to programmatically manage the signature and the certificate of the document, while the PdfViewer's sole responsibility is to display the document. 1. Create a custom button in the Blazor PdfViewer to handle the logic for applying the digital signature to the PDF. See [PdfViewer - Custom Toolbar Button](https://docs.telerik.com/blazor-ui/components/pdfviewer/toolbar#custom-tools) for instructions. 2. Use the PdfProcessing tool to add a digital signature programmatically to the PDF. See [Document Processing - Digital Signature documentation](https://docs.telerik.com/devtools/document-processing/libraries/radpdfprocessing/features/digital-signature) for instructions. 3. Reload the document into the PdfViewer. See [PdfViewer - Overview](https://docs.telerik.com/blazor-ui/components/pdfviewer/overview) for instructions. ## Example ```csharp <TelerikPdfViewer Data="@PdfSource"> <PdfViewerToolBar> <PdfViewerToolBarOpenTool /> <!-- all other buttons here -->	<PdfViewerToolBarSeparator />	<PdfViewerToolBarCustomTool> <TelerikButton OnClick="@OnSignPdfClick">SIGN</TelerikButton> </PdfViewerToolBarCustomTool> </PdfViewerToolBar> </TelerikPdfViewer> @code { private byte[] PdfSource { get; set; }	private async Task OnPdfDownload(PdfViewerDownloadEventArgs args) { args.FileName = "My.pdf"; } private async Task OnSignPdfClick() { var unsignedDocument = this.PdfSource; var signedDocument = SignDocument(this.PdfSource); this.PdfSource = signedDocument; }	private byte[] SignDocument(byte[] unsignedDocumentBytes)	{ // **** PHASE 1 - Get certificate **** //	X509Certificate2 certificate = null;	// OPTION 1 - BRING YOUR OWN CERTIFICATE FILE // RadPdfProcessing enables you to sign and validate signature fields using standard signature encodings // adbe.x509.rsa_sha1 (PKCS #1) // adbe.pkcs7.sha1 (PKCS #7) // adbe.pkcs7.detached (PKCS #7 Detached)	//certificate = new System.Security.Cryptography.X509Certificates.X509Certificate2(certificateFilePath, certificateFilePassword);	// OPTION 2 - USE AN EXISTING CERTIFICATE	var x509Store = new X509Store("MY", StoreLocation.CurrentUser);	x509Store.Open(OpenFlags.ReadOnly | OpenFlags.OpenExistingOnly);	var validCerts = x509Store.Certificates.Find(X509FindType.FindByTimeValid, DateTime.Now, false);	// IMPORTANT: This example is taking the very first valid certificate. In a real app, you will selected the cert you want to sign the document with.	certificate = validCerts.FirstOrDefault(); // **** PHASE 2 - Add certificate to SignatureField and use certificate **** // // The name of the signature must be unique. var signatureName = "John Doe"; // The Signature object is added to a signature field, so we can add a visualization to it.	var signatureField = new SignatureField(signatureName);	signatureField.Signature = new Telerik.Windows.Documents.Fixed.Model.DigitalSignatures.Signature(certificate); // Close the local cert store now that you're done x509Store.Close(); // **** PHASE 3 - IMPORT DOCUMENT and insert signature field **** // var document = new PdfFormatProvider().Import(unsignedDocumentBytes); // This demo adds a new page and adding a new signature field there. If your document already has a signature field, you can search for it instead. RadFixedPage page = document.Pages.AddPage(); // This is the Form XObject element that represents the contents of the signature field. var form = new Telerik.Windows.Documents.Fixed.Model.Objects.Form { FormSource = new FormSource { Size = new Size(220, 220) } }; // This demo uses the editor to fill the Form XObject. var formEditor = new FixedContentEditor(form.FormSource); form.Position.Translate(10, 10); formEditor.DrawCircle(new Point(50, 50), 20); formEditor.DrawText(signatureName);	// The widget contains the Form XObject and defines the appearance of the signature field.	var widget = signatureField.Widgets.AddWidget();	widget.Rect = new Rect(200, 600, 100, 100);	widget.Border = new AnnotationBorder(10, AnnotationBorderStyle.Solid, null);	widget.Content.NormalContentSource = form.FormSource;	widget.RecalculateContent(); // Finally, add the SignatureWidget to the page's annotations.	page.Annotations.Add(widget);	var editor = new FixedContentEditor(page);	editor.Position.Translate(200, 400);	editor.DrawForm(form.FormSource);	document.AcroForm.FormFields.Add(signatureField);	widget.RecalculateContent();	widget.AppearanceCharacteristics.Background = new Telerik.Windows.Documents.Fixed.Model.ColorSpaces.RgbColor(255, 0, 0); // **** PHASE 4 - EXPORT DOCUMENT **** // byte[] signedDocBytes = new PdfFormatProvider().Export(document); return signedDocBytes; } } 

Notes

  • You can use Telerik PdfProcessing to digitally sign the PDF on the server side.
  • The web application cannot access the user's guest operating system's X509 Certificate Store due to security restrictions in modern web browsers. Your application will only have access to X509 certificates installed on the server side.

See Also

 
@@ -0,0 +1,152 @@
---
title: Signing PDFs with PdfPRocessing in DdfViewer
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Handled

The PdfViewer does not currently have the capability to manage digitial signatures of the document. However, this is still possible using the Telerik Document Processing Libraries PdfProcessing to programmatically manage the signature and the certificate of the document, while the PdfViewer's sole responsibility is to display the document.

1. Create a custom button in the Blazor PdfViewer to handle the logic for applying the digital signature to the PDF. See [PdfViewer - Custom Toolbar Button](https://docs.telerik.com/blazor-ui/components/pdfviewer/toolbar#custom-tools) for instructions.
2. Use the PdfProcessing tool to add a digital signature programmatically to the PDF. See [Document Processing - Digital Signature documentation](https://docs.telerik.com/devtools/document-processing/libraries/radpdfprocessing/features/security/digital-signatures) for instructions.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Handled

</PdfViewerToolBar>
</TelerikPdfViewer>

@code {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Handled

x509Store.Open(OpenFlags.ReadOnly | OpenFlags.OpenExistingOnly);
var validCerts = x509Store.Certificates.Find(X509FindType.FindByTimeValid, DateTime.Now, false);

// IMPORTANT: This example is just taking the very first valid cert. In a real app, you will selected the cert you want to sign the document with
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Handled,

Except the "need to" part. The developer can/must select whatever certificate it is from the Store that they use. In most cases the first certificate will be the SSL one, and you don't want that one for the PDF document.

var signatureField = new SignatureField(signatureName);
signatureField.Signature = new Telerik.Windows.Documents.Fixed.Model.DigitalSignatures.Signature(certificate);

// close the local cert store now that we're done
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Handled

widget.Content.NormalContentSource = form.FormSource;
widget.RecalculateContent();

// Finally add the SignatureWidget to the page's annotations
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Handled


## Notes

- The Telerik Blazor PdfViewer does not currently support digital signature management in the UI.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Handled

## Notes

- The Telerik Blazor PdfViewer does not currently support digital signature management in the UI.
- You can use Telerik PdfProcessing to digitally sign the PDF on the server-side.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Handled

## See Also

- [PdfViewer - Overview](https://docs.telerik.com/blazor-ui/components/pdfviewer/overview)
- [Document Processing Digital Signature documentation](https://docs.telerik.com/devtools/document-processing/libraries/radpdfprocessing/features/security/digital-signatures)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Handled

## See Also

- [PdfViewer - Overview](https://docs.telerik.com/blazor-ui/components/pdfviewer/overview)
- [Document Processing Digital Signature documentation](https://docs.telerik.com/devtools/document-processing/libraries/radpdfprocessing/features/security/digital-signatures)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You're correct, it is in the Features section of the documentation. I'm not sure where this one came from, could be hallucination, or that it is a last minute copy/paste mistake on my part.

It seems @LanceMcCarthy has insufficient access to the repo. Committing changes on his behalf.
@ikoevska
Copy link
Contributor

@LanceMcCarthy I applied the changes on your behalf. Please, double-check if everything's OK since there were some issues with how GitHub handled your comment with the changes.

@LanceMcCarthy
Copy link
Contributor

@ikoevska The looks good to me. Next time, I'm going to try a Fork -> PR -> PR to see if it fixes the mess this has become :D

@ntacheva ntacheva self-requested a review January 29, 2024 17:08
@ntacheva
Copy link
Contributor

Synced with @LanceMcCarthy that we can remove product versioning as we do not normally include it unless we are targeting a specific version or if the KB applies to older versions. I updated the environment markup to follow the pattern we are using for the rest of the KBs.

@ntacheva ntacheva requested review from ikoevska and removed request for ikoevska January 29, 2024 17:11
@ntacheva ntacheva dismissed ikoevska’s stale review January 29, 2024 17:18

All requested changes are addressed and confirmed. I am dismissing the review, so I can merge and plug this into the RC.

@ntacheva ntacheva merged commit eff1ea6 into master Jan 29, 2024
@github-actions github-actions bot deleted the new-kb-pdfviewer-sign-pdfs-416f047ee2034e88a376296b55ae0d2c branch January 29, 2024 17:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

5 participants